summaryrefslogtreecommitdiffstats
path: root/sca-java-2.x/trunk
diff options
context:
space:
mode:
authorantelder <antelder@13f79535-47bb-0310-9956-ffa450edef68>2011-05-18 12:00:54 +0000
committerantelder <antelder@13f79535-47bb-0310-9956-ffa450edef68>2011-05-18 12:00:54 +0000
commit12d682d6fe8632db6149c894dc3d77ec6f3163e6 (patch)
tree8cec5fad0776fe97885eb9a15cc18b98ca6709d1 /sca-java-2.x/trunk
parent8703d6e9b35f6139ba89525bd3bb15bd9039f3ac (diff)
Fix Hazelcast reg to properly remove entries when things are removed and update tests so properly shutdown the runtime after each test
git-svn-id: http://svn.us.apache.org/repos/asf/tuscany@1124209 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'sca-java-2.x/trunk')
-rw-r--r--sca-java-2.x/trunk/modules/domain-hazelcast/src/main/java/org/apache/tuscany/sca/registry/hazelcast/HazelcastDomainRegistry.java12
-rw-r--r--sca-java-2.x/trunk/modules/domain-node/src/test/java/org/apache/tuscany/sca/impl/Node2TestCase.java71
-rw-r--r--sca-java-2.x/trunk/modules/domain-node/src/test/java/org/apache/tuscany/sca/runtime/DomainCompositeTestCase.java5
-rw-r--r--sca-java-2.x/trunk/modules/domain-node/src/test/java/org/apache/tuscany/sca/runtime/TwoNodesTestCase.java5
4 files changed, 77 insertions, 16 deletions
diff --git a/sca-java-2.x/trunk/modules/domain-hazelcast/src/main/java/org/apache/tuscany/sca/registry/hazelcast/HazelcastDomainRegistry.java b/sca-java-2.x/trunk/modules/domain-hazelcast/src/main/java/org/apache/tuscany/sca/registry/hazelcast/HazelcastDomainRegistry.java
index 91bf6dbef3..11bc791fe1 100644
--- a/sca-java-2.x/trunk/modules/domain-hazelcast/src/main/java/org/apache/tuscany/sca/registry/hazelcast/HazelcastDomainRegistry.java
+++ b/sca-java-2.x/trunk/modules/domain-hazelcast/src/main/java/org/apache/tuscany/sca/registry/hazelcast/HazelcastDomainRegistry.java
@@ -278,7 +278,7 @@ public class HazelcastDomainRegistry extends BaseDomainRegistry implements Domai
public void addEndpoint(Endpoint endpoint) {
if (findEndpoint(endpoint.getURI()).size() > 0) {
Member m = getOwningMember(endpoint.getURI());
- throw new IllegalStateException("Endpoint " + endpoint.getURI() + " already exists in domain " + domainURI + " at " + m.getInetSocketAddress());
+ throw new IllegalStateException("Endpoint " + endpoint.getURI() + " already exists in domain " + domainURI + " at " + (m == null? "null" : m.getInetSocketAddress()));
}
String localMemberAddr = hazelcastInstance.getCluster().getLocalMember().getInetSocketAddress().toString();
@@ -549,12 +549,22 @@ public class HazelcastDomainRegistry extends BaseDomainRegistry implements Domai
Map<String, String> cs = runningComposites.get(curi);
if (cs != null) {
cs.remove(compositeURI);
+ if (cs.size() > 0) {
+ runningComposites.put(curi, cs);
+ } else {
+ runningComposites.remove(curi);
+ }
}
Map<String, List<String>> ocs = runningCompositeOwners.get(localMemberAddr);
if (ocs != null) {
List<String> xya = ocs.get(curi);
if (xya != null) {
xya.remove(compositeURI);
+ if (xya.size() > 0) {
+ runningCompositeOwners.put(localMemberAddr, ocs);
+ } else {
+ runningCompositeOwners.remove(localMemberAddr);
+ }
}
}
txn.commit();
diff --git a/sca-java-2.x/trunk/modules/domain-node/src/test/java/org/apache/tuscany/sca/impl/Node2TestCase.java b/sca-java-2.x/trunk/modules/domain-node/src/test/java/org/apache/tuscany/sca/impl/Node2TestCase.java
index dcb35995a8..dccdb051ed 100644
--- a/sca-java-2.x/trunk/modules/domain-node/src/test/java/org/apache/tuscany/sca/impl/Node2TestCase.java
+++ b/sca-java-2.x/trunk/modules/domain-node/src/test/java/org/apache/tuscany/sca/impl/Node2TestCase.java
@@ -22,7 +22,6 @@ import java.io.StringReader;
import java.util.List;
import java.util.Map;
-import javax.xml.namespace.QName;
import javax.xml.stream.XMLStreamException;
import junit.framework.Assert;
@@ -35,6 +34,7 @@ import org.apache.tuscany.sca.contribution.processor.ContributionReadException;
import org.apache.tuscany.sca.monitor.ValidationException;
import org.apache.tuscany.sca.runtime.ActivationException;
import org.apache.tuscany.sca.runtime.InstalledContribution;
+import org.junit.Ignore;
import org.junit.Test;
import org.oasisopen.sca.NoSuchDomainException;
import org.oasisopen.sca.NoSuchServiceException;
@@ -65,7 +65,9 @@ public class Node2TestCase {
@Test
public void DistributedInstall() throws NoSuchServiceException, NoSuchDomainException, ContributionReadException, ActivationException, ValidationException {
- Node nodeA = TuscanyRuntime.newInstance().createNode("uri:DistributedInstall");
+ TuscanyRuntime runtime = TuscanyRuntime.newInstance();
+ try {
+ Node nodeA = runtime.createNode("uri:DistributedInstall");
nodeA.installContribution("https://repository.apache.org/content/groups/snapshots/org/apache/tuscany/sca/samples/helloworld/2.0-SNAPSHOT/helloworld-2.0-SNAPSHOT.jar");
nodeA.installContribution("src/test/resources/export.jar");
@@ -75,7 +77,7 @@ public class Node2TestCase {
Contribution cA = nodeA.getContribution("helloworld");
Assert.assertNotNull(cA);
- Node nodeB = TuscanyRuntime.newInstance().createNode("uri:DistributedInstall");
+ Node nodeB = runtime.createNode("uri:DistributedInstall");
Assert.assertEquals(2, nodeB.getInstalledContributionURIs().size());
Assert.assertTrue(nodeB.getInstalledContributionURIs().contains("export"));
Assert.assertTrue(nodeB.getInstalledContributionURIs().contains("helloworld"));
@@ -85,6 +87,9 @@ public class Node2TestCase {
InstalledContribution ic = ((NodeImpl)nodeB).getInstalledContribution("export");
Assert.assertEquals(1, ic.getJavaExports().size());
Assert.assertEquals("sample", ic.getJavaExports().get(0));
+ } finally {
+ runtime.stop();
+ }
}
@Test
@@ -149,19 +154,25 @@ public class Node2TestCase {
@Test
public void importExportDistributedValidate() throws NoSuchServiceException, NoSuchDomainException, ContributionReadException, ActivationException, ValidationException {
- Node nodeA = TuscanyRuntime.newInstance().createNode("uri:ImportTestCase");
- nodeA.installContribution("src/test/resources/import.jar");
+ TuscanyRuntime runtime = TuscanyRuntime.newInstance();
try {
+ Node nodeA = runtime.createNode("uri:ImportTestCase");
+ nodeA.installContribution("src/test/resources/import.jar");
+ try {
+ nodeA.validateContribution("import");
+ } catch (ValidationException e) {
+ // expected
+ }
+ Node nodeB =runtime.createNode("uri:ImportTestCase");
+ nodeB.installContribution("src/test/resources/export.jar");
nodeA.validateContribution("import");
- } catch (ValidationException e) {
- // expected
+ nodeA.startComposite("import", "helloworld.composite");
+ Map<String, List<String>> scs = nodeB.getStartedCompositeURIs();
+ Assert.assertEquals(1, scs.size());
+ }finally {
+ runtime.stop();
}
- Node nodeB = TuscanyRuntime.newInstance().createNode("uri:ImportTestCase");
- nodeB.installContribution("src/test/resources/export.jar");
- nodeA.validateContribution("import");
- nodeA.startComposite("import", "helloworld.composite");
- Map<String, List<String>> scs = nodeB.getStartedCompositeURIs();
- Assert.assertEquals(1, scs.size());
+
}
@Test
@@ -183,6 +194,40 @@ public class Node2TestCase {
}
@Test
+ public void startDistributedTest() throws NoSuchServiceException, NoSuchDomainException, ContributionReadException, ActivationException, ValidationException, InterruptedException {
+ TuscanyRuntime runtime = TuscanyRuntime.newInstance();
+ try {
+ Node node = runtime.createNode("uri:ImportTestCase");
+ Node node2 = runtime.createNode("uri:ImportTestCase");
+
+ node.installContribution("src/test/resources/sample-helloworld.jar");
+ Assert.assertEquals(1, node.getInstalledContributionURIs().size());
+ Assert.assertEquals(1, node2.getInstalledContributionURIs().size());
+
+ node.startComposite("sample-helloworld", "helloworld.composite");
+ Assert.assertEquals(1, node.getStartedCompositeURIs().size());
+ Assert.assertEquals(1, node2.getStartedCompositeURIs().size());
+
+ Assert.assertEquals("helloworld.composite", node.getStartedCompositeURIs().get("sample-helloworld").get(0));
+ Assert.assertEquals("helloworld.composite", node2.getStartedCompositeURIs().get("sample-helloworld").get(0));
+
+ node.stopComposite("sample-helloworld", "helloworld.composite");
+ Assert.assertEquals(0, node.getStartedCompositeURIs().size());
+ Assert.assertEquals(0, node2.getStartedCompositeURIs().size());
+
+ node2.startComposite("sample-helloworld", "helloworld.composite");
+ Assert.assertEquals(1, node.getStartedCompositeURIs().size());
+ Assert.assertEquals("helloworld.composite", node.getStartedCompositeURIs().get("sample-helloworld").get(0));
+
+ Assert.assertEquals(1, node2.getStartedCompositeURIs().size());
+ Assert.assertEquals("helloworld.composite", node2.getStartedCompositeURIs().get("sample-helloworld").get(0));
+
+ } finally {
+ runtime.stop();
+ }
+ }
+
+ @Test
public void addDeploymentCompositeTest() throws NoSuchServiceException, NoSuchDomainException, ContributionReadException, ActivationException, ValidationException, XMLStreamException {
Node node = TuscanyRuntime.newInstance().createNode("addDeploymentCompositeTest");
String curi = node.installContribution("src/test/resources/sample-helloworld.jar");
diff --git a/sca-java-2.x/trunk/modules/domain-node/src/test/java/org/apache/tuscany/sca/runtime/DomainCompositeTestCase.java b/sca-java-2.x/trunk/modules/domain-node/src/test/java/org/apache/tuscany/sca/runtime/DomainCompositeTestCase.java
index e4f93ca85d..6edd6d454a 100644
--- a/sca-java-2.x/trunk/modules/domain-node/src/test/java/org/apache/tuscany/sca/runtime/DomainCompositeTestCase.java
+++ b/sca-java-2.x/trunk/modules/domain-node/src/test/java/org/apache/tuscany/sca/runtime/DomainCompositeTestCase.java
@@ -39,8 +39,11 @@ public class DomainCompositeTestCase {
@Test
public void distributedDomain() throws NoSuchServiceException, NoSuchDomainException, ContributionReadException, ActivationException, ValidationException {
- Node node = TuscanyRuntime.newInstance().createNode("uri:DomainCompositeTestCase");
+ TuscanyRuntime runtime = TuscanyRuntime.newInstance();
+ try {
+ Node node = runtime.createNode("uri:DomainCompositeTestCase");
testIt(node);
+ } finally { runtime.stop(); }
}
private void testIt(Node node) throws ContributionReadException, ActivationException, ValidationException {
diff --git a/sca-java-2.x/trunk/modules/domain-node/src/test/java/org/apache/tuscany/sca/runtime/TwoNodesTestCase.java b/sca-java-2.x/trunk/modules/domain-node/src/test/java/org/apache/tuscany/sca/runtime/TwoNodesTestCase.java
index 4de9215838..0b71b68d70 100644
--- a/sca-java-2.x/trunk/modules/domain-node/src/test/java/org/apache/tuscany/sca/runtime/TwoNodesTestCase.java
+++ b/sca-java-2.x/trunk/modules/domain-node/src/test/java/org/apache/tuscany/sca/runtime/TwoNodesTestCase.java
@@ -34,7 +34,9 @@ public class TwoNodesTestCase {
@Test
public void testInstallDeployable() throws NoSuchServiceException, NoSuchDomainException, ContributionReadException, ActivationException, ValidationException {
- Node node1 = TuscanyRuntime.newInstance().createNode("uri:TwoNodesTestCase?multicast=off&bind=127.0.0.1:44331");
+ TuscanyRuntime runtime = TuscanyRuntime.newInstance();
+ try {
+ Node node1 = runtime.createNode("uri:TwoNodesTestCase?multicast=off&bind=127.0.0.1:44331");
node1.installContribution("helloworld", "src/test/resources/sample-helloworld.jar", null, null);
node1.startComposite("helloworld", "helloworld.composite");
@@ -42,6 +44,7 @@ public class TwoNodesTestCase {
Helloworld helloworldService = node2.getService(Helloworld.class, "HelloworldComponent");
Assert.assertEquals("Hello petra", helloworldService.sayHello("petra"));
+ } finally { runtime.stop(); }
}
}