diff options
author | wjaniszewski <wjaniszewski@13f79535-47bb-0310-9956-ffa450edef68> | 2009-04-03 21:45:50 +0000 |
---|---|---|
committer | wjaniszewski <wjaniszewski@13f79535-47bb-0310-9956-ffa450edef68> | 2009-04-03 21:45:50 +0000 |
commit | 2de833622c128decbfe98f187105eff9e3c9d13c (patch) | |
tree | f796d86d7a7bfb88ed3c64b3fd8d0591014acc6e /branches/sca-java-1.x/modules | |
parent | 707688021dcefb93f9ceb7098d73dd695d7be7a8 (diff) |
Added configurable thread pools, fixed problem with ReferenceServiceTestCase.testMultipleMethod() test case, added writing to binding processor - problems with testing
git-svn-id: http://svn.us.apache.org/repos/asf/tuscany@761812 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'branches/sca-java-1.x/modules')
7 files changed, 208 insertions, 85 deletions
diff --git a/branches/sca-java-1.x/modules/binding-erlang-runtime/src/main/java/org/apache/tuscany/sca/binding/erlang/impl/ErlangNode.java b/branches/sca-java-1.x/modules/binding-erlang-runtime/src/main/java/org/apache/tuscany/sca/binding/erlang/impl/ErlangNode.java index 94bac31809..8a2ca44290 100644 --- a/branches/sca-java-1.x/modules/binding-erlang-runtime/src/main/java/org/apache/tuscany/sca/binding/erlang/impl/ErlangNode.java +++ b/branches/sca-java-1.x/modules/binding-erlang-runtime/src/main/java/org/apache/tuscany/sca/binding/erlang/impl/ErlangNode.java @@ -75,8 +75,7 @@ public class ErlangNode implements Runnable { } public void run() { - // FIXME: add configurable thread pools - executors = Executors.newFixedThreadPool(10); + executors = Executors.newFixedThreadPool(nodeElement.getBinding().getServiceThreadPool()); while (!stopRequested) { try { OtpConnection connection = self.accept(); @@ -92,6 +91,7 @@ public class ErlangNode implements Runnable { logger.log(Level.WARNING, "Error while authenticating client", e); } } + executors.shutdownNow(); } private void registerBinding(ErlangBinding binding, 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 0460db2c1e..8450fd48a4 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 @@ -37,7 +37,7 @@ public class MboxListener implements Runnable { public MboxListener(OtpMbox mbox, Object response) { this(mbox, response, 0); } - + public MboxListener(OtpMbox mbox, Object response, long duration) { this.mbox = mbox; this.response = response; @@ -59,6 +59,20 @@ public class MboxListener implements Runnable { } public OtpMsg getMsg() { + // Sometimes clients tries to get message which isn't fully received. + // If so - give it more tries. This sometimes caused + // NullPointerException in + // ReferenceServiceTestCase.testMultipleArguments(). + for (int i = 0; i < 3; i++) { + if (msg != null) { + return msg; + } else { + try { + Thread.sleep(100); + } catch (InterruptedException e) { + } + } + } return msg; } 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 6d9d117b0e..b602590183 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 @@ -284,7 +284,6 @@ public class ReferenceServiceTestCase { * * @throws Exception */ - // TODO: this test fails sometime @Test(timeout = 1000) public void testMultipleArguments() throws Exception { MboxListener mboxListener = new MboxListener(serMbox, true); diff --git a/branches/sca-java-1.x/modules/binding-erlang/src/main/java/org/apache/tuscany/sca/binding/erlang/ErlangBinding.java b/branches/sca-java-1.x/modules/binding-erlang/src/main/java/org/apache/tuscany/sca/binding/erlang/ErlangBinding.java index 4014dbc11f..a472e88f98 100644 --- a/branches/sca-java-1.x/modules/binding-erlang/src/main/java/org/apache/tuscany/sca/binding/erlang/ErlangBinding.java +++ b/branches/sca-java-1.x/modules/binding-erlang/src/main/java/org/apache/tuscany/sca/binding/erlang/ErlangBinding.java @@ -30,6 +30,8 @@ import org.apache.tuscany.sca.assembly.xml.Constants; public interface ErlangBinding extends Binding {
final long NO_TIMEOUT = 0;
+ // NOTE: default thread pool size
+ final int DEFAULT_THREAD_POOL = 20;
QName BINDING_ERLANG_QNAME = new QName(Constants.SCA10_TUSCANY_NS, "binding.erlang");
@@ -56,5 +58,13 @@ public interface ErlangBinding extends Binding { boolean hasTimeout();
boolean hasCookie();
+
+ int getServiceThreadPool();
+
+ void setServiceThreadPool(int threads);
+
+ boolean isDefaultTimeout();
+
+ boolean isDefaultServiceThreadPool();
}
diff --git a/branches/sca-java-1.x/modules/binding-erlang/src/main/java/org/apache/tuscany/sca/binding/erlang/impl/ErlangBindingImpl.java b/branches/sca-java-1.x/modules/binding-erlang/src/main/java/org/apache/tuscany/sca/binding/erlang/impl/ErlangBindingImpl.java index 9c0e9c82e7..17fd731063 100644 --- a/branches/sca-java-1.x/modules/binding-erlang/src/main/java/org/apache/tuscany/sca/binding/erlang/impl/ErlangBindingImpl.java +++ b/branches/sca-java-1.x/modules/binding-erlang/src/main/java/org/apache/tuscany/sca/binding/erlang/impl/ErlangBindingImpl.java @@ -37,6 +37,10 @@ public class ErlangBindingImpl implements ErlangBinding, PolicySetAttachPoint { private String module;
private boolean mbox;
private String cookie;
+ private int serviceThreadPool = DEFAULT_THREAD_POOL;
+
+ private boolean defaultTimeout = true;
+ private boolean defaultThreads = true;
private List<Intent> requiredIntents = new ArrayList<Intent>();
private List<PolicySet> policySets = new ArrayList<PolicySet>();
@@ -121,6 +125,9 @@ public class ErlangBindingImpl implements ErlangBinding, PolicySetAttachPoint { public void setTimeout(long timeout) {
// NOTE: not setting timeout or setting it to 0 will cause no timeout
this.timeout = timeout;
+ if (timeout != 0) {
+ defaultTimeout = false;
+ }
}
public String getCookie() {
@@ -139,4 +146,21 @@ public class ErlangBindingImpl implements ErlangBinding, PolicySetAttachPoint { return cookie != null && cookie.length() > 0;
}
+ public int getServiceThreadPool() {
+ return serviceThreadPool;
+ }
+
+ public void setServiceThreadPool(int threads) {
+ this.serviceThreadPool = threads;
+ this.defaultThreads = false;
+ }
+
+ public boolean isDefaultServiceThreadPool() {
+ return defaultThreads;
+ }
+
+ public boolean isDefaultTimeout() {
+ return defaultTimeout;
+ }
+
}
diff --git a/branches/sca-java-1.x/modules/binding-erlang/src/main/java/org/apache/tuscany/sca/binding/erlang/impl/ErlangBindingProcessor.java b/branches/sca-java-1.x/modules/binding-erlang/src/main/java/org/apache/tuscany/sca/binding/erlang/impl/ErlangBindingProcessor.java index b611cb2296..07b7533314 100644 --- a/branches/sca-java-1.x/modules/binding-erlang/src/main/java/org/apache/tuscany/sca/binding/erlang/impl/ErlangBindingProcessor.java +++ b/branches/sca-java-1.x/modules/binding-erlang/src/main/java/org/apache/tuscany/sca/binding/erlang/impl/ErlangBindingProcessor.java @@ -44,6 +44,13 @@ public class ErlangBindingProcessor implements private PolicyFactory policyFactory;
private PolicyAttachPointProcessor policyProcessor;
+ private static final String ATTR_COOKIE = "cookie";
+ private static final String ATTR_MBOX = "mbox";
+ private static final String ATTR_MODULE = "module";
+ private static final String ATTR_NODE = "node";
+ private static final String ATTR_SERVICE_THREAD_POOL = "serviceThreadPool";
+ private static final String ATTR_TIMEOUT = "timeout";
+
public ErlangBindingProcessor(ModelFactoryExtensionPoint modelFactories) {
this.policyFactory = modelFactories.getFactory(PolicyFactory.class);
this.policyProcessor = new PolicyAttachPointProcessor(policyFactory);
@@ -65,23 +72,34 @@ public class ErlangBindingProcessor implements // Read the policies
policyProcessor.readPolicies(binding, reader);
- binding.setNode(reader.getAttributeValue(null, "node"));
- String mboxValue = reader.getAttributeValue(null, "mbox");
+
+ binding.setNode(reader.getAttributeValue(null, ATTR_NODE));
+
+ String mboxValue = reader.getAttributeValue(null, ATTR_MBOX);
+
if (mboxValue != null && mboxValue.length() > 0) {
try {
- boolean boolMboxValue = Boolean.parseBoolean(mboxValue);
- binding.setMbox(boolMboxValue);
+ binding.setMbox(Boolean.parseBoolean(mboxValue));
} catch (Exception e) {
}
}
- String timeoutValue = reader.getAttributeValue(null, "timeout");
+
+ try {
+ binding.setTimeout(Long.parseLong(reader.getAttributeValue(null,
+ ATTR_TIMEOUT)));
+ } catch (NumberFormatException e) {
+ }
+
+ binding.setModule(reader.getAttributeValue(null, ATTR_MODULE));
+
+ binding.setCookie(reader.getAttributeValue(null, ATTR_COOKIE));
+
try {
- long longTimeoutValue = Long.parseLong(timeoutValue);
- binding.setTimeout(longTimeoutValue);
+ binding.setServiceThreadPool(Integer.parseInt(reader
+ .getAttributeValue(null, ATTR_SERVICE_THREAD_POOL)));
} catch (NumberFormatException e) {
}
- binding.setModule(reader.getAttributeValue(null, "module"));
- binding.setCookie(reader.getAttributeValue(null, "cookie"));
+
return binding;
}
@@ -91,8 +109,36 @@ public class ErlangBindingProcessor implements */
public void write(ErlangBinding model, XMLStreamWriter writer)
throws ContributionWriteException, XMLStreamException {
+
+
writer.writeStartElement(Constants.SCA10_TUSCANY_NS, "binding.erlang");
- // TODO: implement writing binding element
+
+ if (model.getCookie() != null && model.getCookie().length() > 0) {
+ writer.writeAttribute(ATTR_COOKIE, model.getCookie());
+ }
+
+ if (model.isMbox()) {
+ writer.writeAttribute(ATTR_MBOX, Boolean.TRUE.toString());
+ }
+
+ if (model.getModule() != null && model.getModule().length() > 0) {
+ writer.writeAttribute(ATTR_MODULE, model.getModule());
+ }
+
+ if (model.getNode() != null && model.getNode().length() > 0) {
+ writer.writeAttribute(ATTR_NODE, model.getNode());
+ }
+
+ if (!model.isDefaultServiceThreadPool()) {
+ writer.writeAttribute(ATTR_SERVICE_THREAD_POOL, Integer
+ .toString(model.getServiceThreadPool()));
+ }
+
+ if (!model.isDefaultTimeout()) {
+ writer.writeAttribute(ATTR_TIMEOUT, Long.toString(model
+ .getTimeout()));
+ }
+
writer.writeEndElement();
}
diff --git a/branches/sca-java-1.x/modules/binding-erlang/src/test/java/org/apache/tuscany/sca/binding/erlang/testing/ErlangBindingProcessorTestCase.java b/branches/sca-java-1.x/modules/binding-erlang/src/test/java/org/apache/tuscany/sca/binding/erlang/testing/ErlangBindingProcessorTestCase.java index 3d954d7b5c..673c735f1e 100644 --- a/branches/sca-java-1.x/modules/binding-erlang/src/test/java/org/apache/tuscany/sca/binding/erlang/testing/ErlangBindingProcessorTestCase.java +++ b/branches/sca-java-1.x/modules/binding-erlang/src/test/java/org/apache/tuscany/sca/binding/erlang/testing/ErlangBindingProcessorTestCase.java @@ -21,9 +21,11 @@ package org.apache.tuscany.sca.binding.erlang.testing; import static org.junit.Assert.assertEquals; +import java.io.ByteArrayOutputStream; import java.io.StringReader; import javax.xml.stream.XMLInputFactory; +import javax.xml.stream.XMLOutputFactory; import javax.xml.stream.XMLStreamReader; import org.apache.tuscany.sca.assembly.Composite; @@ -39,6 +41,7 @@ import org.apache.tuscany.sca.monitor.Monitor; import org.apache.tuscany.sca.monitor.MonitorFactory; import org.apache.tuscany.sca.monitor.impl.DefaultMonitorFactoryImpl; import org.junit.BeforeClass; +import org.junit.Ignore; import org.junit.Test; /** @@ -46,79 +49,106 @@ import org.junit.Test; */ public class ErlangBindingProcessorTestCase { - private static final String COMPOSITE = - "<?xml version=\"1.0\" encoding=\"ASCII\"?>" + "<composite xmlns=\"http://www.osoa.org/xmlns/sca/1.0\" xmlns:tuscany=\"http://tuscany.apache.org/xmlns/sca/1.0\" targetNamespace=\"http://binding-erlang\" name=\"binding-erlang\">" - + " <component name=\"HelloWorldComponent\">" - + " <implementation.java class=\"services.HelloWorld\"/>" - + " <service name=\"HelloWorldService\">" - + " <tuscany:binding.erlang node=\"SomeNode\" timeout=\"1000\" cookie=\"cookie\"/>" - + " </service>" - + " </component>" - + "</composite>"; - - private static final String COMPOSITE_DEFAULT_TIMEOUT = - "<?xml version=\"1.0\" encoding=\"ASCII\"?>" + "<composite xmlns=\"http://www.osoa.org/xmlns/sca/1.0\" xmlns:tuscany=\"http://tuscany.apache.org/xmlns/sca/1.0\" targetNamespace=\"http://binding-erlang\" name=\"binding-erlang\">" - + " <component name=\"HelloWorldComponent\">" - + " <implementation.java class=\"services.HelloWorld\"/>" - + " <service name=\"HelloWorldService\">" - + " <tuscany:binding.erlang node=\"SomeNode\"/>" - + " </service>" - + " </component>" - + "</composite>"; + private static final String COMPOSITE = "<?xml version=\"1.0\" encoding=\"ASCII\"?>" + + "<composite xmlns=\"http://www.osoa.org/xmlns/sca/1.0\" xmlns:tuscany=\"http://tuscany.apache.org/xmlns/sca/1.0\" targetNamespace=\"http://binding-erlang\" name=\"binding-erlang\">" + + " <component name=\"HelloWorldComponent\">" + + " <implementation.java class=\"services.HelloWorld\"/>" + + " <service name=\"HelloWorldService\">" + + " <tuscany:binding.erlang node=\"SomeNode\" timeout=\"1000\" cookie=\"cookie\" serviceThreadPool=\"1\"/>" + + " </service>" + " </component>" + "</composite>"; - private static XMLInputFactory inputFactory; - private static StAXArtifactProcessor<Object> staxProcessor; - private static Monitor monitor; + private static final String COMPOSITE_DEFAULT_TIMEOUT = "<?xml version=\"1.0\" encoding=\"ASCII\"?>" + + "<composite xmlns=\"http://www.osoa.org/xmlns/sca/1.0\" xmlns:tuscany=\"http://tuscany.apache.org/xmlns/sca/1.0\" targetNamespace=\"http://binding-erlang\" name=\"binding-erlang\">" + + " <component name=\"HelloWorldComponent\">" + + " <implementation.java class=\"services.HelloWorld\"/>" + + " <service name=\"HelloWorldService\">" + + " <tuscany:binding.erlang node=\"SomeNode\"/>" + + " </service>" + " </component>" + "</composite>"; - @BeforeClass - public static void init() throws Exception { - DefaultExtensionPointRegistry extensionPoints = new DefaultExtensionPointRegistry(); - inputFactory = XMLInputFactory.newInstance(); - // Create a monitor - UtilityExtensionPoint utilities = extensionPoints.getExtensionPoint(UtilityExtensionPoint.class); - MonitorFactory monitorFactory = new DefaultMonitorFactoryImpl(); - if (monitorFactory != null) { - monitor = monitorFactory.createMonitor(); - utilities.addUtility(monitorFactory); - } - StAXArtifactProcessorExtensionPoint staxProcessors = - new DefaultStAXArtifactProcessorExtensionPoint(extensionPoints); - staxProcessor = new ExtensibleStAXArtifactProcessor(staxProcessors, inputFactory, null, monitor); - } + private static XMLInputFactory inputFactory; + private static StAXArtifactProcessor<Object> staxProcessor; + private static Monitor monitor; - /** - * Tests reading "binding.erlang" element - * - * @throws Exception - */ - @Test - public void testLoadValidComposite() throws Exception { - XMLStreamReader reader = inputFactory.createXMLStreamReader(new StringReader(COMPOSITE)); - Composite composite = (Composite)staxProcessor.read(reader); - ErlangBinding binding = - (ErlangBinding)composite.getComponents().get(0).getServices().get(0).getBindings().get(0); - assertEquals("SomeNode", binding.getNode()); - assertEquals(1000, binding.getTimeout()); - assertEquals("cookie", binding.getCookie()); - assertEquals(true, binding.hasTimeout()); - assertEquals(true, binding.hasCookie()); - } - - /** - * Tests using default "resultTimeout" value - * - * @throws Exception - */ - @Test - public void testLoadDefaultTimeout() throws Exception { - XMLStreamReader reader = inputFactory.createXMLStreamReader(new StringReader(COMPOSITE_DEFAULT_TIMEOUT)); + @BeforeClass + public static void init() throws Exception { + DefaultExtensionPointRegistry extensionPoints = new DefaultExtensionPointRegistry(); + inputFactory = XMLInputFactory.newInstance(); + // Create a monitor + UtilityExtensionPoint utilities = extensionPoints + .getExtensionPoint(UtilityExtensionPoint.class); + MonitorFactory monitorFactory = new DefaultMonitorFactoryImpl(); + if (monitorFactory != null) { + monitor = monitorFactory.createMonitor(); + utilities.addUtility(monitorFactory); + } + StAXArtifactProcessorExtensionPoint staxProcessors = new DefaultStAXArtifactProcessorExtensionPoint( + extensionPoints); + staxProcessor = new ExtensibleStAXArtifactProcessor(staxProcessors, + inputFactory, null, monitor); + } + + /** + * Tests reading "binding.erlang" element + * + * @throws Exception + */ + @Test + public void testLoadValidComposite() throws Exception { + XMLStreamReader reader = inputFactory + .createXMLStreamReader(new StringReader(COMPOSITE)); + Composite composite = (Composite) staxProcessor.read(reader); + ErlangBinding binding = (ErlangBinding) composite.getComponents() + .get(0).getServices().get(0).getBindings().get(0); + assertEquals("SomeNode", binding.getNode()); + assertEquals(1000, binding.getTimeout()); + assertEquals("cookie", binding.getCookie()); + assertEquals(true, binding.hasTimeout()); + assertEquals(true, binding.hasCookie()); + assertEquals(1, binding.getServiceThreadPool()); + assertEquals(false, binding.isDefaultServiceThreadPool()); + assertEquals(false, binding.isDefaultTimeout()); + } + + /** + * Tests using default "resultTimeout", default thread pool, no cookie + * + * @throws Exception + */ + @Test + public void testLoadDefaultTimeout() throws Exception { + XMLStreamReader reader = inputFactory + .createXMLStreamReader(new StringReader( + COMPOSITE_DEFAULT_TIMEOUT)); + Composite composite = (Composite) staxProcessor.read(reader); + ErlangBinding binding = (ErlangBinding) composite.getComponents() + .get(0).getServices().get(0).getBindings().get(0); + assertEquals(ErlangBindingImpl.NO_TIMEOUT, binding.getTimeout()); + assertEquals(null, binding.getCookie()); + assertEquals(false, binding.hasTimeout()); + assertEquals(false, binding.hasCookie()); + assertEquals(ErlangBinding.DEFAULT_THREAD_POOL, binding + .getServiceThreadPool()); + assertEquals(true, binding.isDefaultServiceThreadPool()); + assertEquals(true, binding.isDefaultTimeout()); + } + + @Test + @Ignore("unbound namespace problem") + //FIXME: fix it + public void testWrite() throws Exception { + XMLStreamReader reader = inputFactory.createXMLStreamReader(new StringReader(COMPOSITE)); Composite composite = (Composite)staxProcessor.read(reader); - ErlangBinding binding = - (ErlangBinding)composite.getComponents().get(0).getServices().get(0).getBindings().get(0); - assertEquals(ErlangBindingImpl.NO_TIMEOUT, binding.getTimeout()); - assertEquals(null, binding.getCookie()); - assertEquals(false, binding.hasTimeout()); - assertEquals(false, binding.hasCookie()); - } - + ErlangBinding binding1 = (ErlangBinding)composite.getComponents().get(0).getServices().get(0).getBindings().get(0); + ByteArrayOutputStream bos = new ByteArrayOutputStream(); + XMLOutputFactory outputFactory = XMLOutputFactory.newInstance(); + + staxProcessor.write(composite, outputFactory.createXMLStreamWriter(bos)); + + XMLStreamReader reader2 = inputFactory.createXMLStreamReader(new StringReader(bos.toString())); + Composite composite2 = (Composite)staxProcessor.read(reader2); + ErlangBinding binding2 = (ErlangBinding)composite2.getComponents().get(0).getServices().get(0).getBindings().get(0); + + //compare binding1 to binding2 + } + } |