diff options
author | antelder <antelder@13f79535-47bb-0310-9956-ffa450edef68> | 2010-03-21 09:42:41 +0000 |
---|---|---|
committer | antelder <antelder@13f79535-47bb-0310-9956-ffa450edef68> | 2010-03-21 09:42:41 +0000 |
commit | 238ecf66b372844363a8dfc78ea08f3799775214 (patch) | |
tree | 59e38043afa79a457ddc4bc23be7c0d6300a495f /sca-java-2.x/trunk/modules/endpoint-hazelcast/src | |
parent | 07cfae8bfa80e6b266276b0da91ee1ae67c5b7ec (diff) |
Update Hazelcast registry to check for duplicate endpoints
git-svn-id: http://svn.us.apache.org/repos/asf/tuscany@925745 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to '')
2 files changed, 33 insertions, 0 deletions
diff --git a/sca-java-2.x/trunk/modules/endpoint-hazelcast/src/main/java/org/apache/tuscany/sca/endpoint/hazelcast/HazelcastEndpointRegistry.java b/sca-java-2.x/trunk/modules/endpoint-hazelcast/src/main/java/org/apache/tuscany/sca/endpoint/hazelcast/HazelcastEndpointRegistry.java index a170376e07..dae2c85608 100644 --- a/sca-java-2.x/trunk/modules/endpoint-hazelcast/src/main/java/org/apache/tuscany/sca/endpoint/hazelcast/HazelcastEndpointRegistry.java +++ b/sca-java-2.x/trunk/modules/endpoint-hazelcast/src/main/java/org/apache/tuscany/sca/endpoint/hazelcast/HazelcastEndpointRegistry.java @@ -155,6 +155,11 @@ public class HazelcastEndpointRegistry extends BaseEndpointRegistry implements E }
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 " + configURI.getDomainName() + " at " + m.getInetSocketAddress());
+ }
+
String localMemberAddr = hazelcastInstance.getCluster().getLocalMember().getInetSocketAddress().toString();
String endpointURI = endpoint.getURI();
Transaction txn = hazelcastInstance.getTransaction();
diff --git a/sca-java-2.x/trunk/modules/endpoint-hazelcast/src/test/java/org/apache/tuscany/sca/endpoint/hazelcast/MultiRegTestCase.java b/sca-java-2.x/trunk/modules/endpoint-hazelcast/src/test/java/org/apache/tuscany/sca/endpoint/hazelcast/MultiRegTestCase.java index b7f0201244..c4391e59bb 100644 --- a/sca-java-2.x/trunk/modules/endpoint-hazelcast/src/test/java/org/apache/tuscany/sca/endpoint/hazelcast/MultiRegTestCase.java +++ b/sca-java-2.x/trunk/modules/endpoint-hazelcast/src/test/java/org/apache/tuscany/sca/endpoint/hazelcast/MultiRegTestCase.java @@ -108,6 +108,34 @@ public class MultiRegTestCase { System.out.println("done"); } + @Test + public void testDuplicates() throws Exception { + HazelcastEndpointRegistry reg1 = new HazelcastEndpointRegistry(extensionPoints, null, "tuscany:foo?listen=127.0.0.1:9876&multicast=off", "bar"); + reg1.start(); + RuntimeEndpoint ep1 = createEndpoint("ep1uri"); + ep1.bind(extensionPoints, reg1); + reg1.addEndpoint(ep1); + + HazelcastEndpointRegistry reg2 = new HazelcastEndpointRegistry(extensionPoints, null, "tuscany:foo?listen=127.0.0.1:9877&multicast=off&remotes=127.0.0.1:9876", "bar"); + reg2.start(); + + try { + reg2.addEndpoint(ep1); + Assert.fail(); + } catch (IllegalStateException e) { + // expected + } + + reg1.stop(); + + Thread.sleep(200); + + // now it should work + reg2.addEndpoint(ep1); + + reg2.stop(); + } + private Endpoint assertExists(HazelcastEndpointRegistry reg, String uri) throws InterruptedException { Endpoint ep = reg.getEndpoint(uri); Assert.assertNotNull(ep); |