summaryrefslogtreecommitdiffstats
path: root/sandbox/wjaniszewski/binding-erlang-runtime/src/test/java/org/apache/tuscany
diff options
context:
space:
mode:
Diffstat (limited to 'sandbox/wjaniszewski/binding-erlang-runtime/src/test/java/org/apache/tuscany')
-rw-r--r--sandbox/wjaniszewski/binding-erlang-runtime/src/test/java/org/apache/tuscany/sca/binding/erlang/testing/MboxInterface.java3
-rw-r--r--sandbox/wjaniszewski/binding-erlang-runtime/src/test/java/org/apache/tuscany/sca/binding/erlang/testing/MboxListener.java10
-rw-r--r--sandbox/wjaniszewski/binding-erlang-runtime/src/test/java/org/apache/tuscany/sca/binding/erlang/testing/ReferenceServiceTestCase.java134
-rw-r--r--sandbox/wjaniszewski/binding-erlang-runtime/src/test/java/org/apache/tuscany/sca/binding/erlang/testing/ReferenceTestComponentImpl.java44
-rw-r--r--sandbox/wjaniszewski/binding-erlang-runtime/src/test/java/org/apache/tuscany/sca/binding/erlang/testing/ServiceInterface.java1
-rw-r--r--sandbox/wjaniszewski/binding-erlang-runtime/src/test/java/org/apache/tuscany/sca/binding/erlang/testing/ServiceTestComponentImplTimeout.java61
6 files changed, 248 insertions, 5 deletions
diff --git a/sandbox/wjaniszewski/binding-erlang-runtime/src/test/java/org/apache/tuscany/sca/binding/erlang/testing/MboxInterface.java b/sandbox/wjaniszewski/binding-erlang-runtime/src/test/java/org/apache/tuscany/sca/binding/erlang/testing/MboxInterface.java
index 0f477fe660..74ec613018 100644
--- a/sandbox/wjaniszewski/binding-erlang-runtime/src/test/java/org/apache/tuscany/sca/binding/erlang/testing/MboxInterface.java
+++ b/sandbox/wjaniszewski/binding-erlang-runtime/src/test/java/org/apache/tuscany/sca/binding/erlang/testing/MboxInterface.java
@@ -49,4 +49,7 @@ public interface MboxInterface {
String[] sendArgs(String[] arg) throws Exception;
String[][] sendArgs(String[][] arg);
+
+ byte[] sendArgs(byte[] arg);
+
}
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 e64728b01e..0460db2c1e 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
@@ -21,7 +21,6 @@ package org.apache.tuscany.sca.binding.erlang.testing;
import org.apache.tuscany.sca.binding.erlang.impl.types.TypeHelpersProxy;
-import com.ericsson.otp.erlang.OtpErlangExit;
import com.ericsson.otp.erlang.OtpMbox;
import com.ericsson.otp.erlang.OtpMsg;
@@ -33,21 +32,28 @@ public class MboxListener implements Runnable {
private OtpMbox mbox;
private OtpMsg msg;
private Object response;
+ private long duration;
public MboxListener(OtpMbox mbox, Object response) {
+ this(mbox, response, 0);
+ }
+
+ public MboxListener(OtpMbox mbox, Object response, long duration) {
this.mbox = mbox;
this.response = response;
+ this.duration = duration;
}
public void run() {
try {
msg = mbox.receiveMsg();
+ Thread.sleep(duration);
if (response != null) {
Object[] args = new Object[1];
args[0] = response;
mbox.send(msg.getSenderPid(), TypeHelpersProxy.toErlang(args));
}
- } catch (OtpErlangExit e) {
+ } catch (Exception e) {
e.printStackTrace();
}
}
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());
+ }
+ }
+
}
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 71041a2be2..f36a711f66 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
@@ -27,17 +27,41 @@ import org.osoa.sca.annotations.Reference;
public class ReferenceTestComponentImpl implements ReferenceTestComponent {
private MboxInterface mboxReference;
+ private MboxInterface timeoutMboxReference;
+ private MboxInterface cookieMboxReference;
private ServiceInterface moduleReference;
+ private ServiceInterface cookieModuleReference;
+ private ServiceInterface timeoutModuleReference;
private ServiceInterface clonedModuleReference;
@Reference
public void setMboxReference(MboxInterface mboxReference) {
this.mboxReference = mboxReference;
}
+
+ @Reference
+ public void setTimeoutMboxReference(MboxInterface timeoutMboxReference) {
+ this.timeoutMboxReference = timeoutMboxReference;
+ }
+
+ @Reference
+ public void setCookieMboxReference(MboxInterface cookieMboxReference) {
+ this.cookieMboxReference = cookieMboxReference;
+ }
@Reference
- public void setModuleReference(ServiceInterface moduleReference) {
- this.moduleReference = moduleReference;
+ public void setModuleReference(ServiceInterface timeoutModuleReference) {
+ this.moduleReference = timeoutModuleReference;
+ }
+
+ @Reference
+ public void setCookieModuleReference(ServiceInterface cookieModuleReference) {
+ this.cookieModuleReference = cookieModuleReference;
+ }
+
+ @Reference
+ public void setTimeoutModuleReference(ServiceInterface timeoutModuleReference) {
+ this.timeoutModuleReference = timeoutModuleReference;
}
@Reference
@@ -49,10 +73,26 @@ public class ReferenceTestComponentImpl implements ReferenceTestComponent {
return mboxReference;
}
+ public MboxInterface getTimeoutMboxReference() {
+ return timeoutMboxReference;
+ }
+
+ public MboxInterface getCookieMboxReference() {
+ return cookieMboxReference;
+ }
+
public ServiceInterface getModuleReference() {
return moduleReference;
}
+ public ServiceInterface getCookieModuleReference() {
+ return cookieModuleReference;
+ }
+
+ public ServiceInterface getTimeoutModuleReference() {
+ return timeoutModuleReference;
+ }
+
public ServiceInterface getClonedModuleReference() {
return clonedModuleReference;
}
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
index 95c0ea06f6..76ff3fdbe0 100644
--- 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
@@ -41,4 +41,5 @@ public interface ServiceInterface {
void notExistWithException() throws Exception;
void notExist();
+
}
diff --git a/sandbox/wjaniszewski/binding-erlang-runtime/src/test/java/org/apache/tuscany/sca/binding/erlang/testing/ServiceTestComponentImplTimeout.java b/sandbox/wjaniszewski/binding-erlang-runtime/src/test/java/org/apache/tuscany/sca/binding/erlang/testing/ServiceTestComponentImplTimeout.java
new file mode 100644
index 0000000000..bcf454837e
--- /dev/null
+++ b/sandbox/wjaniszewski/binding-erlang-runtime/src/test/java/org/apache/tuscany/sca/binding/erlang/testing/ServiceTestComponentImplTimeout.java
@@ -0,0 +1,61 @@
+/*
+ * 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;
+
+/**
+ * @version $Rev$ $Date$
+ */
+public class ServiceTestComponentImplTimeout implements ServiceTestComponent {
+
+ private long duration = 1000;
+
+ public String sayHello(String arg1, String arg2) {
+ try {
+ Thread.sleep(duration);
+ } catch (InterruptedException e) {
+ e.printStackTrace();
+ }
+ return "Bye " + arg1 + " " + arg2;
+ }
+
+ public String[] sayHellos() {
+ try {
+ Thread.sleep(duration);
+ } catch (InterruptedException e) {
+ e.printStackTrace();
+ }
+ String[] result = new String[] { "-1", "-2" };
+ return result;
+ }
+
+ public StructuredTuple passComplexArgs(StructuredTuple arg1, String[] arg2) {
+ try {
+ Thread.sleep(duration);
+ } catch (InterruptedException e) {
+ e.printStackTrace();
+ }
+ return arg1;
+ }
+
+ public void doNothing() {
+
+ }
+
+}