diff options
author | wjaniszewski <wjaniszewski@13f79535-47bb-0310-9956-ffa450edef68> | 2009-03-02 22:49:01 +0000 |
---|---|---|
committer | wjaniszewski <wjaniszewski@13f79535-47bb-0310-9956-ffa450edef68> | 2009-03-02 22:49:01 +0000 |
commit | 65c9710b644bd3ef0f5dd21aaa0049f984394c57 (patch) | |
tree | e67b40fea3ffe03bc0d28f0fbca5e020ef49fcc9 /sandbox/wjaniszewski | |
parent | 6c6ad2fbdd72a4aabc4025339a3d6aa090668444 (diff) |
Epmd starts automatically - if epmd is not available tests are beeing ignored. Normalized service/reference RPC, added some error handling.
git-svn-id: http://svn.us.apache.org/repos/asf/tuscany@749461 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'sandbox/wjaniszewski')
17 files changed, 1105 insertions, 670 deletions
diff --git a/sandbox/wjaniszewski/binding-erlang-runtime/src/main/java/org/apache/tuscany/sca/binding/erlang/impl/ErlangInvoker.java b/sandbox/wjaniszewski/binding-erlang-runtime/src/main/java/org/apache/tuscany/sca/binding/erlang/impl/ErlangInvoker.java index 7e963cc34a..fd9e89bc2d 100644 --- a/sandbox/wjaniszewski/binding-erlang-runtime/src/main/java/org/apache/tuscany/sca/binding/erlang/impl/ErlangInvoker.java +++ b/sandbox/wjaniszewski/binding-erlang-runtime/src/main/java/org/apache/tuscany/sca/binding/erlang/impl/ErlangInvoker.java @@ -20,15 +20,16 @@ package org.apache.tuscany.sca.binding.erlang.impl;
import org.apache.tuscany.sca.binding.erlang.ErlangBinding;
+import org.apache.tuscany.sca.binding.erlang.impl.exceptions.ErlangException;
import org.apache.tuscany.sca.binding.erlang.impl.types.TypeHelpersProxy;
import org.apache.tuscany.sca.invocation.Invoker;
import org.apache.tuscany.sca.invocation.Message;
-import org.apache.tuscany.sca.runtime.RuntimeComponentReference;
import com.ericsson.otp.erlang.OtpConnection;
import com.ericsson.otp.erlang.OtpEpmd;
import com.ericsson.otp.erlang.OtpErlangList;
import com.ericsson.otp.erlang.OtpErlangObject;
+import com.ericsson.otp.erlang.OtpErlangTuple;
import com.ericsson.otp.erlang.OtpMbox;
import com.ericsson.otp.erlang.OtpMsg;
import com.ericsson.otp.erlang.OtpNode;
@@ -40,78 +41,102 @@ import com.ericsson.otp.erlang.OtpSelf; */
public class ErlangInvoker implements Invoker {
- private RuntimeComponentReference reference;
- private ErlangBinding binding;
- private OtpNode node;
+ private ErlangBinding binding;
+ private OtpNode node;
- public ErlangInvoker(RuntimeComponentReference reference, ErlangBinding binding) {
- this.reference = reference;
- this.binding = binding;
- }
+ public ErlangInvoker(ErlangBinding binding) {
+ this.binding = binding;
+ }
- private Message sendMessage(Message msg) {
- OtpMbox tmpMbox = null;
- try {
- String nodeName = "_connector_to_" + binding.getNode();
- node = new OtpNode(nodeName);
- tmpMbox = node.createMbox();
- Object[] args = msg.getBody();
- OtpErlangObject msgPayload = TypeHelpersProxy.toErlang(args);
- tmpMbox.send(msg.getOperation().getName(), binding.getNode(), msgPayload);
- if (msg.getOperation().getOutputType() != null) {
- OtpMsg resultMsg = tmpMbox.receiveMsg();
- OtpErlangObject result = resultMsg.getMsg();
- msg.setBody(TypeHelpersProxy.toJava(result, msg.getOperation().getOutputType().getPhysical()));
- }
- } catch (Exception e) {
- msg.setFaultBody(e);
- } finally {
- if (tmpMbox != null) {
- tmpMbox.close();
- }
- if (node != null) {
- OtpEpmd.unPublishPort(node);
- node.close();
- }
- }
- return msg;
- }
+ private Message sendMessage(Message msg) {
+ OtpMbox tmpMbox = null;
+ try {
+ String nodeName = "_connector_to_" + binding.getNode();
+ node = new OtpNode(nodeName);
+ tmpMbox = node.createMbox();
+ Object[] args = msg.getBody();
+ OtpErlangObject msgPayload = TypeHelpersProxy.toErlang(args);
+ tmpMbox.send(msg.getOperation().getName(), binding.getNode(),
+ msgPayload);
+ if (msg.getOperation().getOutputType() != null) {
+ OtpMsg resultMsg = tmpMbox.receiveMsg();
+ OtpErlangObject result = resultMsg.getMsg();
+ msg.setBody(TypeHelpersProxy.toJava(result, msg.getOperation()
+ .getOutputType().getPhysical()));
+ }
+ } catch (Exception e) {
+ msg.setFaultBody(e);
+ } finally {
+ if (tmpMbox != null) {
+ tmpMbox.close();
+ }
+ if (node != null) {
+ OtpEpmd.unPublishPort(node);
+ node.close();
+ }
+ }
+ return msg;
+ }
- private Message invokeOperation(Message msg) {
- OtpSelf self = null;
- OtpPeer other = null;
- OtpConnection connection = null;
- try {
- String nodeName = "_connector_to_" + binding.getNode();
- self = new OtpSelf(nodeName);
- other = new OtpPeer(binding.getNode());
- connection = self.connect(other);
- OtpErlangList params = TypeHelpersProxy.toErlangAsList((Object[])msg.getBody());
- connection.sendRPC(binding.getModule(), msg.getOperation().getName(), params);
- if (msg.getOperation().getOutputType() != null) {
- OtpErlangObject result = connection.receiveRPC();
- msg.setBody(TypeHelpersProxy.toJava(result, msg.getOperation().getOutputType().getPhysical()));
- }
- } catch (Exception e) {
- msg.setFaultBody(e);
- } finally {
- if (connection != null) {
- connection.close();
- }
- }
- return msg;
- }
+ private Message invokeOperation(Message msg) {
+ OtpSelf self = null;
+ OtpPeer other = null;
+ OtpConnection connection = null;
+ try {
+ String nodeName = "_connector_to_" + binding.getNode();
+ self = new OtpSelf(nodeName);
+ other = new OtpPeer(binding.getNode());
+ connection = self.connect(other);
+ OtpErlangList params = TypeHelpersProxy
+ .toErlangAsList((Object[]) msg.getBody());
+ OtpErlangTuple message = MessageHelper.rpcMessage(self.pid(), self
+ .createRef(), binding.getModule(), msg.getOperation()
+ .getName(), params);
+ connection.send("rex", message);
+ OtpErlangObject result = connection.receiveRPC();
+ if (MessageHelper.isfunctionUndefMessage(result)) {
+ // TODO: externalize message?
+ Exception e = new ErlangException(
+ "No such function in referenced Erlang node.");
+ if (msg.getOperation().getFaultTypes().size() == 0) {
+ // TODO: no way to throw exception, log it (temporary as System.out)
+ // TODO: do we really want not to throw any exception?
+ System.out.println("PROBLEM: " + e.getMessage());
+ // in this case we don't throw occured problem, so we need
+ // to reset message body (if body is not cleared then
+ // operation arguments would be set as operation output)
+ msg.setBody(null);
+ } else {
+ msg.setFaultBody(e);
+ }
+ } else if (msg.getOperation().getOutputType() != null) {
+ if (result.getClass().equals(OtpErlangTuple.class)) {
+ OtpErlangObject resultBody = ((OtpErlangTuple) result)
+ .elementAt(1);
+ msg.setBody(TypeHelpersProxy.toJava(resultBody, msg
+ .getOperation().getOutputType().getPhysical()));
+ }
+ }
+ } catch (Exception e) {
+ msg.setFaultBody(e);
+ } finally {
+ if (connection != null) {
+ connection.close();
+ }
+ }
+ return msg;
+ }
- /**
- * @see org.apache.tuscany.sca.invocation.Invoker#invoke(org.apache.tuscany.sca.invocation.Message)
- */
- public Message invoke(Message msg) {
- if (binding.isMbox()) {
- return sendMessage(msg);
- } else {
- return invokeOperation(msg);
- }
+ /**
+ * @see org.apache.tuscany.sca.invocation.Invoker#invoke(org.apache.tuscany.sca.invocation.Message)
+ */
+ public Message invoke(Message msg) {
+ if (binding.isMbox()) {
+ return sendMessage(msg);
+ } else {
+ return invokeOperation(msg);
+ }
- }
+ }
}
diff --git a/sandbox/wjaniszewski/binding-erlang-runtime/src/main/java/org/apache/tuscany/sca/binding/erlang/impl/ErlangReferenceBindingProvider.java b/sandbox/wjaniszewski/binding-erlang-runtime/src/main/java/org/apache/tuscany/sca/binding/erlang/impl/ErlangReferenceBindingProvider.java index 34af39ce41..0ce9d33238 100644 --- a/sandbox/wjaniszewski/binding-erlang-runtime/src/main/java/org/apache/tuscany/sca/binding/erlang/impl/ErlangReferenceBindingProvider.java +++ b/sandbox/wjaniszewski/binding-erlang-runtime/src/main/java/org/apache/tuscany/sca/binding/erlang/impl/ErlangReferenceBindingProvider.java @@ -48,7 +48,7 @@ public class ErlangReferenceBindingProvider implements ReferenceBindingProvider */
public Invoker createInvoker(Operation operation) {
try {
- return new ErlangInvoker(reference, binding);
+ return new ErlangInvoker(binding);
} catch (Exception e) {
logger.log(Level.WARNING, "Exception during creating Erlang invoker", e);
}
diff --git a/sandbox/wjaniszewski/binding-erlang-runtime/src/main/java/org/apache/tuscany/sca/binding/erlang/impl/ErlangServiceBindingProvider.java b/sandbox/wjaniszewski/binding-erlang-runtime/src/main/java/org/apache/tuscany/sca/binding/erlang/impl/ErlangServiceBindingProvider.java index 8d6e2e810c..df82c5813c 100644 --- a/sandbox/wjaniszewski/binding-erlang-runtime/src/main/java/org/apache/tuscany/sca/binding/erlang/impl/ErlangServiceBindingProvider.java +++ b/sandbox/wjaniszewski/binding-erlang-runtime/src/main/java/org/apache/tuscany/sca/binding/erlang/impl/ErlangServiceBindingProvider.java @@ -32,6 +32,7 @@ public class ErlangServiceBindingProvider implements ServiceBindingProvider { private RuntimeComponentService service;
private ErlangBinding binding;
+ private RpcServer rpcServer;
public ErlangServiceBindingProvider(ErlangBinding binding, RuntimeComponentService service) {
this.service = service;
@@ -50,8 +51,8 @@ public class ErlangServiceBindingProvider implements ServiceBindingProvider { */
public void start() {
try {
- Runnable server = new RpcServer(service, binding);
- Thread thread = new Thread(server);
+ rpcServer = new RpcServer(service, binding);
+ Thread thread = new Thread(rpcServer);
thread.start();
} catch (Exception e) {
throw new ServiceRuntimeException(e);
@@ -64,7 +65,7 @@ public class ErlangServiceBindingProvider implements ServiceBindingProvider { */
public void stop() {
try {
- //TODO: stop RPC server
+ rpcServer.stop();
} catch (Exception e) {
throw new ServiceRuntimeException(e);
}
diff --git a/sandbox/wjaniszewski/binding-erlang-runtime/src/main/java/org/apache/tuscany/sca/binding/erlang/impl/MessageHelper.java b/sandbox/wjaniszewski/binding-erlang-runtime/src/main/java/org/apache/tuscany/sca/binding/erlang/impl/MessageHelper.java new file mode 100644 index 0000000000..55134782d5 --- /dev/null +++ b/sandbox/wjaniszewski/binding-erlang-runtime/src/main/java/org/apache/tuscany/sca/binding/erlang/impl/MessageHelper.java @@ -0,0 +1,93 @@ +package org.apache.tuscany.sca.binding.erlang.impl; + +import com.ericsson.otp.erlang.OtpErlangAtom; +import com.ericsson.otp.erlang.OtpErlangList; +import com.ericsson.otp.erlang.OtpErlangObject; +import com.ericsson.otp.erlang.OtpErlangPid; +import com.ericsson.otp.erlang.OtpErlangRef; +import com.ericsson.otp.erlang.OtpErlangTuple; + +public class MessageHelper { + + private static String ATOM_BADRPC = "badrpc"; + private static String ATOM_EXIT = "EXIT"; + private static String ATOM_UNDEF = "undef"; + + public static OtpErlangObject functionUndefMessage(String module, String function, OtpErlangList args, String tuscanyMsg) { + OtpErlangObject[] args4 = new OtpErlangObject[3]; + args4[0] = new OtpErlangAtom(module); + args4[1] = new OtpErlangAtom(function); + args4[2] = args; + + OtpErlangObject[] args3 = new OtpErlangObject[2]; + args3[0] = new OtpErlangTuple(args4); + args3[1] = new OtpErlangAtom(tuscanyMsg); + + OtpErlangObject[] args2 = new OtpErlangObject[2]; + args2[0] = new OtpErlangAtom(ATOM_UNDEF); + args2[1] = new OtpErlangList(args3); + + OtpErlangObject[] args1 = new OtpErlangObject[2]; + args1[0] = new OtpErlangAtom(ATOM_EXIT); + args1[1] = new OtpErlangTuple(args2); + + OtpErlangTuple result = new OtpErlangTuple(args1); + return result; + } + + public static boolean isfunctionUndefMessage(OtpErlangObject msg) { + if (msg.getClass().equals(OtpErlangTuple.class)) { + OtpErlangTuple tupleMsg = (OtpErlangTuple) msg; + if (tupleMsg.arity() == 2 + && tupleMsg.elementAt(0).getClass().equals( + OtpErlangAtom.class) + && tupleMsg.elementAt(1).getClass().equals( + OtpErlangTuple.class) + && ((OtpErlangAtom) tupleMsg.elementAt(0)).atomValue() + .equals(ATOM_BADRPC)) { + OtpErlangTuple badrpcTuple = (OtpErlangTuple) tupleMsg + .elementAt(1); + if (badrpcTuple.arity() == 2 + && badrpcTuple.elementAt(0).getClass().equals( + OtpErlangAtom.class) + && badrpcTuple.elementAt(1).getClass().equals( + OtpErlangTuple.class) + && ((OtpErlangAtom) badrpcTuple.elementAt(0)) + .atomValue().equals(ATOM_EXIT)) { + OtpErlangTuple exitTuple = (OtpErlangTuple) badrpcTuple + .elementAt(1); + if (exitTuple.arity() == 2 + && exitTuple.elementAt(0).getClass().equals( + OtpErlangAtom.class) + && ((OtpErlangAtom) exitTuple.elementAt(0)) + .atomValue().equals(ATOM_UNDEF)) { + return true; + } + } + + } + } + return false; + } + + public static OtpErlangTuple rpcMessage(OtpErlangPid senderPid, OtpErlangRef ref, String module, String function, OtpErlangList args) { + OtpErlangObject[] args3 = new OtpErlangObject[5]; + args3[0] = new OtpErlangAtom("call"); + args3[1] = new OtpErlangAtom(module); + args3[2] = new OtpErlangAtom(function); + args3[3] = args; + args3[4] = senderPid; + + OtpErlangObject[] args2 = new OtpErlangObject[2]; + args2[0] = senderPid; + args2[1] = ref; + + OtpErlangObject[] args1 = new OtpErlangObject[3]; + args1[0] = new OtpErlangAtom("$gen_call"); + args1[1] = new OtpErlangTuple(args2); + args1[2] = new OtpErlangTuple(args3); + + OtpErlangTuple result = new OtpErlangTuple(args1); + return result; + } +} diff --git a/sandbox/wjaniszewski/binding-erlang-runtime/src/main/java/org/apache/tuscany/sca/binding/erlang/impl/RpcExecutor.java b/sandbox/wjaniszewski/binding-erlang-runtime/src/main/java/org/apache/tuscany/sca/binding/erlang/impl/RpcExecutor.java index 3940c34b7b..6707496194 100644 --- a/sandbox/wjaniszewski/binding-erlang-runtime/src/main/java/org/apache/tuscany/sca/binding/erlang/impl/RpcExecutor.java +++ b/sandbox/wjaniszewski/binding-erlang-runtime/src/main/java/org/apache/tuscany/sca/binding/erlang/impl/RpcExecutor.java @@ -20,6 +20,7 @@ package org.apache.tuscany.sca.binding.erlang.impl; import java.io.IOException; +import java.lang.reflect.InvocationTargetException; import java.util.List; import org.apache.tuscany.sca.binding.erlang.ErlangBinding; @@ -39,105 +40,134 @@ import com.ericsson.otp.erlang.OtpErlangTuple; public class RpcExecutor implements Runnable { - private RuntimeComponentService service; - private ErlangBinding binding; - private OtpConnection connection; + private RuntimeComponentService service; + private ErlangBinding binding; + private OtpConnection connection; - private static final OtpErlangAtom OK = new OtpErlangAtom("ok"); - private static final OtpErlangAtom ERROR = new OtpErlangAtom("error"); + private static final OtpErlangAtom OK = new OtpErlangAtom("ok"); + private static final OtpErlangAtom ERROR = new OtpErlangAtom("error"); + private static final OtpErlangAtom BADRPC = new OtpErlangAtom("badrpc"); - public RpcExecutor(RuntimeComponentService service, ErlangBinding binding, OtpConnection connection) { - this.service = service; - this.binding = binding; - this.connection = connection; - } + public RpcExecutor(RuntimeComponentService service, ErlangBinding binding, + OtpConnection connection) { + this.service = service; + this.binding = binding; + this.connection = connection; + } - private void sendMessage(OtpConnection connection, - OtpErlangPid pid, - OtpErlangRef ref, - OtpErlangAtom head, - OtpErlangObject message) throws IOException { - OtpErlangTuple tResult = new OtpErlangTuple(new OtpErlangObject[] {head, message}); - OtpErlangObject msg = null; - if (ref != null) { - msg = new OtpErlangTuple(new OtpErlangObject[] {ref, tResult}); - } else { - msg = tResult; - } - connection.send(pid, msg); - } - - public void run() { - OtpErlangTuple request = null; - OtpErlangPid senderPid = null; - OtpErlangRef senderRef = null; - try { - OtpErlangTuple call = (OtpErlangTuple)connection.receive(); - if (call.arity() == 2) { - // is call from jinterface library - senderPid = (OtpErlangPid)call.elementAt(0); - request = (OtpErlangTuple)call.elementAt(1); - } else { - // is call from native *erl* console - OtpErlangTuple from = (OtpErlangTuple)call.elementAt(1); - request = (OtpErlangTuple)call.elementAt(2); - senderPid = (OtpErlangPid)from.elementAt(0); - senderRef = (OtpErlangRef)from.elementAt(1); - } - String module = ((OtpErlangAtom)request.elementAt(1)).atomValue(); - String function = ((OtpErlangAtom)request.elementAt(2)).atomValue(); - OtpErlangObject args = request.elementAt(3); - OtpErlangList argsList = null; - if (args instanceof OtpErlangList) { - argsList = (OtpErlangList)args; - } else { - argsList = new OtpErlangList(args); - } - if (!binding.getModule().equals(module)) { - sendMessage(connection, senderPid, senderRef, ERROR, new OtpErlangString("No such module")); - } else { - List<Operation> operations = service.getInterfaceContract().getInterface().getOperations(); - Operation operation = null; - for (Operation o : operations) { - if (o.getName().equals(function)) { - operation = o; - break; - } - } - if (operation != null) { - List<DataType> iTypes = operation.getInputType().getLogical(); - Class<?>[] forClasses = new Class<?>[iTypes.size()]; - for (int i = 0; i < iTypes.size(); i++) { - forClasses[i] = iTypes.get(i).getPhysical(); - } - Object result = - service.getRuntimeWire(binding).invoke(operation, - TypeHelpersProxy.toJavaFromList(argsList, forClasses)); - OtpErlangObject response = null; - if (operation.getOutputType() != null && operation.getOutputType().getPhysical().isArray()) { - response = TypeHelpersProxy.toErlangAsList(result); - } else if (operation.getOutputType() == null) { - Object[] arrArg = new Object[] {}; - response = TypeHelpersProxy.toErlang(arrArg); - } else { - Object[] arrArg = new Object[] {result}; - response = TypeHelpersProxy.toErlang(arrArg); - } - sendMessage(connection, senderPid, senderRef, OK, response); - } else { - sendMessage(connection, senderPid, senderRef, ERROR, new OtpErlangString("No such operation")); - } - } - } catch (Exception e) { - // TODO: distinguish and describe errors! - try { - sendMessage(connection, senderPid, senderRef, ERROR, new OtpErlangString("Error while processing request")); - } catch (IOException e1) { - // error while sending error message. Can't do anything now - } - } finally { - connection.close(); - } - } + private void sendMessage(OtpConnection connection, OtpErlangPid pid, + OtpErlangRef ref, OtpErlangAtom head, OtpErlangObject message) + throws IOException { + OtpErlangTuple tResult = new OtpErlangTuple(new OtpErlangObject[] { + head, message }); + OtpErlangObject msg = null; + msg = new OtpErlangTuple(new OtpErlangObject[] { ref, tResult }); + connection.send(pid, msg); + } + public void run() { + OtpErlangTuple request = null; + OtpErlangPid senderPid = null; + OtpErlangRef senderRef = null; + try { + OtpErlangTuple call = (OtpErlangTuple) connection.receive(); + OtpErlangTuple from = (OtpErlangTuple) call.elementAt(1); + request = (OtpErlangTuple) call.elementAt(2); + senderPid = (OtpErlangPid) from.elementAt(0); + senderRef = (OtpErlangRef) from.elementAt(1); + String module = ((OtpErlangAtom) request.elementAt(1)).atomValue(); + String function = ((OtpErlangAtom) request.elementAt(2)) + .atomValue(); + OtpErlangObject args = request.elementAt(3); + OtpErlangList argsList = null; + if (args instanceof OtpErlangList) { + argsList = (OtpErlangList) args; + } else { + argsList = new OtpErlangList(args); + } + if (!binding.getModule().equals(module)) { + // TODO: externalize message? + OtpErlangObject errorMsg = MessageHelper.functionUndefMessage( + module, function, argsList, + "Module not found in SCA component."); + sendMessage(connection, senderPid, senderRef, BADRPC, errorMsg); + } else { + List<Operation> operations = service.getInterfaceContract() + .getInterface().getOperations(); + Operation operation = null; + for (Operation o : operations) { + if (o.getName().equals(function)) { + operation = o; + break; + } + } + if (operation != null) { + List<DataType> iTypes = operation.getInputType() + .getLogical(); + Class<?>[] forClasses = new Class<?>[iTypes.size()]; + for (int i = 0; i < iTypes.size(); i++) { + forClasses[i] = iTypes.get(i).getPhysical(); + } + try { + Object result = service.getRuntimeWire(binding).invoke( + operation, + TypeHelpersProxy.toJavaFromList(argsList, + forClasses)); + OtpErlangObject response = null; + if (operation.getOutputType() != null + && operation.getOutputType().getPhysical() + .isArray()) { + response = TypeHelpersProxy.toErlangAsList(result); + } else if (operation.getOutputType() == null) { + Object[] arrArg = new Object[] {}; + response = TypeHelpersProxy.toErlang(arrArg); + } else { + Object[] arrArg = new Object[] { result }; + response = TypeHelpersProxy.toErlang(arrArg); + } + sendMessage(connection, senderPid, senderRef, OK, + response); + } catch (Exception e) { + if ((e.getClass().equals( + InvocationTargetException.class) && e + .getCause().getClass().equals( + IllegalArgumentException.class)) + || e.getClass().equals( + TypeMismatchException.class)) { + // TODO: externalize message? + OtpErlangObject errorMsg = MessageHelper + .functionUndefMessage(module, function, + argsList, + "Operation name found in SCA component, but parameters types didn't match."); + sendMessage(connection, senderPid, senderRef, + BADRPC, errorMsg); + } else { + throw e; + } + } + } else { + // TODO: externalize message? + OtpErlangObject errorMsg = MessageHelper + .functionUndefMessage(module, function, argsList, + "Operation name not found in SCA component."); + sendMessage(connection, senderPid, senderRef, BADRPC, + errorMsg); + } + } + } catch (Exception e) { + // TODO: distinguish and describe errors! + try { + e.printStackTrace(); + sendMessage(connection, senderPid, senderRef, ERROR, + new OtpErlangString( + "Unhandled error while processing request: " + + e.getClass().getCanonicalName() + + ", message: " + e.getMessage())); + } catch (IOException e1) { + // error while sending error message. Can't do anything now + } + } finally { + connection.close(); + } + } } diff --git a/sandbox/wjaniszewski/binding-erlang-runtime/src/main/java/org/apache/tuscany/sca/binding/erlang/impl/RpcServer.java b/sandbox/wjaniszewski/binding-erlang-runtime/src/main/java/org/apache/tuscany/sca/binding/erlang/impl/RpcServer.java index 90c47091e8..ab10865c83 100644 --- a/sandbox/wjaniszewski/binding-erlang-runtime/src/main/java/org/apache/tuscany/sca/binding/erlang/impl/RpcServer.java +++ b/sandbox/wjaniszewski/binding-erlang-runtime/src/main/java/org/apache/tuscany/sca/binding/erlang/impl/RpcServer.java @@ -23,6 +23,7 @@ import java.util.concurrent.ExecutorService; import java.util.concurrent.Executors; import org.apache.tuscany.sca.binding.erlang.ErlangBinding; +import org.apache.tuscany.sca.binding.erlang.impl.exceptions.ErlangException; import org.apache.tuscany.sca.runtime.RuntimeComponentService; import com.ericsson.otp.erlang.OtpConnection; @@ -33,6 +34,8 @@ public class RpcServer implements Runnable { private RuntimeComponentService service; private ErlangBinding binding; private OtpSelf self; + ExecutorService executors; + private boolean stopRequested; public RpcServer(RuntimeComponentService service, ErlangBinding binding) throws Exception { this.service = service; @@ -40,14 +43,19 @@ public class RpcServer implements Runnable { self = new OtpSelf(binding.getNode()); boolean registered = self.publishPort(); if (!registered) { - // TODO: throw exception, no epmd + //TODO: externalize messages? + throw new ErlangException("Problem with publishing service under epmd server."); } + executors = Executors.newFixedThreadPool(10); + } + + public void stop() { + stopRequested = true; + executors.shutdownNow(); } public void run() { - // TODO: thread management - ExecutorService executors = Executors.newFixedThreadPool(10); - while (true) { + while (!stopRequested) { try { OtpConnection connection = self.accept(); executors.execute(new RpcExecutor(service, binding, connection)); diff --git a/sandbox/wjaniszewski/binding-erlang-runtime/src/main/java/org/apache/tuscany/sca/binding/erlang/impl/TypeMismatchException.java b/sandbox/wjaniszewski/binding-erlang-runtime/src/main/java/org/apache/tuscany/sca/binding/erlang/impl/TypeMismatchException.java index 7a3e727aa4..03b53b60bd 100644 --- a/sandbox/wjaniszewski/binding-erlang-runtime/src/main/java/org/apache/tuscany/sca/binding/erlang/impl/TypeMismatchException.java +++ b/sandbox/wjaniszewski/binding-erlang-runtime/src/main/java/org/apache/tuscany/sca/binding/erlang/impl/TypeMismatchException.java @@ -30,6 +30,10 @@ public class TypeMismatchException extends Exception { this.expected = expected; this.received = received; } + + public TypeMismatchException() { + super("Arguments don't match"); + } public Class<?> getExpected() { return expected; diff --git a/sandbox/wjaniszewski/binding-erlang-runtime/src/main/java/org/apache/tuscany/sca/binding/erlang/impl/exceptions/ErlangException.java b/sandbox/wjaniszewski/binding-erlang-runtime/src/main/java/org/apache/tuscany/sca/binding/erlang/impl/exceptions/ErlangException.java new file mode 100644 index 0000000000..6ae919b969 --- /dev/null +++ b/sandbox/wjaniszewski/binding-erlang-runtime/src/main/java/org/apache/tuscany/sca/binding/erlang/impl/exceptions/ErlangException.java @@ -0,0 +1,9 @@ +package org.apache.tuscany.sca.binding.erlang.impl.exceptions; + +public class ErlangException extends Exception { + + public ErlangException(String message) { + super(message); + } + +} diff --git a/sandbox/wjaniszewski/binding-erlang-runtime/src/main/java/org/apache/tuscany/sca/binding/erlang/impl/types/TypeHelpersProxy.java b/sandbox/wjaniszewski/binding-erlang-runtime/src/main/java/org/apache/tuscany/sca/binding/erlang/impl/types/TypeHelpersProxy.java index e695f87dce..208216eef2 100644 --- a/sandbox/wjaniszewski/binding-erlang-runtime/src/main/java/org/apache/tuscany/sca/binding/erlang/impl/types/TypeHelpersProxy.java +++ b/sandbox/wjaniszewski/binding-erlang-runtime/src/main/java/org/apache/tuscany/sca/binding/erlang/impl/types/TypeHelpersProxy.java @@ -33,115 +33,122 @@ import com.ericsson.otp.erlang.OtpErlangTuple; public class TypeHelpersProxy {
- private static Map<Class<?>, TypeHelper> primitiveTypes = null;
+ private static Map<Class<?>, TypeHelper> primitiveTypes = null;
- static {
- // initiate type helpers
- primitiveTypes = new HashMap<Class<?>, TypeHelper>();
- primitiveTypes.put(boolean.class, new BooleanTypeHelper());
- primitiveTypes.put(short.class, new ShortTypeHelper());
- primitiveTypes.put(byte.class, new ByteTypeHelper());
- primitiveTypes.put(char.class, new CharTypeHelper());
- primitiveTypes.put(int.class, new IntTypeHelper());
- primitiveTypes.put(long.class, new LongTypeHelper());
- primitiveTypes.put(float.class, new FloatTypeHelper());
- primitiveTypes.put(double.class, new DoubleTypeHelper());
- primitiveTypes.put(String.class, new StringTypeHelper());
- primitiveTypes.put(Boolean.class, primitiveTypes.get(boolean.class));
- primitiveTypes.put(Character.class, primitiveTypes.get(char.class));
- primitiveTypes.put(Short.class, primitiveTypes.get(char.class));
- primitiveTypes.put(Byte.class, primitiveTypes.get(byte.class));
- primitiveTypes.put(Short.class, primitiveTypes.get(short.class));
- primitiveTypes.put(Integer.class, primitiveTypes.get(int.class));
- primitiveTypes.put(Long.class, primitiveTypes.get(long.class));
- primitiveTypes.put(Float.class, primitiveTypes.get(float.class));
- primitiveTypes.put(Double.class, primitiveTypes.get(double.class));
- primitiveTypes.put(String.class, primitiveTypes.get(String.class));
- }
+ static {
+ // initiate type helpers
+ primitiveTypes = new HashMap<Class<?>, TypeHelper>();
+ primitiveTypes.put(boolean.class, new BooleanTypeHelper());
+ primitiveTypes.put(short.class, new ShortTypeHelper());
+ primitiveTypes.put(byte.class, new ByteTypeHelper());
+ primitiveTypes.put(char.class, new CharTypeHelper());
+ primitiveTypes.put(int.class, new IntTypeHelper());
+ primitiveTypes.put(long.class, new LongTypeHelper());
+ primitiveTypes.put(float.class, new FloatTypeHelper());
+ primitiveTypes.put(double.class, new DoubleTypeHelper());
+ primitiveTypes.put(String.class, new StringTypeHelper());
+ primitiveTypes.put(Boolean.class, primitiveTypes.get(boolean.class));
+ primitiveTypes.put(Character.class, primitiveTypes.get(char.class));
+ primitiveTypes.put(Short.class, primitiveTypes.get(char.class));
+ primitiveTypes.put(Byte.class, primitiveTypes.get(byte.class));
+ primitiveTypes.put(Short.class, primitiveTypes.get(short.class));
+ primitiveTypes.put(Integer.class, primitiveTypes.get(int.class));
+ primitiveTypes.put(Long.class, primitiveTypes.get(long.class));
+ primitiveTypes.put(Float.class, primitiveTypes.get(float.class));
+ primitiveTypes.put(Double.class, primitiveTypes.get(double.class));
+ primitiveTypes.put(String.class, primitiveTypes.get(String.class));
+ }
- private static TypeHelper getTypeHelper(Class<?> forClass) {
- TypeHelper typeHelper = null;
- if (forClass.isArray()) {
- typeHelper = new ListTypeHelper();
- } else {
- typeHelper = primitiveTypes.get(forClass);
- }
- if (typeHelper == null) {
- typeHelper = new TupleTypeHelper();
- }
- return typeHelper;
- }
+ private static TypeHelper getTypeHelper(Class<?> forClass) {
+ TypeHelper typeHelper = null;
+ if (forClass.isArray()) {
+ typeHelper = new ListTypeHelper();
+ } else {
+ typeHelper = primitiveTypes.get(forClass);
+ }
+ if (typeHelper == null) {
+ typeHelper = new TupleTypeHelper();
+ }
+ return typeHelper;
+ }
- public static OtpErlangObject toErlang(Object[] objects) {
- OtpErlangObject result = null;
- if (objects != null) {
- TypeHelper helper = null;
- switch (objects.length) {
- case 0:
- result = new OtpErlangList();
- break;
- case 1:
- helper = getTypeHelper(objects[0].getClass());
- result = helper.toErlang(objects[0]);
- break;
- default:
- OtpErlangObject[] erlObjects = new OtpErlangObject[objects.length];
- for (int i = 0; i < objects.length; i++) {
- helper = getTypeHelper(objects[i].getClass());
- erlObjects[i] = helper.toErlang(objects[i]);
- }
- result = new OtpErlangTuple(erlObjects);
- break;
- }
- }
- return result;
- }
+ public static OtpErlangObject toErlang(Object[] objects) {
+ OtpErlangObject result = null;
+ if (objects != null) {
+ TypeHelper helper = null;
+ switch (objects.length) {
+ case 0:
+ result = new OtpErlangList();
+ break;
+ case 1:
+ helper = getTypeHelper(objects[0].getClass());
+ result = helper.toErlang(objects[0]);
+ break;
+ default:
+ OtpErlangObject[] erlObjects = new OtpErlangObject[objects.length];
+ for (int i = 0; i < objects.length; i++) {
+ helper = getTypeHelper(objects[i].getClass());
+ erlObjects[i] = helper.toErlang(objects[i]);
+ }
+ result = new OtpErlangTuple(erlObjects);
+ break;
+ }
+ }
+ return result;
+ }
- public static OtpErlangList toErlangAsList(Object array) {
- OtpErlangList result = null;
- if (array != null) {
- if (!array.getClass().isArray()) {
- array = new Object[] {array};
- }
- List<OtpErlangObject> attrsList = new ArrayList<OtpErlangObject>();
- int i = 0;
- while (true) {
- try {
- TypeHelper helper = getTypeHelper(Array.get(array, i).getClass());
- attrsList.add(helper.toErlang(Array.get(array, i)));
- i++;
- } catch (ArrayIndexOutOfBoundsException e) {
- break;
- }
- }
- result = new OtpErlangList(attrsList.toArray(new OtpErlangObject[attrsList.size()]));
- } else {
- result = new OtpErlangList();
- }
- return result;
- }
+ public static OtpErlangList toErlangAsList(Object array) {
+ OtpErlangList result = null;
+ if (array != null) {
+ if (!array.getClass().isArray()) {
+ array = new Object[] { array };
+ }
+ List<OtpErlangObject> attrsList = new ArrayList<OtpErlangObject>();
+ int i = 0;
+ while (true) {
+ try {
+ TypeHelper helper = getTypeHelper(Array.get(array, i)
+ .getClass());
+ attrsList.add(helper.toErlang(Array.get(array, i)));
+ i++;
+ } catch (ArrayIndexOutOfBoundsException e) {
+ break;
+ }
+ }
+ result = new OtpErlangList(attrsList
+ .toArray(new OtpErlangObject[attrsList.size()]));
+ } else {
+ result = new OtpErlangList();
+ }
+ return result;
+ }
- public static Object toJava(OtpErlangObject object, Class<?> forClass) throws Exception {
- try {
- TypeHelper helper = getTypeHelper(forClass);
- return helper.toJava(object, forClass);
- } catch (ClassCastException e) {
- throw new TypeMismatchException(forClass, object.getClass());
- }
- }
+ public static Object toJava(OtpErlangObject object, Class<?> forClass)
+ throws Exception {
+ try {
+ TypeHelper helper = getTypeHelper(forClass);
+ return helper.toJava(object, forClass);
+ } catch (ClassCastException e) {
+ throw new TypeMismatchException(forClass, object.getClass());
+ }
+ }
- public static Object[] toJavaFromList(OtpErlangList objects, Class<?>[] forClass) throws Exception {
- Object[] result = new Object[objects.arity()];
- try {
- for (int i = 0; i < objects.arity(); i++) {
- TypeHelper helper = getTypeHelper(forClass[i]);
- result[i] = helper.toJava(objects.elementAt(i), forClass[i]);
- }
- } catch (ClassCastException e) {
- e.printStackTrace();
- // throw new TypeMismatchException(forClass, objects[i].getClass());
- }
- return result;
- }
+ public static Object[] toJavaFromList(OtpErlangList objects,
+ Class<?>[] forClass) throws Exception {
+ Object[] result = new Object[objects.arity()];
+ try {
+ for (int i = 0; i < objects.arity(); i++) {
+ TypeHelper helper = getTypeHelper(forClass[i]);
+ result[i] = helper.toJava(objects.elementAt(i), forClass[i]);
+ }
+ } catch (Exception e) {
+ // type mismatch as mismatch of parameters count or parameters type
+ if (e.getClass().equals(ClassCastException.class)
+ || e.getClass()
+ .equals(ArrayIndexOutOfBoundsException.class))
+ throw new TypeMismatchException();
+ }
+ return result;
+ }
}
diff --git a/sandbox/wjaniszewski/binding-erlang-runtime/src/test/java/org/apache/tuscany/sca/binding/erlang/testing/MboxListener.java b/sandbox/wjaniszewski/binding-erlang-runtime/src/test/java/org/apache/tuscany/sca/binding/erlang/testing/MboxListener.java index 61e814b740..b5d5e67b00 100644 --- a/sandbox/wjaniszewski/binding-erlang-runtime/src/test/java/org/apache/tuscany/sca/binding/erlang/testing/MboxListener.java +++ b/sandbox/wjaniszewski/binding-erlang-runtime/src/test/java/org/apache/tuscany/sca/binding/erlang/testing/MboxListener.java @@ -27,39 +27,31 @@ import com.ericsson.otp.erlang.OtpMsg; public class MboxListener implements Runnable { - private static final long TEST_TIMEOUT = 500; - - private OtpMbox mbox; - private OtpMsg msg; - private Object response; - - public MboxListener(OtpMbox mbox, Object response) { - this.mbox = mbox; - this.response = response; - } - - public void run() { - try { - try { - msg = mbox.receiveMsg(TEST_TIMEOUT); - - if (response != null) { - Object[] args = new Object[1]; - args[0] = response; - mbox.send(msg.getSenderPid(), TypeHelpersProxy.toErlang(args)); - } - } catch (InterruptedException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } - } catch (OtpErlangExit e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } - } - - public OtpMsg getMsg() { - return msg; - } + private OtpMbox mbox; + private OtpMsg msg; + private Object response; + + public MboxListener(OtpMbox mbox, Object response) { + this.mbox = mbox; + this.response = response; + } + + public void run() { + try { + msg = mbox.receiveMsg(); + + if (response != null) { + Object[] args = new Object[1]; + args[0] = response; + mbox.send(msg.getSenderPid(), TypeHelpersProxy.toErlang(args)); + } + } catch (OtpErlangExit e) { + e.printStackTrace(); + } + } + + public OtpMsg getMsg() { + return msg; + } } diff --git a/sandbox/wjaniszewski/binding-erlang-runtime/src/test/java/org/apache/tuscany/sca/binding/erlang/testing/ReferenceServiceTestCase.java b/sandbox/wjaniszewski/binding-erlang-runtime/src/test/java/org/apache/tuscany/sca/binding/erlang/testing/ReferenceServiceTestCase.java index ff6f5c3b4f..04adb60adb 100644 --- a/sandbox/wjaniszewski/binding-erlang-runtime/src/test/java/org/apache/tuscany/sca/binding/erlang/testing/ReferenceServiceTestCase.java +++ b/sandbox/wjaniszewski/binding-erlang-runtime/src/test/java/org/apache/tuscany/sca/binding/erlang/testing/ReferenceServiceTestCase.java @@ -24,9 +24,15 @@ import static org.junit.Assert.assertEquals; import java.io.IOException; import org.apache.tuscany.sca.binding.erlang.impl.TypeMismatchException; +import org.apache.tuscany.sca.binding.erlang.impl.exceptions.ErlangException; +import org.apache.tuscany.sca.binding.erlang.testing.dynaignore.IgnorableRunner; +import org.apache.tuscany.sca.binding.erlang.testing.dynaignore.IgnoreTest; import org.apache.tuscany.sca.host.embedded.SCADomain; +import org.junit.AfterClass; +import org.junit.Before; import org.junit.BeforeClass; import org.junit.Test; +import org.junit.runner.RunWith; import com.ericsson.otp.erlang.OtpErlangAtom; import com.ericsson.otp.erlang.OtpErlangDouble; @@ -37,360 +43,439 @@ import com.ericsson.otp.erlang.OtpErlangTuple; import com.ericsson.otp.erlang.OtpMbox; import com.ericsson.otp.erlang.OtpNode; +@RunWith(IgnorableRunner.class) public class ReferenceServiceTestCase { - private static MboxInterface mboxReference; - private static ServiceTestComponent moduleReference; - private static OtpNode node; - private static OtpMbox mbox; - - @BeforeClass - public static void init() throws IOException { - SCADomain domain = SCADomain.newInstance("ErlangReference.composite"); - SCADomain.newInstance("ErlangService.composite"); - ReferenceTestComponentImpl component = domain.getService(ReferenceTestComponentImpl.class, "ReferenceTest"); - mboxReference = component.getMboxReference(); - moduleReference = component.getModuleReference(); - node = new OtpNode("MboxServer"); - mbox = node.createMbox("sendArgs"); - } - - @Test - public void testStrings() throws Exception { - String strArg = "Test message"; - String strResult = "OK"; - MboxListener mboxListener = new MboxListener(mbox, strResult); - Thread mboxThread = new Thread(mboxListener); - mboxThread.start(); - String testResult = mboxReference.sendArgs(strArg); - assertEquals(strArg, ((OtpErlangString)mboxListener.getMsg().getMsg()).stringValue()); - assertEquals(strResult, testResult); - } - - @Test - public void testBooleans() throws Exception { - boolean booleanArg = true; - boolean booleanResult = false; - MboxListener mboxListener = new MboxListener(mbox, booleanResult); - Thread mboxThread = new Thread(mboxListener); - mboxThread.start(); - boolean testResult = mboxReference.sendArgs(booleanArg); - assertEquals(booleanArg, ((OtpErlangAtom)mboxListener.getMsg().getMsg()).booleanValue()); - assertEquals(booleanResult, testResult); - } - - @Test - public void testFloats() throws Exception { - float floatArg = 1.0f; - float floatResult = 2.0f; - MboxListener mboxListener = new MboxListener(mbox, floatResult); - Thread mboxThread = new Thread(mboxListener); - mboxThread.start(); - float testResult = mboxReference.sendArgs(floatArg); - assertEquals(floatArg, ((OtpErlangDouble)mboxListener.getMsg().getMsg()).doubleValue(), 0); - assertEquals(floatResult, testResult, 0); - } - - @Test - public void testDoubles() throws Exception { - double doubleArg = 1.0f; - double doubleResult = 2.0f; - MboxListener mboxListener = new MboxListener(mbox, doubleResult); - Thread mboxThread = new Thread(mboxListener); - mboxThread.start(); - double testResult = mboxReference.sendArgs(doubleArg); - assertEquals(doubleArg, ((OtpErlangDouble)mboxListener.getMsg().getMsg()).doubleValue(), 0); - assertEquals(doubleResult, testResult, 0); - } - - @Test - public void testLongs() throws Exception { - long longArg = 1; - long longResult = 2; - MboxListener mboxListener = new MboxListener(mbox, longResult); - Thread mboxThread = new Thread(mboxListener); - mboxThread.start(); - long testResult = mboxReference.sendArgs(longArg); - assertEquals(longArg, ((OtpErlangLong)mboxListener.getMsg().getMsg()).longValue(), 0); - assertEquals(longResult, testResult, 0); - } - - @Test - public void testInts() throws Exception { - int intArg = 1; - int intResult = 2; - MboxListener mboxListener = new MboxListener(mbox, intResult); - Thread mboxThread = new Thread(mboxListener); - mboxThread.start(); - int testResult = mboxReference.sendArgs(intArg); - assertEquals(intArg, ((OtpErlangLong)mboxListener.getMsg().getMsg()).intValue(), 0); - assertEquals(intResult, testResult, 0); - } - - @Test - public void testChars() throws Exception { - char charArg = 1; - char charResult = 2; - MboxListener mboxListener = new MboxListener(mbox, charResult); - Thread mboxThread = new Thread(mboxListener); - mboxThread.start(); - char testResult = mboxReference.sendArgs(charArg); - assertEquals(charArg, ((OtpErlangLong)mboxListener.getMsg().getMsg()).charValue(), 0); - assertEquals(charResult, testResult, 0); - } - - @Test - public void testShorts() throws Exception { - short shortArg = 1; - short shortResult = 2; - MboxListener mboxListener = new MboxListener(mbox, shortResult); - Thread mboxThread = new Thread(mboxListener); - mboxThread.start(); - short testResult = mboxReference.sendArgs(shortArg); - assertEquals(shortArg, ((OtpErlangLong)mboxListener.getMsg().getMsg()).shortValue(), 0); - assertEquals(shortResult, testResult, 0); - } - - @Test - public void testBytes() throws Exception { - byte byteArg = 1; - byte byteResult = 2; - MboxListener mboxListener = new MboxListener(mbox, byteResult); - Thread mboxThread = new Thread(mboxListener); - mboxThread.start(); - byte testResult = mboxReference.sendArgs(byteArg); - assertEquals(byteArg, ((OtpErlangLong)mboxListener.getMsg().getMsg()).byteValue(), 0); - assertEquals(byteResult, testResult, 0); - } - - @Test - public void testMultipleArguments() throws Exception { - MboxListener mboxListener = new MboxListener(mbox, true); - Thread mboxThread = new Thread(mboxListener); - mboxThread.start(); - String testString = "TupleString"; - int testInt = 10; - mboxReference.sendArgs(testInt, testString); - assertEquals(testInt, ((OtpErlangLong)((OtpErlangTuple)mboxListener.getMsg().getMsg()).elementAt(0)) - .longValue()); - assertEquals(testString, ((OtpErlangString)((OtpErlangTuple)mboxListener.getMsg().getMsg()).elementAt(1)) - .stringValue()); - } - - @Test - public void testTuples() throws Exception { - StructuredTuple tupleResult = new StructuredTuple(); - tupleResult.arg1.arg1 = 1; - tupleResult.arg1.arg2 = "Tuple inside tuple"; - tupleResult.arg2 = "Tuple!"; - tupleResult.arg3 = true; - MboxListener mboxListener = new MboxListener(mbox, tupleResult); - Thread mboxThread = new Thread(mboxListener); - mboxThread.start(); - StructuredTuple testArg = new StructuredTuple(); - testArg.arg2 = "Arg2a"; - testArg.arg3 = true; - testArg.arg1.arg1 = 10; - testArg.arg1.arg2 = "Arg2b"; - StructuredTuple testResult = mboxReference.sendArgs(testArg); - assertEquals(tupleResult, testResult); - OtpErlangTuple received = (OtpErlangTuple)mboxListener.getMsg().getMsg(); - assertEquals(testArg.arg1.arg1, ((OtpErlangLong)((OtpErlangTuple)received.elementAt(0)).elementAt(0)) - .longValue()); - assertEquals(testArg.arg1.arg2, ((OtpErlangString)((OtpErlangTuple)received.elementAt(0)).elementAt(1)) - .stringValue()); - assertEquals(testArg.arg2, ((OtpErlangString)received.elementAt(1)).stringValue()); - assertEquals(testArg.arg3, ((OtpErlangAtom)received.elementAt(2)).booleanValue()); - } - - @Test - public void testLists() throws Exception { - String[] testArg = new String[] {"One", "Two", "Three"}; - MboxListener mboxListener = new MboxListener(mbox, testArg); - Thread mboxThread = new Thread(mboxListener); - mboxThread.start(); - String[] testResult = mboxReference.sendArgs(testArg); - assertEquals(testArg.length, testResult.length); - for (int i = 0; i < testArg.length; i++) { - assertEquals(testArg[i], testResult[i]); - } - OtpErlangList received = (OtpErlangList)mboxListener.getMsg().getMsg(); - assertEquals(testArg.length, received.arity()); - for (int i = 0; i < testArg.length; i++) { - assertEquals(testArg[i], ((OtpErlangString)received.elementAt(i)).stringValue()); - } - } - - @Test - public void testMultiDimLists() throws Exception { - String[][] testArg = new String[][] { {"One", "Two"}, {"Three", "Four", "Five"}, {"Six"}}; - MboxListener mboxListener = new MboxListener(mbox, testArg); - Thread mboxThread = new Thread(mboxListener); - mboxThread.start(); - String[][] testResult = mboxReference.sendArgs(testArg); - assertEquals(testArg.length, testResult.length); - for (int i = 0; i < testArg.length; i++) { - for (int j = 0; j < testArg[i].length; j++) { - assertEquals(testArg[i][j], testResult[i][j]); - } - } - OtpErlangList received = (OtpErlangList)mboxListener.getMsg().getMsg(); - assertEquals(testArg.length, received.arity()); - for (int i = 0; i < testArg.length; i++) { - for (int j = 0; j < testArg[i].length; j++) { - assertEquals(testArg[i][j], (((OtpErlangString)((OtpErlangList)received.elementAt(i)).elementAt(j)) - .stringValue())); - } - } - } - - @Test - public void typeMismatch() throws Exception { - try { - StructuredTuple arg = new StructuredTuple(); - MboxListener mboxListener = new MboxListener(mbox, true); - Thread mboxThread = new Thread(mboxListener); - mboxThread.start(); - mboxReference.sendArgs(arg); - } catch (Exception e) { - assertEquals(TypeMismatchException.class, e.getClass()); - System.out.println(e.getMessage()); - } - - try { - String[] arg = new String[] {"test"}; - MboxListener mboxListener = new MboxListener(mbox, true); - Thread mboxThread = new Thread(mboxListener); - mboxThread.start(); - mboxReference.sendArgs(arg); - } catch (Exception e) { - assertEquals(TypeMismatchException.class, e.getClass()); - System.out.println(e.getMessage()); - } - - try { - long arg = 1; - MboxListener mboxListener = new MboxListener(mbox, true); - Thread mboxThread = new Thread(mboxListener); - mboxThread.start(); - mboxReference.sendArgs(arg); - } catch (Exception e) { - assertEquals(TypeMismatchException.class, e.getClass()); - System.out.println(e.getMessage()); - } - - try { - int arg = 1; - MboxListener mboxListener = new MboxListener(mbox, true); - Thread mboxThread = new Thread(mboxListener); - mboxThread.start(); - mboxReference.sendArgs(arg); - } catch (Exception e) { - assertEquals(TypeMismatchException.class, e.getClass()); - System.out.println(e.getMessage()); - } - - try { - short arg = 1; - MboxListener mboxListener = new MboxListener(mbox, true); - Thread mboxThread = new Thread(mboxListener); - mboxThread.start(); - mboxReference.sendArgs(arg); - } catch (Exception e) { - assertEquals(TypeMismatchException.class, e.getClass()); - System.out.println(e.getMessage()); - } - - try { - char arg = 1; - MboxListener mboxListener = new MboxListener(mbox, true); - Thread mboxThread = new Thread(mboxListener); - mboxThread.start(); - mboxReference.sendArgs(arg); - } catch (Exception e) { - assertEquals(TypeMismatchException.class, e.getClass()); - System.out.println(e.getMessage()); - } - - try { - byte arg = 1; - MboxListener mboxListener = new MboxListener(mbox, true); - Thread mboxThread = new Thread(mboxListener); - mboxThread.start(); - mboxReference.sendArgs(arg); - } catch (Exception e) { - assertEquals(TypeMismatchException.class, e.getClass()); - System.out.println(e.getMessage()); - } - - try { - double arg = 1; - MboxListener mboxListener = new MboxListener(mbox, true); - Thread mboxThread = new Thread(mboxListener); - mboxThread.start(); - mboxReference.sendArgs(arg); - } catch (Exception e) { - assertEquals(TypeMismatchException.class, e.getClass()); - System.out.println(e.getMessage()); - } - - try { - float arg = 1; - MboxListener mboxListener = new MboxListener(mbox, true); - Thread mboxThread = new Thread(mboxListener); - mboxThread.start(); - mboxReference.sendArgs(arg); - } catch (Exception e) { - assertEquals(TypeMismatchException.class, e.getClass()); - System.out.println(e.getMessage()); - } - - try { - String arg = "1"; - MboxListener mboxListener = new MboxListener(mbox, true); - Thread mboxThread = new Thread(mboxListener); - mboxThread.start(); - mboxReference.sendArgs(arg); - } catch (Exception e) { - assertEquals(TypeMismatchException.class, e.getClass()); - System.out.println(e.getMessage()); - } - - try { - boolean arg = true; - MboxListener mboxListener = new MboxListener(mbox, 1); - Thread mboxThread = new Thread(mboxListener); - mboxThread.start(); - mboxReference.sendArgs(arg); - } catch (Exception e) { - assertEquals(TypeMismatchException.class, e.getClass()); - System.out.println(e.getMessage()); - } - } - - @Test - public void testRPC() throws Exception { - String[] result = moduleReference.sayHellos(); - assertEquals(2, result.length); - assertEquals("1", result[0]); - assertEquals("2", result[1]); - } - - @Test - public void testRPCWithArgs() throws Exception { - String arg1 = "One"; - String arg2 = "Two"; - String testResult = moduleReference.sayHello(arg1, arg2); - assertEquals("Hello " + arg1 + " " + arg2, testResult); - } - - @Test - public void testRPCWithComplexArgs() throws Exception { - StructuredTuple arg = new StructuredTuple(); - arg.arg1.arg2 = "Not empty"; - arg.arg2 = "Not empty"; - StructuredTuple testResult = moduleReference.passComplexArgs(arg, new String[]{"some", "array"}); - assertEquals(arg, testResult); - } + private static final String EPMD_COMMAND = "epmd"; + + private static MboxInterface mboxReference; + private static ServiceInterface moduleReference; + private static OtpNode node; + private static OtpMbox mbox; + private static Process epmdProcess; + + @BeforeClass + public static void init() throws IOException { + try { + epmdProcess = Runtime.getRuntime().exec(EPMD_COMMAND); + SCADomain domain = SCADomain + .newInstance("ErlangReference.composite"); + SCADomain.newInstance("ErlangService.composite"); + ReferenceTestComponentImpl component = domain.getService( + ReferenceTestComponentImpl.class, "ReferenceTest"); + mboxReference = component.getMboxReference(); + moduleReference = component.getModuleReference(); + node = new OtpNode("MboxServer"); + mbox = node.createMbox("sendArgs"); + } catch (IOException e) { + System.out.println("Problem executing " + EPMD_COMMAND + ": " + + e.getLocalizedMessage() + ". Tests will be IGNORED."); + } + } + + @AfterClass + public static void clean() { + if (epmdProcess != null) { + epmdProcess.destroy(); + } + } + + @Before + public void before() { + if (epmdProcess == null) { + throw new IgnoreTest(); + } + } + + @Test(timeout = 1000) + public void testStrings() throws Exception { + String strArg = "Test message"; + String strResult = "OK"; + MboxListener mboxListener = new MboxListener(mbox, strResult); + Thread mboxThread = new Thread(mboxListener); + mboxThread.start(); + String testResult = mboxReference.sendArgs(strArg); + assertEquals(strArg, ((OtpErlangString) mboxListener.getMsg().getMsg()) + .stringValue()); + assertEquals(strResult, testResult); + } + + @Test(timeout = 1000) + public void testBooleans() throws Exception { + boolean booleanArg = true; + boolean booleanResult = false; + MboxListener mboxListener = new MboxListener(mbox, booleanResult); + Thread mboxThread = new Thread(mboxListener); + mboxThread.start(); + boolean testResult = mboxReference.sendArgs(booleanArg); + assertEquals(booleanArg, ((OtpErlangAtom) mboxListener.getMsg() + .getMsg()).booleanValue()); + assertEquals(booleanResult, testResult); + } + + @Test(timeout = 1000) + public void testFloats() throws Exception { + float floatArg = 1.0f; + float floatResult = 2.0f; + MboxListener mboxListener = new MboxListener(mbox, floatResult); + Thread mboxThread = new Thread(mboxListener); + mboxThread.start(); + float testResult = mboxReference.sendArgs(floatArg); + assertEquals(floatArg, ((OtpErlangDouble) mboxListener.getMsg() + .getMsg()).doubleValue(), 0); + assertEquals(floatResult, testResult, 0); + } + + @Test(timeout = 1000) + public void testDoubles() throws Exception { + double doubleArg = 1.0f; + double doubleResult = 2.0f; + MboxListener mboxListener = new MboxListener(mbox, doubleResult); + Thread mboxThread = new Thread(mboxListener); + mboxThread.start(); + double testResult = mboxReference.sendArgs(doubleArg); + assertEquals(doubleArg, ((OtpErlangDouble) mboxListener.getMsg() + .getMsg()).doubleValue(), 0); + assertEquals(doubleResult, testResult, 0); + } + + @Test(timeout = 1000) + public void testLongs() throws Exception { + long longArg = 1; + long longResult = 2; + MboxListener mboxListener = new MboxListener(mbox, longResult); + Thread mboxThread = new Thread(mboxListener); + mboxThread.start(); + long testResult = mboxReference.sendArgs(longArg); + assertEquals(longArg, ((OtpErlangLong) mboxListener.getMsg().getMsg()) + .longValue(), 0); + assertEquals(longResult, testResult, 0); + } + + @Test(timeout = 1000) + public void testInts() throws Exception { + int intArg = 1; + int intResult = 2; + MboxListener mboxListener = new MboxListener(mbox, intResult); + Thread mboxThread = new Thread(mboxListener); + mboxThread.start(); + int testResult = mboxReference.sendArgs(intArg); + assertEquals(intArg, ((OtpErlangLong) mboxListener.getMsg().getMsg()) + .intValue(), 0); + assertEquals(intResult, testResult, 0); + } + + @Test(timeout = 1000) + public void testChars() throws Exception { + char charArg = 1; + char charResult = 2; + MboxListener mboxListener = new MboxListener(mbox, charResult); + Thread mboxThread = new Thread(mboxListener); + mboxThread.start(); + char testResult = mboxReference.sendArgs(charArg); + assertEquals(charArg, ((OtpErlangLong) mboxListener.getMsg().getMsg()) + .charValue(), 0); + assertEquals(charResult, testResult, 0); + } + + @Test(timeout = 1000) + public void testShorts() throws Exception { + short shortArg = 1; + short shortResult = 2; + MboxListener mboxListener = new MboxListener(mbox, shortResult); + Thread mboxThread = new Thread(mboxListener); + mboxThread.start(); + short testResult = mboxReference.sendArgs(shortArg); + assertEquals(shortArg, ((OtpErlangLong) mboxListener.getMsg().getMsg()) + .shortValue(), 0); + assertEquals(shortResult, testResult, 0); + } + + @Test(timeout = 1000) + public void testBytes() throws Exception { + byte byteArg = 1; + byte byteResult = 2; + MboxListener mboxListener = new MboxListener(mbox, byteResult); + Thread mboxThread = new Thread(mboxListener); + mboxThread.start(); + byte testResult = mboxReference.sendArgs(byteArg); + assertEquals(byteArg, ((OtpErlangLong) mboxListener.getMsg().getMsg()) + .byteValue(), 0); + assertEquals(byteResult, testResult, 0); + } + + @Test(timeout = 1000) + public void testMultipleArguments() throws Exception { + MboxListener mboxListener = new MboxListener(mbox, true); + Thread mboxThread = new Thread(mboxListener); + mboxThread.start(); + String testString = "TupleString"; + int testInt = 10; + mboxReference.sendArgs(testInt, testString); + assertEquals(testInt, ((OtpErlangLong) ((OtpErlangTuple) mboxListener + .getMsg().getMsg()).elementAt(0)).longValue()); + assertEquals(testString, + ((OtpErlangString) ((OtpErlangTuple) mboxListener.getMsg() + .getMsg()).elementAt(1)).stringValue()); + } + + @Test(timeout = 1000) + public void testTuples() throws Exception { + StructuredTuple tupleResult = new StructuredTuple(); + tupleResult.arg1.arg1 = 1; + tupleResult.arg1.arg2 = "Tuple inside tuple"; + tupleResult.arg2 = "Tuple!"; + tupleResult.arg3 = true; + MboxListener mboxListener = new MboxListener(mbox, tupleResult); + Thread mboxThread = new Thread(mboxListener); + mboxThread.start(); + StructuredTuple testArg = new StructuredTuple(); + testArg.arg2 = "Arg2a"; + testArg.arg3 = true; + testArg.arg1.arg1 = 10; + testArg.arg1.arg2 = "Arg2b"; + StructuredTuple testResult = mboxReference.sendArgs(testArg); + assertEquals(tupleResult, testResult); + OtpErlangTuple received = (OtpErlangTuple) mboxListener.getMsg() + .getMsg(); + assertEquals(testArg.arg1.arg1, + ((OtpErlangLong) ((OtpErlangTuple) received.elementAt(0)) + .elementAt(0)).longValue()); + assertEquals(testArg.arg1.arg2, + ((OtpErlangString) ((OtpErlangTuple) received.elementAt(0)) + .elementAt(1)).stringValue()); + assertEquals(testArg.arg2, ((OtpErlangString) received.elementAt(1)) + .stringValue()); + assertEquals(testArg.arg3, ((OtpErlangAtom) received.elementAt(2)) + .booleanValue()); + } + + @Test(timeout = 1000) + public void testLists() throws Exception { + String[] testArg = new String[] { "One", "Two", "Three" }; + MboxListener mboxListener = new MboxListener(mbox, testArg); + Thread mboxThread = new Thread(mboxListener); + mboxThread.start(); + String[] testResult = mboxReference.sendArgs(testArg); + assertEquals(testArg.length, testResult.length); + for (int i = 0; i < testArg.length; i++) { + assertEquals(testArg[i], testResult[i]); + } + OtpErlangList received = (OtpErlangList) mboxListener.getMsg().getMsg(); + assertEquals(testArg.length, received.arity()); + for (int i = 0; i < testArg.length; i++) { + assertEquals(testArg[i], ((OtpErlangString) received.elementAt(i)) + .stringValue()); + } + } + + @Test(timeout = 1000) + public void testMultiDimLists() throws Exception { + String[][] testArg = new String[][] { { "One", "Two" }, + { "Three", "Four", "Five" }, { "Six" } }; + MboxListener mboxListener = new MboxListener(mbox, testArg); + Thread mboxThread = new Thread(mboxListener); + mboxThread.start(); + String[][] testResult = mboxReference.sendArgs(testArg); + assertEquals(testArg.length, testResult.length); + for (int i = 0; i < testArg.length; i++) { + for (int j = 0; j < testArg[i].length; j++) { + assertEquals(testArg[i][j], testResult[i][j]); + } + } + OtpErlangList received = (OtpErlangList) mboxListener.getMsg().getMsg(); + assertEquals(testArg.length, received.arity()); + for (int i = 0; i < testArg.length; i++) { + for (int j = 0; j < testArg[i].length; j++) { + assertEquals(testArg[i][j], + (((OtpErlangString) ((OtpErlangList) received + .elementAt(i)).elementAt(j)).stringValue())); + } + } + } + + @Test(timeout = 1000) + public void typeMismatch() throws Exception { + try { + StructuredTuple arg = new StructuredTuple(); + MboxListener mboxListener = new MboxListener(mbox, true); + Thread mboxThread = new Thread(mboxListener); + mboxThread.start(); + mboxReference.sendArgs(arg); + } catch (Exception e) { + assertEquals(TypeMismatchException.class, e.getClass()); + System.out.println(e.getMessage()); + } + + try { + String[] arg = new String[] { "test" }; + MboxListener mboxListener = new MboxListener(mbox, true); + Thread mboxThread = new Thread(mboxListener); + mboxThread.start(); + mboxReference.sendArgs(arg); + } catch (Exception e) { + assertEquals(TypeMismatchException.class, e.getClass()); + System.out.println(e.getMessage()); + } + + try { + long arg = 1; + MboxListener mboxListener = new MboxListener(mbox, true); + Thread mboxThread = new Thread(mboxListener); + mboxThread.start(); + mboxReference.sendArgs(arg); + } catch (Exception e) { + assertEquals(TypeMismatchException.class, e.getClass()); + System.out.println(e.getMessage()); + } + + try { + int arg = 1; + MboxListener mboxListener = new MboxListener(mbox, true); + Thread mboxThread = new Thread(mboxListener); + mboxThread.start(); + mboxReference.sendArgs(arg); + } catch (Exception e) { + assertEquals(TypeMismatchException.class, e.getClass()); + System.out.println(e.getMessage()); + } + + try { + short arg = 1; + MboxListener mboxListener = new MboxListener(mbox, true); + Thread mboxThread = new Thread(mboxListener); + mboxThread.start(); + mboxReference.sendArgs(arg); + } catch (Exception e) { + assertEquals(TypeMismatchException.class, e.getClass()); + System.out.println(e.getMessage()); + } + + try { + char arg = 1; + MboxListener mboxListener = new MboxListener(mbox, true); + Thread mboxThread = new Thread(mboxListener); + mboxThread.start(); + mboxReference.sendArgs(arg); + } catch (Exception e) { + assertEquals(TypeMismatchException.class, e.getClass()); + System.out.println(e.getMessage()); + } + + try { + byte arg = 1; + MboxListener mboxListener = new MboxListener(mbox, true); + Thread mboxThread = new Thread(mboxListener); + mboxThread.start(); + mboxReference.sendArgs(arg); + } catch (Exception e) { + assertEquals(TypeMismatchException.class, e.getClass()); + System.out.println(e.getMessage()); + } + + try { + double arg = 1; + MboxListener mboxListener = new MboxListener(mbox, true); + Thread mboxThread = new Thread(mboxListener); + mboxThread.start(); + mboxReference.sendArgs(arg); + } catch (Exception e) { + assertEquals(TypeMismatchException.class, e.getClass()); + System.out.println(e.getMessage()); + } + + try { + float arg = 1; + MboxListener mboxListener = new MboxListener(mbox, true); + Thread mboxThread = new Thread(mboxListener); + mboxThread.start(); + mboxReference.sendArgs(arg); + } catch (Exception e) { + assertEquals(TypeMismatchException.class, e.getClass()); + System.out.println(e.getMessage()); + } + + try { + String arg = "1"; + MboxListener mboxListener = new MboxListener(mbox, true); + Thread mboxThread = new Thread(mboxListener); + mboxThread.start(); + mboxReference.sendArgs(arg); + } catch (Exception e) { + assertEquals(TypeMismatchException.class, e.getClass()); + System.out.println(e.getMessage()); + } + + try { + boolean arg = true; + MboxListener mboxListener = new MboxListener(mbox, 1); + Thread mboxThread = new Thread(mboxListener); + mboxThread.start(); + mboxReference.sendArgs(arg); + } catch (Exception e) { + assertEquals(TypeMismatchException.class, e.getClass()); + System.out.println(e.getMessage()); + } + } + + @Test(timeout = 1000) + public void testRPC() throws Exception { + String[] result = moduleReference.sayHellos(); + assertEquals(2, result.length); + assertEquals("1", result[0]); + assertEquals("2", result[1]); + } + + @Test(timeout = 1000) + public void testRPCWithArgs() throws Exception { + String arg1 = "One"; + String arg2 = "Two"; + String testResult = moduleReference.sayHello(arg1, arg2); + assertEquals("Hello " + arg1 + " " + arg2, testResult); + } + + @Test(timeout = 1000) + public void testRPCWithComplexArgs() throws Exception { + StructuredTuple arg = new StructuredTuple(); + arg.arg1.arg2 = "Not empty"; + arg.arg2 = "Not empty"; + StructuredTuple testResult = moduleReference.passComplexArgs(arg, + new String[] { "some", "array" }); + assertEquals(arg, testResult); + } + + @Test(timeout = 1000) + public void testUnknownFunction() throws Exception { + + //following functions differs by parameters + + try { + moduleReference.sayHello(); + } catch (Exception e) { + assertEquals(ErlangException.class, e.getClass()); + } + + try { + moduleReference.sayHello("1"); + } catch (Exception e) { + assertEquals(ErlangException.class, e.getClass()); + } + + try { + moduleReference.sayHello(1, 2); + } catch (Exception e) { + assertEquals(ErlangException.class, e.getClass()); + } + + //for following ones name not exists + + moduleReference.notExist(); + + try { + moduleReference.notExistWithException(); + } catch (Exception e) { + assertEquals(ErlangException.class, e.getClass()); + } + } } diff --git a/sandbox/wjaniszewski/binding-erlang-runtime/src/test/java/org/apache/tuscany/sca/binding/erlang/testing/ReferenceTestComponentImpl.java b/sandbox/wjaniszewski/binding-erlang-runtime/src/test/java/org/apache/tuscany/sca/binding/erlang/testing/ReferenceTestComponentImpl.java index 49a06a9256..f9f9a99054 100644 --- a/sandbox/wjaniszewski/binding-erlang-runtime/src/test/java/org/apache/tuscany/sca/binding/erlang/testing/ReferenceTestComponentImpl.java +++ b/sandbox/wjaniszewski/binding-erlang-runtime/src/test/java/org/apache/tuscany/sca/binding/erlang/testing/ReferenceTestComponentImpl.java @@ -5,7 +5,7 @@ import org.osoa.sca.annotations.Reference; public class ReferenceTestComponentImpl implements ReferenceTestComponent { private MboxInterface mboxReference; - private ServiceTestComponent moduleReference; + private ServiceInterface moduleReference; @Reference public void setMboxReference(MboxInterface mboxReference) { @@ -13,7 +13,7 @@ public class ReferenceTestComponentImpl implements ReferenceTestComponent { } @Reference - public void setModuleReference(ServiceTestComponent moduleReference) { + public void setModuleReference(ServiceInterface moduleReference) { this.moduleReference = moduleReference; } @@ -21,7 +21,7 @@ public class ReferenceTestComponentImpl implements ReferenceTestComponent { return mboxReference; } - public ServiceTestComponent getModuleReference() { + public ServiceInterface getModuleReference() { return moduleReference; } diff --git a/sandbox/wjaniszewski/binding-erlang-runtime/src/test/java/org/apache/tuscany/sca/binding/erlang/testing/ServiceInterface.java b/sandbox/wjaniszewski/binding-erlang-runtime/src/test/java/org/apache/tuscany/sca/binding/erlang/testing/ServiceInterface.java new file mode 100644 index 0000000000..33afcfb53d --- /dev/null +++ b/sandbox/wjaniszewski/binding-erlang-runtime/src/test/java/org/apache/tuscany/sca/binding/erlang/testing/ServiceInterface.java @@ -0,0 +1,20 @@ +package org.apache.tuscany.sca.binding.erlang.testing; + +public interface ServiceInterface { + + String sayHello(String arg1, String arg2); + + String[] sayHellos() throws Exception; + + StructuredTuple passComplexArgs(StructuredTuple arg1, String[] arg2); + + String sayHello() throws Exception; + + String sayHello(String arg) throws Exception; + + String sayHello(int arg1, int arg2); + + void notExistWithException() throws Exception; + + void notExist(); +} diff --git a/sandbox/wjaniszewski/binding-erlang-runtime/src/test/java/org/apache/tuscany/sca/binding/erlang/testing/ServiceTestComponent.java b/sandbox/wjaniszewski/binding-erlang-runtime/src/test/java/org/apache/tuscany/sca/binding/erlang/testing/ServiceTestComponent.java index f286627192..f5c03ef281 100644 --- a/sandbox/wjaniszewski/binding-erlang-runtime/src/test/java/org/apache/tuscany/sca/binding/erlang/testing/ServiceTestComponent.java +++ b/sandbox/wjaniszewski/binding-erlang-runtime/src/test/java/org/apache/tuscany/sca/binding/erlang/testing/ServiceTestComponent.java @@ -4,7 +4,7 @@ public interface ServiceTestComponent { String sayHello(String arg1, String arg2); - String[] sayHellos(); + String[] sayHellos() throws Exception; StructuredTuple passComplexArgs(StructuredTuple arg1, String[] arg2); diff --git a/sandbox/wjaniszewski/binding-erlang-runtime/src/test/java/org/apache/tuscany/sca/binding/erlang/testing/ServiceTestComponentImpl.java b/sandbox/wjaniszewski/binding-erlang-runtime/src/test/java/org/apache/tuscany/sca/binding/erlang/testing/ServiceTestComponentImpl.java index 11b7ace284..4d79005938 100644 --- a/sandbox/wjaniszewski/binding-erlang-runtime/src/test/java/org/apache/tuscany/sca/binding/erlang/testing/ServiceTestComponentImpl.java +++ b/sandbox/wjaniszewski/binding-erlang-runtime/src/test/java/org/apache/tuscany/sca/binding/erlang/testing/ServiceTestComponentImpl.java @@ -16,5 +16,4 @@ public class ServiceTestComponentImpl implements ServiceTestComponent { return arg1; } - } diff --git a/sandbox/wjaniszewski/binding-erlang-runtime/src/test/java/org/apache/tuscany/sca/binding/erlang/testing/dynaignore/IgnorableRunner.java b/sandbox/wjaniszewski/binding-erlang-runtime/src/test/java/org/apache/tuscany/sca/binding/erlang/testing/dynaignore/IgnorableRunner.java new file mode 100644 index 0000000000..81a17ff9dd --- /dev/null +++ b/sandbox/wjaniszewski/binding-erlang-runtime/src/test/java/org/apache/tuscany/sca/binding/erlang/testing/dynaignore/IgnorableRunner.java @@ -0,0 +1,136 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.apache.tuscany.sca.binding.erlang.testing.dynaignore; + +import org.junit.runner.Description; +import org.junit.runner.Result; +import org.junit.runner.Runner; +import org.junit.runner.notification.Failure; +import org.junit.runner.notification.RunListener; +import org.junit.runner.notification.RunNotifier; +import org.junit.runner.notification.StoppedByUserException; +import org.junit.runners.BlockJUnit4ClassRunner; +import org.junit.runners.model.InitializationError; + +public class IgnorableRunner extends Runner { + + private static final class Notifier extends RunNotifier { + private final RunNotifier notifier; + + public Notifier(final RunNotifier notifier) { + this.notifier = notifier; + } + + public void addFirstListener(final RunListener listener) { + notifier.addFirstListener(listener); + } + + public void addListener(final RunListener listener) { + notifier.addListener(listener); + } + + @Override + public boolean equals(final Object obj) { + return notifier.equals(obj); + } + + @Override + public void fireTestFailure(final Failure failure) { + if (failure.getException().getClass() == IgnoreTest.class) { + notifier.fireTestIgnored(failure.getDescription()); + } else { + notifier.fireTestFailure(failure); + } + } + + @Override + public void fireTestFinished(final Description description) { + notifier.fireTestFinished(description); + } + + @Override + public void fireTestIgnored(final Description description) { + notifier.fireTestIgnored(description); + } + + @Override + public void fireTestRunFinished(final Result result) { + notifier.fireTestRunFinished(result); + } + + @Override + public void fireTestRunStarted(final Description description) { + notifier.fireTestRunStarted(description); + } + + @Override + public void fireTestStarted(final Description description) + throws StoppedByUserException { + notifier.fireTestStarted(description); + } + + @Override + public int hashCode() { + return notifier.hashCode(); + } + + @Override + public void pleaseStop() { + notifier.pleaseStop(); + } + + @Override + public void removeListener(final RunListener listener) { + notifier.removeListener(listener); + } + + public void testAborted(final Description description, + final Throwable cause) { + ((Notifier) notifier).testAborted(description, cause); + } + + @Override + public String toString() { + return notifier.toString(); + } + + } + + Runner runner = null; + + public IgnorableRunner(Class<?> testClass) { + try { + runner = new BlockJUnit4ClassRunner(testClass); + } catch (InitializationError e) { + e.printStackTrace(); + } + } + + @Override + public Description getDescription() { + return runner.getDescription(); + } + + @Override + public void run(RunNotifier notifier) { + runner.run(new Notifier(notifier)); + } + +} diff --git a/sandbox/wjaniszewski/binding-erlang-runtime/src/test/java/org/apache/tuscany/sca/binding/erlang/testing/dynaignore/IgnoreTest.java b/sandbox/wjaniszewski/binding-erlang-runtime/src/test/java/org/apache/tuscany/sca/binding/erlang/testing/dynaignore/IgnoreTest.java new file mode 100644 index 0000000000..9a8372051c --- /dev/null +++ b/sandbox/wjaniszewski/binding-erlang-runtime/src/test/java/org/apache/tuscany/sca/binding/erlang/testing/dynaignore/IgnoreTest.java @@ -0,0 +1,26 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.apache.tuscany.sca.binding.erlang.testing.dynaignore; + +public final class IgnoreTest extends Error { + + private static final long serialVersionUID = 1L; + +} |