summaryrefslogtreecommitdiffstats
path: root/sandbox/wjaniszewski/binding-erlang-runtime/src/test/java/org/apache/tuscany/sca/binding/erlang/testing/ReferenceServiceTestCase.java
diff options
context:
space:
mode:
Diffstat (limited to 'sandbox/wjaniszewski/binding-erlang-runtime/src/test/java/org/apache/tuscany/sca/binding/erlang/testing/ReferenceServiceTestCase.java')
-rw-r--r--sandbox/wjaniszewski/binding-erlang-runtime/src/test/java/org/apache/tuscany/sca/binding/erlang/testing/ReferenceServiceTestCase.java134
1 files changed, 133 insertions, 1 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 2312c5ebea..636cf124d8 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
@@ -20,6 +20,7 @@
package org.apache.tuscany.sca.binding.erlang.testing;
import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.fail;
import java.io.IOException;
@@ -35,7 +36,9 @@ 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.OtpErlangAtom;
+import com.ericsson.otp.erlang.OtpErlangBinary;
import com.ericsson.otp.erlang.OtpErlangBoolean;
import com.ericsson.otp.erlang.OtpErlangDouble;
import com.ericsson.otp.erlang.OtpErlangInt;
@@ -48,7 +51,9 @@ import com.ericsson.otp.erlang.OtpMbox;
import com.ericsson.otp.erlang.OtpNode;
/**
- * Test is annotated with test runner, which will ignore tests if epmd is not available
+ * Test is annotated with test runner, which will ignore tests if epmd is not
+ * available
+ *
* @version $Rev$ $Date$
*/
@RunWith(IgnorableRunner.class)
@@ -57,10 +62,16 @@ public class ReferenceServiceTestCase {
private static final String EPMD_COMMAND = "epmd";
private static MboxInterface mboxReference;
+ private static MboxInterface timeoutMboxReference;
+ private static MboxInterface cookieMboxReference;
private static ServiceInterface moduleReference;
+ private static ServiceInterface cookieModuleReference;
+ 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;
@@ -74,11 +85,20 @@ public class ReferenceServiceTestCase {
SCADomain.newInstance("ErlangService.composite");
ReferenceTestComponentImpl component = domain.getService(
ReferenceTestComponentImpl.class, "ReferenceTest");
+
mboxReference = component.getMboxReference();
+ timeoutMboxReference = component.getTimeoutMboxReference();
+ cookieMboxReference = component.getCookieMboxReference();
moduleReference = component.getModuleReference();
+ cookieModuleReference = component.getCookieModuleReference();
+ 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) {
@@ -268,6 +288,7 @@ public class ReferenceServiceTestCase {
*
* @throws Exception
*/
+ // TODO: this test fails sometime
@Test(timeout = 1000)
public void testMultipleArguments() throws Exception {
MboxListener mboxListener = new MboxListener(serMbox, true);
@@ -320,6 +341,30 @@ public class ReferenceServiceTestCase {
}
/**
+ * Test passing Erlang binaries
+ *
+ * @throws Exception
+ */
+ @Test(timeout = 1000)
+ public void testBinaries() throws Exception {
+ byte[] testArg = { 0, 1 };
+ MboxListener mboxListener = new MboxListener(serMbox, testArg);
+ Thread mboxThread = new Thread(mboxListener);
+ mboxThread.start();
+ byte[] testResult = mboxReference.sendArgs(testArg);
+ assertEquals(testArg.length, testResult.length);
+ for (int i = 0; i < testArg.length; i++) {
+ assertEquals(testArg[i], testResult[i]);
+ }
+ OtpErlangBinary received = (OtpErlangBinary) mboxListener.getMsg()
+ .getMsg();
+ assertEquals(testArg.length, received.size());
+ for (int i = 0; i < testArg.length; i++) {
+ assertEquals(testArg[i], received.binaryValue()[i]);
+ }
+ }
+
+ /**
* Tests passing lists
*
* @throws Exception
@@ -684,4 +729,91 @@ public class ReferenceServiceTestCase {
.elementAt(2)).booleanValue());
}
+ /**
+ * Tests timeout feature for reference binding messaging
+ *
+ * @throws Exception
+ */
+ @Test(timeout = 4000)
+ public void testMboxReferenceTimeouts() throws Exception {
+ long timeBiggerThanTimeout = 1000;
+ String stringResult = "result";
+
+ // doing test for response time bigger than declared timeout (500)
+ MboxListener mboxListener = new MboxListener(serMbox, stringResult,
+ timeBiggerThanTimeout);
+ Thread mboxThread = new Thread(mboxListener);
+ mboxThread.start();
+ try {
+ // timeout exception expected
+ timeoutMboxReference.sendArgs("");
+ fail();
+ } catch (Exception e) {
+ assertEquals(ErlangException.class, e.getClass());
+ assertEquals(e.getCause().getClass(), InterruptedException.class);
+ }
+
+ // doing test for response time smaller than declared timeout (500)
+ mboxListener = new MboxListener(serMbox, stringResult, 0);
+ mboxThread = new Thread(mboxListener);
+ mboxThread.start();
+ // expecting no timeout exception
+ String testResult = timeoutMboxReference.sendArgs("");
+ assertEquals(stringResult, testResult);
+
+ // doing test for response time which will cause timeout. This time
+ // there is no declared exception in users operation so we expect no
+ // exception and null result
+ mboxListener = new MboxListener(serMbox, new byte[1],
+ timeBiggerThanTimeout);
+ mboxThread = new Thread(mboxListener);
+ mboxThread.start();
+ // expecting no timeout exception
+ byte[] result = timeoutMboxReference.sendArgs(new byte[1]);
+ assertEquals(null, result);
+ }
+
+ /**
+ * Tests timeout feature for reference binding RPC
+ *
+ * @throws Exception
+ */
+ @Test(timeout = 4000)
+ public void testRpcReferenceTimeouts() throws Exception {
+
+ // doing test for response time which will cause timeout. Method does
+ // not
+ // declare exception so only null value will be returned
+ String result1 = timeoutModuleReference.sayHello("hello", "world");
+ assertEquals(null, result1);
+
+ // doing test for response time which will cause timeout. Method declare
+ // exception, so expecting one
+ try {
+ timeoutModuleReference.sayHellos();
+ fail();
+ } catch (Exception e) {
+ assertEquals(ErlangException.class, e.getClass());
+ }
+
+ // doing test for response time shorter than timeout
+ timeoutModuleReference.doNothing();
+ }
+
+ /**
+ * Tests timeout feature for reference binding RPC
+ *
+ * @throws Exception
+ */
+ @Test(timeout = 1000)
+ public void testReferenceCookies() throws Exception {
+ try {
+ cookieModuleReference.sayHellos();
+ fail();
+ } catch (Exception e) {
+ assertEquals(ErlangException.class, e.getClass());
+ assertEquals(OtpAuthException.class, e.getCause().getClass());
+ }
+ }
+
}