diff options
author | wjaniszewski <wjaniszewski@13f79535-47bb-0310-9956-ffa450edef68> | 2009-04-16 18:01:41 +0000 |
---|---|---|
committer | wjaniszewski <wjaniszewski@13f79535-47bb-0310-9956-ffa450edef68> | 2009-04-16 18:01:41 +0000 |
commit | ca64a758cac9b5bd066eda16d569f1a0e3952c9e (patch) | |
tree | 75ab46a42e06450187bc6757474a4c0539ef974a /branches/sca-java-1.x/modules/binding-erlang-runtime/src/test/java/org/apache/tuscany/sca | |
parent | c86f42066a6a005d52f534694aecd6fdc1692217 (diff) |
Added support for Erlang Atoms
git-svn-id: http://svn.us.apache.org/repos/asf/tuscany@765708 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to '')
4 files changed, 119 insertions, 12 deletions
diff --git a/branches/sca-java-1.x/modules/binding-erlang-runtime/src/test/java/org/apache/tuscany/sca/binding/erlang/testing/AtomTuple.java b/branches/sca-java-1.x/modules/binding-erlang-runtime/src/test/java/org/apache/tuscany/sca/binding/erlang/testing/AtomTuple.java new file mode 100644 index 0000000000..f0930295a7 --- /dev/null +++ b/branches/sca-java-1.x/modules/binding-erlang-runtime/src/test/java/org/apache/tuscany/sca/binding/erlang/testing/AtomTuple.java @@ -0,0 +1,30 @@ +/* + * 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; + +import org.apache.tuscany.sca.binding.erlang.meta.ErlangAtom; + +public class AtomTuple { + + @ErlangAtom + public String field1; + public int field2; + +} diff --git a/branches/sca-java-1.x/modules/binding-erlang-runtime/src/test/java/org/apache/tuscany/sca/binding/erlang/testing/MboxInterface.java b/branches/sca-java-1.x/modules/binding-erlang-runtime/src/test/java/org/apache/tuscany/sca/binding/erlang/testing/MboxInterface.java index 74ec613018..8f950d54f7 100644 --- a/branches/sca-java-1.x/modules/binding-erlang-runtime/src/test/java/org/apache/tuscany/sca/binding/erlang/testing/MboxInterface.java +++ b/branches/sca-java-1.x/modules/binding-erlang-runtime/src/test/java/org/apache/tuscany/sca/binding/erlang/testing/MboxInterface.java @@ -19,6 +19,8 @@ package org.apache.tuscany.sca.binding.erlang.testing; +import org.apache.tuscany.sca.binding.erlang.meta.ErlangAtom; + /** * @version $Rev$ $Date$ */ @@ -49,7 +51,15 @@ public interface MboxInterface { String[] sendArgs(String[] arg) throws Exception; String[][] sendArgs(String[][] arg); - + byte[] sendArgs(byte[] arg); - + + @ErlangAtom + String[] sendArgs(@ErlangAtom String arg1, AtomTuple arg2); + + @ErlangAtom + String[][] sendArgs(@ErlangAtom String[][] arg1, int arg2); + + void sendArgs(); + } diff --git a/branches/sca-java-1.x/modules/binding-erlang-runtime/src/test/java/org/apache/tuscany/sca/binding/erlang/testing/MboxListener.java b/branches/sca-java-1.x/modules/binding-erlang-runtime/src/test/java/org/apache/tuscany/sca/binding/erlang/testing/MboxListener.java index fe643fcff6..0cab5c0b0e 100644 --- a/branches/sca-java-1.x/modules/binding-erlang-runtime/src/test/java/org/apache/tuscany/sca/binding/erlang/testing/MboxListener.java +++ b/branches/sca-java-1.x/modules/binding-erlang-runtime/src/test/java/org/apache/tuscany/sca/binding/erlang/testing/MboxListener.java @@ -19,6 +19,8 @@ package org.apache.tuscany.sca.binding.erlang.testing; +import java.lang.annotation.Annotation; + import org.apache.tuscany.sca.binding.erlang.impl.types.TypeHelpersProxy; import com.ericsson.otp.erlang.OtpErlangObject; @@ -53,14 +55,16 @@ public class MboxListener implements Runnable { Thread.sleep(duration); OtpErlangPid senderPid = null; if (response != null) { - Object[] args = new Object[1]; - args[0] = response; - if (msg.getMsg().getClass().equals(OtpErlangTuple.class) && ((OtpErlangTuple) msg.getMsg()).elementAt(0).getClass().equals(OtpErlangPid.class)) { - senderPid = (OtpErlangPid) ((OtpErlangTuple) msg.getMsg()).elementAt(0); + if (msg.getMsg().getClass().equals(OtpErlangTuple.class) + && ((OtpErlangTuple) msg.getMsg()).elementAt(0) + .getClass().equals(OtpErlangPid.class)) { + senderPid = (OtpErlangPid) ((OtpErlangTuple) msg.getMsg()) + .elementAt(0); } else { senderPid = msg.getSenderPid(); } - mbox.send(senderPid, TypeHelpersProxy.toErlang(args)); + mbox.send(senderPid, TypeHelpersProxy.toErlang(response, + new Annotation[0])); } } catch (Exception e) { e.printStackTrace(); @@ -84,9 +88,9 @@ public class MboxListener implements Runnable { } } } - return msg.getMsg(); + return ((OtpErlangTuple) msg.getMsg()).elementAt(1); } catch (Exception e) { - + e.printStackTrace(); } return null; } diff --git a/branches/sca-java-1.x/modules/binding-erlang-runtime/src/test/java/org/apache/tuscany/sca/binding/erlang/testing/ReferenceServiceTestCase.java b/branches/sca-java-1.x/modules/binding-erlang-runtime/src/test/java/org/apache/tuscany/sca/binding/erlang/testing/ReferenceServiceTestCase.java index 3e0a60725e..0c80df7a04 100644 --- a/branches/sca-java-1.x/modules/binding-erlang-runtime/src/test/java/org/apache/tuscany/sca/binding/erlang/testing/ReferenceServiceTestCase.java +++ b/branches/sca-java-1.x/modules/binding-erlang-runtime/src/test/java/org/apache/tuscany/sca/binding/erlang/testing/ReferenceServiceTestCase.java @@ -32,6 +32,7 @@ import org.apache.tuscany.sca.host.embedded.SCADomain; import org.junit.AfterClass; import org.junit.Before; import org.junit.BeforeClass; +import org.junit.Ignore; import org.junit.Test; import org.junit.runner.RunWith; @@ -292,6 +293,11 @@ public class ReferenceServiceTestCase { String testString = "TupleString"; int testInt = 10; mboxReference.sendArgs(testInt, testString); + // FIXME: + // without following sleep an exception occurs: + // com.ericsson.otp.erlang.OtpErlangDecodeException: Cannot read from + // input stream + Thread.sleep(100); assertEquals(testInt, ((OtpErlangLong) ((OtpErlangTuple) mboxListener .getMsg()).elementAt(0)).longValue()); assertEquals(testString, @@ -412,6 +418,52 @@ public class ReferenceServiceTestCase { } /** + * Tests passing Erlang atoms. It provides cases for annotating result + * types, parameters and fields in java classes - tuples. + * + * @throws Exception + */ + @Test(timeout = 1000) + public void testAtoms() throws Exception { + AtomTuple arg2 = new AtomTuple(); + arg2.field1 = "test"; + String arg1 = "First arg"; + String[] strResult = { "Hello", "World" }; + MboxListener mboxListener = new MboxListener(serMbox, strResult); + Thread mboxThread = new Thread(mboxListener); + mboxThread.start(); + String[] testResult = mboxReference.sendArgs(arg1, arg2); + assertEquals(strResult[0], testResult[0]); + assertEquals(strResult[1], testResult[1]); + + assertEquals(arg1, ((OtpErlangAtom) ((OtpErlangTuple) mboxListener + .getMsg()).elementAt(0)).atomValue()); + + assertEquals( + arg2.field1, + ((OtpErlangAtom) ((OtpErlangTuple) ((OtpErlangTuple) mboxListener + .getMsg()).elementAt(1)).elementAt(0)).atomValue()); + + // test multi dimensional arrays + String[][] arg = { { "this", "is" }, { "a" }, { "test" } }; + mboxListener = new MboxListener(serMbox, arg); + mboxThread = new Thread(mboxListener); + mboxThread.start(); + String[][] multiDimRes = mboxReference.sendArgs(arg, 1); + for (int i = 0; i < arg.length; i++) { + for (int j = 0; j < arg[i].length; j++) { + assertEquals(arg[i][j], multiDimRes[i][j]); + assertEquals( + arg[i][j], + ((OtpErlangAtom) ((OtpErlangList) ((OtpErlangList) ((OtpErlangTuple) mboxListener + .getMsg()).elementAt(0)).elementAt(i)) + .elementAt(j)).atomValue()); + } + } + + } + + /** * Tests mismatched interface * * @throws Exception @@ -644,14 +696,16 @@ public class ReferenceServiceTestCase { OtpErlangObject[] argsWithSender = new OtpErlangObject[2]; argsWithSender[0] = refMbox.self(); argsWithSender[1] = tuple; - refMbox.send("sayHello", "RPCServerMbox", new OtpErlangTuple(argsWithSender)); + refMbox.send("sayHello", "RPCServerMbox", new OtpErlangTuple( + argsWithSender)); OtpErlangString result = (OtpErlangString) refMbox.receiveMsg() .getMsg(); assertEquals("Hello world !", result.stringValue()); } - + /** * Tests receiving reply without sending self PID + * * @throws Exception */ @Test(timeout = 1000) @@ -698,7 +752,8 @@ public class ReferenceServiceTestCase { OtpErlangObject[] withSender = new OtpErlangObject[2]; withSender[0] = refMbox.self(); withSender[1] = args; - refMbox.send("passComplexArgs", "RPCServerMbox", new OtpErlangTuple(withSender)); + refMbox.send("passComplexArgs", "RPCServerMbox", new OtpErlangTuple( + withSender)); OtpErlangObject result = refMbox.receiveMsg().getMsg(); assertEquals(arg1, ((OtpErlangLong) ((OtpErlangTuple) ((OtpErlangTuple) result) @@ -831,4 +886,12 @@ public class ReferenceServiceTestCase { cookieModuleReference.sayHellos(); } + @Test(timeout = 1000) + @Ignore("Nothing to test yet") + public void testMboxNoArgs() throws Exception { + // FIXME: decide what to do while invoking mbox reference with no params + // exception? log? + mboxReference.sendArgs(); + } + } |