diff options
author | wjaniszewski <wjaniszewski@13f79535-47bb-0310-9956-ffa450edef68> | 2009-03-20 14:23:51 +0000 |
---|---|---|
committer | wjaniszewski <wjaniszewski@13f79535-47bb-0310-9956-ffa450edef68> | 2009-03-20 14:23:51 +0000 |
commit | fce6ad4c30b15b4284a94e7a00e084bf18748cf2 (patch) | |
tree | a49756814cc819ecb6ca2ccecfedb3f9969b274e /sandbox/wjaniszewski/binding-erlang-runtime/src/test | |
parent | e962b3bbdff3995b6871393755ccd070b78aa329 (diff) |
Added configurable timeout and cookies for service bindings. Consequence is that one SCA-Erlang node is created excusively for one service binding, so service bindings cannot share the same value in 'node' attribute like it was before. Made some other fixes.
git-svn-id: http://svn.us.apache.org/repos/asf/tuscany@756480 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to '')
5 files changed, 77 insertions, 92 deletions
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 636cf124d8..6d9d117b0e 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 @@ -34,9 +34,9 @@ import org.junit.Before; import org.junit.BeforeClass; import org.junit.Test; import org.junit.runner.RunWith; -import org.osoa.sca.ServiceRuntimeException; import com.ericsson.otp.erlang.OtpAuthException; +import com.ericsson.otp.erlang.OtpConnection; import com.ericsson.otp.erlang.OtpErlangAtom; import com.ericsson.otp.erlang.OtpErlangBinary; import com.ericsson.otp.erlang.OtpErlangBoolean; @@ -49,6 +49,8 @@ import com.ericsson.otp.erlang.OtpErlangString; import com.ericsson.otp.erlang.OtpErlangTuple; import com.ericsson.otp.erlang.OtpMbox; import com.ericsson.otp.erlang.OtpNode; +import com.ericsson.otp.erlang.OtpPeer; +import com.ericsson.otp.erlang.OtpSelf; /** * Test is annotated with test runner, which will ignore tests if epmd is not @@ -63,15 +65,12 @@ public class ReferenceServiceTestCase { private static MboxInterface mboxReference; private static MboxInterface timeoutMboxReference; - private static MboxInterface cookieMboxReference; private static ServiceInterface moduleReference; private static ServiceInterface cookieModuleReference; + private static ServiceInterface invalidCookieModuleReference; private static ServiceInterface timeoutModuleReference; - private static ServiceInterface clonedModuleReference; private static OtpNode serNode; - private static OtpNode serCookieNode; private static OtpMbox serMbox; - private static OtpMbox serCookieMbox; private static OtpNode refNode; private static OtpMbox refMbox; private static Process epmdProcess; @@ -88,17 +87,14 @@ public class ReferenceServiceTestCase { mboxReference = component.getMboxReference(); timeoutMboxReference = component.getTimeoutMboxReference(); - cookieMboxReference = component.getCookieMboxReference(); moduleReference = component.getModuleReference(); cookieModuleReference = component.getCookieModuleReference(); + invalidCookieModuleReference = component + .getInvalidCookieModuleReference(); timeoutModuleReference = component.getTimeoutModuleReference(); - clonedModuleReference = component.getClonedModuleReference(); serNode = new OtpNode("MboxServer"); - serCookieNode = new OtpNode("MboxServer"); - serCookieNode.setCookie("cookie"); serMbox = serNode.createMbox("sendArgs"); - serCookieMbox = serCookieNode.createMbox("sendArgs"); refNode = new OtpNode("MboxClient"); refMbox = refNode.createMbox("connector_to_SCA_mbox"); } catch (IOException e) { @@ -552,7 +548,7 @@ public class ReferenceServiceTestCase { * * @throws Exception */ - @Test(timeout = 1000) + @Test(timeout = 10000000) public void testRPC() throws Exception { String[] result = moduleReference.sayHellos(); assertEquals(2, result.length); @@ -636,38 +632,7 @@ public class ReferenceServiceTestCase { assertEquals(ErlangException.class, e.getClass()); } } - - /** - * Tests using multiple Erlang modules on one SCA Erlang node - * - * @throws Exception - */ - @Test(timeout = 1000) - public void testMultipleModulesOnNode() throws Exception { - String[] mr = moduleReference.sayHellos(); - String[] cmr = clonedModuleReference.sayHellos(); - assertEquals("1", mr[0]); - assertEquals("2", mr[1]); - - assertEquals("-1", cmr[0]); - assertEquals("-2", cmr[1]); - } - - /** - * Tests nodes with duplcated components (the same node and module - * parameters) - * - * @throws Exception - */ - @Test(timeout = 1000) - public void testModuleDuplicatedOnNode() throws Exception { - try { - SCADomain.newInstance("ErlangServiceModuleDuplicate.composite"); - } catch (ServiceRuntimeException e) { - assertEquals(ErlangException.class, e.getCause().getClass()); - } - } - + /** * Tests mbox with retrieving and answering with basic arguments * @@ -679,7 +644,7 @@ public class ReferenceServiceTestCase { args[0] = new OtpErlangString("world"); args[1] = new OtpErlangString("!"); OtpErlangTuple tuple = new OtpErlangTuple(args); - refMbox.send("sayHello", "RPCServer", tuple); + refMbox.send("sayHello", "RPCServerMbox", tuple); OtpErlangString result = (OtpErlangString) refMbox.receiveMsg() .getMsg(); assertEquals("Hello world !", result.stringValue()); @@ -690,7 +655,7 @@ public class ReferenceServiceTestCase { * * @throws Exception */ - @Test(timeout = 1000) + @Test(timeout = 2000) public void testMboxWithComplexArgs() throws Exception { int arg1 = 1; String arg2 = "arg2"; @@ -715,7 +680,7 @@ public class ReferenceServiceTestCase { argsContent[0] = structuredTuple; argsContent[1] = list; OtpErlangTuple args = new OtpErlangTuple(argsContent); - refMbox.send("passComplexArgs", "RPCServer", args); + refMbox.send("passComplexArgs", "RPCServerMbox", args); OtpErlangObject result = refMbox.receiveMsg().getMsg(); assertEquals(arg1, ((OtpErlangLong) ((OtpErlangTuple) ((OtpErlangTuple) result) @@ -747,7 +712,7 @@ public class ReferenceServiceTestCase { try { // timeout exception expected timeoutMboxReference.sendArgs(""); - fail(); + fail("Exception expected"); } catch (Exception e) { assertEquals(ErlangException.class, e.getClass()); assertEquals(e.getCause().getClass(), InterruptedException.class); @@ -791,7 +756,7 @@ public class ReferenceServiceTestCase { // exception, so expecting one try { timeoutModuleReference.sayHellos(); - fail(); + fail("Exception expected"); } catch (Exception e) { assertEquals(ErlangException.class, e.getClass()); } @@ -801,19 +766,51 @@ public class ReferenceServiceTestCase { } /** - * Tests timeout feature for reference binding RPC + * Tests timeout feature for service side bindings + * @throws Exception + */ + @Test(timeout = 4000) + public void testServiceTimeouts() throws Exception { + OtpSelf self = new OtpSelf("tmp_connector_" + + System.currentTimeMillis()); + OtpPeer peer = new OtpPeer("RPCServerTimeout"); + OtpConnection connection = self.connect(peer); + // delay message sending after connecting + Thread.sleep(1000); + // service binding timeout set to 500 so after that time it will give up + // and close connection + try { + connection.send("rex", new OtpErlangString("test")); + fail("Exception expected"); + } catch (Exception e) { + assertEquals(IOException.class, e.getClass()); + } + + connection = self.connect(peer); + // sending message immediately and encountering no connection close + connection.send("rex", new OtpErlangString("test")); + + } + + /** + * Tests cookie feature for both reference and service bindings RPC * * @throws Exception */ @Test(timeout = 1000) public void testReferenceCookies() throws Exception { + // testing wrong cookie try { - cookieModuleReference.sayHellos(); - fail(); + invalidCookieModuleReference.sayHellos(); + fail("Exception expected"); } catch (Exception e) { assertEquals(ErlangException.class, e.getClass()); assertEquals(OtpAuthException.class, e.getCause().getClass()); } - } + // testing correct cookie + cookieModuleReference.sayHellos(); + + } + } 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 f36a711f66..7bcc378b78 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 @@ -31,6 +31,7 @@ public class ReferenceTestComponentImpl implements ReferenceTestComponent { private MboxInterface cookieMboxReference; private ServiceInterface moduleReference; private ServiceInterface cookieModuleReference; + private ServiceInterface invalidCookieModuleReference; private ServiceInterface timeoutModuleReference; private ServiceInterface clonedModuleReference; @@ -60,6 +61,11 @@ public class ReferenceTestComponentImpl implements ReferenceTestComponent { } @Reference + public void setInvalidCookieModuleReference(ServiceInterface invalidCookieModuleReference) { + this.invalidCookieModuleReference = invalidCookieModuleReference; + } + + @Reference public void setTimeoutModuleReference(ServiceInterface timeoutModuleReference) { this.timeoutModuleReference = timeoutModuleReference; } @@ -88,6 +94,10 @@ public class ReferenceTestComponentImpl implements ReferenceTestComponent { public ServiceInterface getCookieModuleReference() { return cookieModuleReference; } + + public ServiceInterface getInvalidCookieModuleReference() { + return invalidCookieModuleReference; + } public ServiceInterface getTimeoutModuleReference() { return timeoutModuleReference; diff --git a/sandbox/wjaniszewski/binding-erlang-runtime/src/test/resources/ErlangReference.composite b/sandbox/wjaniszewski/binding-erlang-runtime/src/test/resources/ErlangReference.composite index 0d52cbae32..aa9d9f973e 100644 --- a/sandbox/wjaniszewski/binding-erlang-runtime/src/test/resources/ErlangReference.composite +++ b/sandbox/wjaniszewski/binding-erlang-runtime/src/test/resources/ErlangReference.composite @@ -14,8 +14,8 @@ <tuscany:binding.erlang node="MboxServer" mbox="true" timeout="500"/> </reference> - <reference name="timeoutMboxReference"> - <tuscany:binding.erlang node="MboxServer" mbox="true" timeout="500"/> + <reference name="cookieMboxReference"> + <tuscany:binding.erlang node="MboxServer" mbox="true" cookie="cookie"/> </reference> <reference name="moduleReference"> @@ -23,16 +23,17 @@ </reference> <reference name="cookieModuleReference"> - <tuscany:binding.erlang node="RPCServer" module="hello" cookie="cookie"/> + <tuscany:binding.erlang node="RPCServerCookie" module="hello_cookie" cookie="cookie"/> </reference> - <reference name="timeoutModuleReference"> - <tuscany:binding.erlang node="RPCServer" module="hello_timeout" timeout="500"/> + <reference name="invalidCookieModuleReference"> + <tuscany:binding.erlang node="RPCServerCookie" module="hello_cookie" cookie="invalid_cookie"/> </reference> - <reference name="clonedModuleReference"> - <tuscany:binding.erlang node="RPCServer" module="hello_clone"/> + <reference name="timeoutModuleReference"> + <tuscany:binding.erlang node="RPCServerTimeout" module="hello_timeout" timeout="500"/> </reference> + </component> </composite>
\ No newline at end of file diff --git a/sandbox/wjaniszewski/binding-erlang-runtime/src/test/resources/ErlangService.composite b/sandbox/wjaniszewski/binding-erlang-runtime/src/test/resources/ErlangService.composite index d946cd6141..6da602cffd 100644 --- a/sandbox/wjaniszewski/binding-erlang-runtime/src/test/resources/ErlangService.composite +++ b/sandbox/wjaniszewski/binding-erlang-runtime/src/test/resources/ErlangService.composite @@ -13,15 +13,7 @@ </service> <service name="ServiceTestMbox" promote="ServiceTest"> <interface.java interface="org.apache.tuscany.sca.binding.erlang.testing.ServiceTestComponent" /> - <tuscany:binding.erlang node="RPCServer" mbox="true"/> - </service> - - <component name="ServiceTestClone"> - <implementation.java class="org.apache.tuscany.sca.binding.erlang.testing.ServiceTestComponentImplClone" /> - </component> - <service name="ServiceTestClone" promote="ServiceTestClone"> - <interface.java interface="org.apache.tuscany.sca.binding.erlang.testing.ServiceTestComponent" /> - <tuscany:binding.erlang node="RPCServer" module="hello_clone"/> + <tuscany:binding.erlang node="RPCServerMbox" mbox="true"/> </service> <component name="ServiceTestTimeout"> @@ -29,7 +21,15 @@ </component> <service name="ServiceTestTimeout" promote="ServiceTestTimeout"> <interface.java interface="org.apache.tuscany.sca.binding.erlang.testing.ServiceTestComponent" /> - <tuscany:binding.erlang node="RPCServer" module="hello_timeout"/> + <tuscany:binding.erlang node="RPCServerTimeout" module="hello_timeout" timeout="500"/> + </service> + + <component name="ServiceTestCookie"> + <implementation.java class="org.apache.tuscany.sca.binding.erlang.testing.ServiceTestComponentImpl" /> + </component> + <service name="ServiceTestCookie" promote="ServiceTestCookie"> + <interface.java interface="org.apache.tuscany.sca.binding.erlang.testing.ServiceTestComponent" /> + <tuscany:binding.erlang node="RPCServerCookie" module="hello_cookie" cookie="cookie"/> </service> </composite>
\ No newline at end of file diff --git a/sandbox/wjaniszewski/binding-erlang-runtime/src/test/resources/ErlangServiceModuleDuplicate.composite b/sandbox/wjaniszewski/binding-erlang-runtime/src/test/resources/ErlangServiceModuleDuplicate.composite deleted file mode 100644 index 008b186955..0000000000 --- a/sandbox/wjaniszewski/binding-erlang-runtime/src/test/resources/ErlangServiceModuleDuplicate.composite +++ /dev/null @@ -1,23 +0,0 @@ -<composite xmlns="http://www.osoa.org/xmlns/sca/1.0" - xmlns:tuscany="http://tuscany.apache.org/xmlns/sca/1.0" - targetNamespace="http://sample" - xmlns:sample="http://sample" - name="ErlangServiceBinding"> - - <component name="ServiceTest"> - <implementation.java class="org.apache.tuscany.sca.binding.erlang.testing.ServiceTestComponentImpl" /> - </component> - <service name="ServiceTest" promote="ServiceTest"> - <interface.java interface="org.apache.tuscany.sca.binding.erlang.testing.ServiceTestComponent" /> - <tuscany:binding.erlang node="DuplicateTest" module="hello"/> - </service> - - <component name="ServiceTestClone"> - <implementation.java class="org.apache.tuscany.sca.binding.erlang.testing.ServiceTestComponentImplClone" /> - </component> - <service name="ServiceTestClone" promote="ServiceTestClone"> - <interface.java interface="org.apache.tuscany.sca.binding.erlang.testing.ServiceTestComponent" /> - <tuscany:binding.erlang node="DuplicateTest" module="hello"/> - </service> - -</composite>
\ No newline at end of file |