Skip to main content
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorslewis@composent.com2010-10-26 05:17:17 +0000
committerslewis@composent.com2010-10-26 05:17:17 +0000
commit588ad10826f9b5fef1667e2b992e44818d0e96aa (patch)
treeeebf636ced3dc81f57743462fd5495e940476706
parent38b958b2e962c46dd629f69c34f2b42bd0878ecf (diff)
downloadorg.eclipse.ecf-588ad10826f9b5fef1667e2b992e44818d0e96aa.tar.gz
org.eclipse.ecf-588ad10826f9b5fef1667e2b992e44818d0e96aa.tar.xz
org.eclipse.ecf-588ad10826f9b5fef1667e2b992e44818d0e96aa.zip
Fix for https://bugs.eclipse.org/bugs/show_bug.cgi?id=327919
-rw-r--r--providers/bundles/org.eclipse.ecf.provider.remoteservice/src/org/eclipse/ecf/provider/remoteservice/generic/RegistrySharedObject.java143
-rw-r--r--[-rwxr-xr-x]tests/bundles/org.eclipse.ecf.tests.presence/src/org/eclipse/ecf/tests/presence/AbstractChatTest.java32
-rw-r--r--[-rwxr-xr-x]tests/bundles/org.eclipse.ecf.tests.presence/src/org/eclipse/ecf/tests/presence/AbstractConnectTest.java6
-rw-r--r--tests/bundles/org.eclipse.ecf.tests.provider.xmpp/src/org/eclipse/ecf/tests/provider/xmpp/datashare/ChannelTest.java14
-rw-r--r--tests/bundles/org.eclipse.ecf.tests.provider.xmpp/src/org/eclipse/ecf/tests/provider/xmpp/remoteservice/RemoteServiceRetrieval.java84
-rw-r--r--tests/bundles/org.eclipse.ecf.tests.remoteservice.generic/src/org/eclipse/ecf/tests/remoteservice/generic/RemoteServiceProxyTest.java2
-rw-r--r--tests/bundles/org.eclipse.ecf.tests.remoteservice.generic/src/org/eclipse/ecf/tests/remoteservice/generic/RemoteServiceTest.java2
-rw-r--r--tests/bundles/org.eclipse.ecf.tests.remoteservice.generic/src/org/eclipse/ecf/tests/remoteservice/generic/RemoteServiceTrackerTest.java2
-rw-r--r--tests/bundles/org.eclipse.ecf.tests.remoteservice/src/org/eclipse/ecf/tests/remoteservice/AbstractRemoteServiceTest.java94
9 files changed, 232 insertions, 147 deletions
diff --git a/providers/bundles/org.eclipse.ecf.provider.remoteservice/src/org/eclipse/ecf/provider/remoteservice/generic/RegistrySharedObject.java b/providers/bundles/org.eclipse.ecf.provider.remoteservice/src/org/eclipse/ecf/provider/remoteservice/generic/RegistrySharedObject.java
index dfdd989ef..a639c48d7 100644
--- a/providers/bundles/org.eclipse.ecf.provider.remoteservice/src/org/eclipse/ecf/provider/remoteservice/generic/RegistrySharedObject.java
+++ b/providers/bundles/org.eclipse.ecf.provider.remoteservice/src/org/eclipse/ecf/provider/remoteservice/generic/RegistrySharedObject.java
@@ -240,17 +240,18 @@ public class RegistrySharedObject extends BaseSharedObject implements IRemoteSer
}
// Add to local registry
final RemoteServiceRegistrationImpl reg = new RemoteServiceRegistrationImpl();
- reg.publish(this, localRegistry, service, clazzes, properties);
-
- // Only send add registrations if we are connected
- if (isConnected()) {
- final ID[] targets = getTargetsFromProperties(properties);
- RemoteServiceRegistrationImpl[] regs = new RemoteServiceRegistrationImpl[] {reg};
- if (targets == null)
- sendAddRegistrations(null, null, regs);
- else
- for (int i = 0; i < targets.length; i++)
- sendAddRegistrations(targets[i], null, regs);
+ synchronized (localRegistry) {
+ reg.publish(this, localRegistry, service, clazzes, properties);
+ // Only send add registrations if we are connected
+ if (isConnected()) {
+ final ID[] targets = getTargetsFromProperties(properties);
+ RemoteServiceRegistrationImpl[] regs = new RemoteServiceRegistrationImpl[] {reg};
+ if (targets == null)
+ sendAddRegistrations(null, null, regs);
+ else
+ for (int i = 0; i < targets.length; i++)
+ sendAddRegistrations(targets[i], null, regs);
+ }
}
fireRemoteServiceListeners(createRegisteredEvent(reg));
@@ -455,6 +456,10 @@ public class RegistrySharedObject extends BaseSharedObject implements IRemoteSer
synchronized (registryUpdateRequests) {
registryUpdateRequests.clear();
}
+ synchronized (localRegistry) {
+ localRegistry.unpublishServices();
+ localRegistryUnregistrationTargets.clear();
+ }
super.dispose(containerID);
}
@@ -516,22 +521,9 @@ public class RegistrySharedObject extends BaseSharedObject implements IRemoteSer
// Skip if the targetContainerID is null
if (targetContainerID == null)
continue;
- RemoteServiceRegistryImpl remoteRegistryForContainer = null;
- // No change to the registrys while we look for the appropriate registry
- synchronized (remoteRegistrys) {
- remoteRegistryForContainer = (RemoteServiceRegistryImpl) remoteRegistrys.get(targetContainerID);
- // If one is found, then we simply add any entrys to referencesFound and we're done
- // for that container
- if (remoteRegistryForContainer != null) {
- addReferencesFromRegistry(clazz, remoteFilter, remoteRegistryForContainer, referencesFound);
- continue;
- }
- }
- // This block is only reached if remoteRegistryForContainer is null
sendRegistryUpdateRequestAndWait(targetContainerID);
- // Now we check remoteRegistrys again
synchronized (remoteRegistrys) {
- remoteRegistryForContainer = (RemoteServiceRegistryImpl) remoteRegistrys.get(targetContainerID);
+ RemoteServiceRegistryImpl remoteRegistryForContainer = (RemoteServiceRegistryImpl) remoteRegistrys.get(targetContainerID);
if (remoteRegistryForContainer != null)
addReferencesFromRegistry(clazz, remoteFilter, remoteRegistryForContainer, referencesFound);
}
@@ -1203,6 +1195,12 @@ public class RegistrySharedObject extends BaseSharedObject implements IRemoteSer
Trace.entering(Activator.PLUGIN_ID, IRemoteServiceProviderDebugOptions.METHODS_ENTERING, this.getClass(), "sendAddRegistrations", new Object[] {receiver, requestId, regs}); //$NON-NLS-1$
try {
sendSharedObjectMsgTo(receiver, SharedObjectMsg.createMsg(null, ADD_REGISTRATIONS, getLocalContainerID(), requestId, regs));
+ // if the receiver is in response to an explicit remote request (receiver != null && requestId != null)
+ // then for all registrations add a target for unregistration, so that upon unregistration we can
+ if (receiver != null && requestId != null) {
+ for (int i = 0; i < regs.length; i++)
+ addTargetForUnregister(regs[i], receiver);
+ }
} catch (final IOException e) {
log(ADD_REGISTRATION_ERROR_CODE, ADD_REGISTRATION_ERROR_MESSAGE, e);
}
@@ -1600,6 +1598,44 @@ public class RegistrySharedObject extends BaseSharedObject implements IRemoteSer
Trace.exiting(Activator.PLUGIN_ID, IRemoteServiceProviderDebugOptions.METHODS_EXITING, this.getClass(), FIRE_REQUEST);
}
+ // RemoteServiceRegistrationImpl -> List<ID>
+ private Map localRegistryUnregistrationTargets = new HashMap();
+
+ private void addTargetForUnregister(RemoteServiceRegistrationImpl serviceRegistration, ID targetContainerID) {
+ List existingTargets = (List) localRegistryUnregistrationTargets.get(serviceRegistration);
+ if (existingTargets == null) {
+ existingTargets = new ArrayList();
+ }
+ existingTargets.add(targetContainerID);
+ Trace.trace(Activator.PLUGIN_ID, "addTargetForUnregister localContainerID=" + getLocalContainerID() + ",targetContainerID=" + targetContainerID + ",serviceRegistration=" + serviceRegistration); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
+ localRegistryUnregistrationTargets.put(serviceRegistration, existingTargets);
+ }
+
+ private void sendUnregisterToTargets(RemoteServiceRegistrationImpl serviceRegistration, ID[] otherTargets) {
+ List allTargets = new ArrayList();
+ // First add in otherTargets
+ if (otherTargets != null) {
+ allTargets.addAll(Arrays.asList(otherTargets));
+ }
+ // Then add any explicitly registered targets
+ List registeredTargets = (List) localRegistryUnregistrationTargets.remove(serviceRegistration);
+ if (registeredTargets != null) {
+ allTargets.addAll(registeredTargets);
+ }
+ // Now allTargets should have all the container IDs of unregistration messages so we send to all
+ for (Iterator i = allTargets.iterator(); i.hasNext();) {
+ ID unregistrationTarget = (ID) i.next();
+ ID registrationLocalContainerID = serviceRegistration.getContainerID();
+ Long serviceId = new Long(serviceRegistration.getServiceId());
+ Trace.trace(Activator.PLUGIN_ID, "sendUnregisterToTargets " + "localContainerID=" + getLocalContainerID() + ",targetContainerID=" + unregistrationTarget + ",serviceRegistration=" + serviceRegistration); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ try {
+ this.sendSharedObjectMsgTo(unregistrationTarget, SharedObjectMsg.createMsg(UNREGISTER, new Object[] {registrationLocalContainerID, serviceId}));
+ } catch (final IOException e) {
+ log(UNREGISTER_ERROR_CODE, UNREGISTER_ERROR_MESSAGE, e);
+ }
+ }
+ }
+
protected void sendUnregister(RemoteServiceRegistrationImpl serviceRegistration) {
Trace.entering(Activator.PLUGIN_ID, IRemoteServiceProviderDebugOptions.METHODS_ENTERING, this.getClass(), "sendUnregister", new Object[] {serviceRegistration}); //$NON-NLS-1$
synchronized (localRegistry) {
@@ -1616,21 +1652,41 @@ public class RegistrySharedObject extends BaseSharedObject implements IRemoteSer
} catch (final IOException e) {
log(UNREGISTER_ERROR_CODE, UNREGISTER_ERROR_MESSAGE, e);
}
- } else
- // Send an unregister message to all targetIds
- for (int i = 0; i < targetIds.length; i++) {
- try {
- this.sendSharedObjectMsgTo(targetIds[i], SharedObjectMsg.createMsg(UNREGISTER, new Object[] {containerID, serviceId}));
- } catch (final IOException e) {
- log(UNREGISTER_ERROR_CODE, UNREGISTER_ERROR_MESSAGE, e);
- }
- }
+ }
+ // And send unregister explicitly to targets
+ sendUnregisterToTargets(serviceRegistration, targetIds);
}
}
fireRemoteServiceListeners(createUnregisteredEvent(serviceRegistration));
Trace.exiting(Activator.PLUGIN_ID, IRemoteServiceProviderDebugOptions.METHODS_EXITING, this.getClass(), "sendUnregister"); //$NON-NLS-1$
}
+ protected void handleUnregister(ID containerID, Long serviceId) {
+ Trace.entering(Activator.PLUGIN_ID, IRemoteServiceProviderDebugOptions.METHODS_ENTERING, this.getClass(), "handleUnregister", new Object[] {containerID, serviceId}); //$NON-NLS-1$
+ RemoteServiceRegistrationImpl registration = null;
+ synchronized (remoteRegistrys) {
+ // get registry for given containerID
+ final RemoteServiceRegistryImpl serviceRegistry = (RemoteServiceRegistryImpl) remoteRegistrys.get(containerID);
+ if (serviceRegistry != null) {
+ registration = serviceRegistry.findRegistrationForServiceId(serviceId.longValue());
+ if (registration != null) {
+ serviceRegistry.unpublishService(registration);
+ unregisterServiceRegistrationsForContainer(registration.getContainerID());
+ // If there are no remaining registration for this remote service registry,
+ // then remove the registry from the remoteRegistrys
+ RemoteServiceRegistrationImpl[] registrations = serviceRegistry.getRegistrations();
+ Trace.trace(Activator.PLUGIN_ID, "handleUnregister localContainerID=" + getLocalContainerID() + ",registrationRemoved=" + registration + ",containerID=" + containerID); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
+ if (registrations.length == 0) {
+ remoteRegistrys.remove(containerID);
+ }
+ }
+ }
+ }
+ if (registration != null)
+ fireRemoteServiceListeners(createUnregisteredEvent(registration));
+ Trace.exiting(Activator.PLUGIN_ID, IRemoteServiceProviderDebugOptions.METHODS_EXITING, this.getClass(), "handleUnregister"); //$NON-NLS-1$
+ }
+
/**
* @since 3.2
*/
@@ -1662,25 +1718,6 @@ public class RegistrySharedObject extends BaseSharedObject implements IRemoteSer
}
}
- protected void handleUnregister(ID containerID, Long serviceId) {
- Trace.entering(Activator.PLUGIN_ID, IRemoteServiceProviderDebugOptions.METHODS_ENTERING, this.getClass(), "handleUnregister", new Object[] {containerID, serviceId}); //$NON-NLS-1$
- RemoteServiceRegistrationImpl registration = null;
- synchronized (remoteRegistrys) {
- // get registry for given containerID
- final RemoteServiceRegistryImpl serviceRegistry = (RemoteServiceRegistryImpl) remoteRegistrys.get(containerID);
- if (serviceRegistry != null) {
- registration = serviceRegistry.findRegistrationForServiceId(serviceId.longValue());
- if (registration != null) {
- serviceRegistry.unpublishService(registration);
- unregisterServiceRegistrationsForContainer(registration.getContainerID());
- }
- }
- }
- if (registration != null)
- fireRemoteServiceListeners(createUnregisteredEvent(registration));
- Trace.exiting(Activator.PLUGIN_ID, IRemoteServiceProviderDebugOptions.METHODS_EXITING, this.getClass(), "handleUnregister"); //$NON-NLS-1$
- }
-
protected IRemoteServiceUnregisteredEvent createUnregisteredEvent(final RemoteServiceRegistrationImpl registration) {
return new IRemoteServiceUnregisteredEvent() {
diff --git a/tests/bundles/org.eclipse.ecf.tests.presence/src/org/eclipse/ecf/tests/presence/AbstractChatTest.java b/tests/bundles/org.eclipse.ecf.tests.presence/src/org/eclipse/ecf/tests/presence/AbstractChatTest.java
index 659400c3e..30ccd3f04 100755..100644
--- a/tests/bundles/org.eclipse.ecf.tests.presence/src/org/eclipse/ecf/tests/presence/AbstractChatTest.java
+++ b/tests/bundles/org.eclipse.ecf.tests.presence/src/org/eclipse/ecf/tests/presence/AbstractChatTest.java
@@ -30,14 +30,18 @@ import org.eclipse.ecf.presence.im.IChatMessageEvent;
public abstract class AbstractChatTest extends AbstractPresenceTestCase {
IChatManager chat0, chat1 = null;
- public static final int WAITTIME = 3000;
+ public static final int SLEEPTIME = new Integer(
+ System.getProperty(
+ "org.eclipse.ecf.tests.presence.AbstractChatTest.SLEEPTIME",
+ "5000")).intValue();
List receivedChatMessages = new ArrayList();
IIMMessageListener listener = new IIMMessageListener() {
public void handleMessageEvent(IIMMessageEvent messageEvent) {
if (messageEvent instanceof IChatMessageEvent) {
- final IChatMessage chatmessage = ((IChatMessageEvent) messageEvent).getChatMessage();
+ final IChatMessage chatmessage = ((IChatMessageEvent) messageEvent)
+ .getChatMessage();
System.out.println("received chat message=" + chatmessage);
receivedChatMessages.add(chatmessage);
}
@@ -58,7 +62,6 @@ public abstract class AbstractChatTest extends AbstractPresenceTestCase {
chat1.addMessageListener(listener);
for (int i = 0; i < 2; i++) {
connectClient(i);
- sleep(WAITTIME);
}
}
@@ -73,9 +76,9 @@ public abstract class AbstractChatTest extends AbstractPresenceTestCase {
}
public void testSendIM() throws Exception {
- sleep(WAITTIME);
- chat0.getChatMessageSender().sendChatMessage(getClient(1).getConnectedID(), "abcdef");
- sleep(WAITTIME);
+ chat0.getChatMessageSender().sendChatMessage(
+ getClient(1).getConnectedID(), "abcdef");
+ sleep(SLEEPTIME);
assertHasEvent(receivedChatMessages, IChatMessage.class);
final IChatMessage message = (IChatMessage) receivedChatMessages.get(0);
assertTrue(message.getBody().equals("abcdef"));
@@ -87,13 +90,15 @@ public abstract class AbstractChatTest extends AbstractPresenceTestCase {
}
public void testSendIM2() throws Exception {
- sleep(WAITTIME);
final Map sendprops = new HashMap();
sendprops.put("prop1", "this");
- final ID sendthreadid = IDFactory.getDefault().createStringID("thread1");
+ final ID sendthreadid = IDFactory.getDefault()
+ .createStringID("thread1");
// Send the whole thing
- chat0.getChatMessageSender().sendChatMessage(getClient(1).getConnectedID(), sendthreadid, IChatMessage.Type.CHAT, "subject1", "uvwxyz", sendprops);
- sleep(WAITTIME);
+ chat0.getChatMessageSender().sendChatMessage(
+ getClient(1).getConnectedID(), sendthreadid,
+ IChatMessage.Type.CHAT, "subject1", "uvwxyz", sendprops);
+ sleep(SLEEPTIME);
assertHasEvent(receivedChatMessages, IChatMessage.class);
final IChatMessage message = (IChatMessage) receivedChatMessages.get(0);
@@ -111,12 +116,13 @@ public abstract class AbstractChatTest extends AbstractPresenceTestCase {
}
public void testSendMessageProperties() throws Exception {
- sleep(WAITTIME);
final Map sendprops = new HashMap();
sendprops.put("prop2", "that");
// Send the whole thing
- chat0.getChatMessageSender().sendChatMessage(getClient(1).getConnectedID(), null, IChatMessage.Type.CHAT, null, null, sendprops);
- sleep(WAITTIME);
+ chat0.getChatMessageSender().sendChatMessage(
+ getClient(1).getConnectedID(), null, IChatMessage.Type.CHAT,
+ null, null, sendprops);
+ sleep(SLEEPTIME);
assertHasEvent(receivedChatMessages, IChatMessage.class);
final IChatMessage message = (IChatMessage) receivedChatMessages.get(0);
diff --git a/tests/bundles/org.eclipse.ecf.tests.presence/src/org/eclipse/ecf/tests/presence/AbstractConnectTest.java b/tests/bundles/org.eclipse.ecf.tests.presence/src/org/eclipse/ecf/tests/presence/AbstractConnectTest.java
index cd864677e..e1062fa06 100755..100644
--- a/tests/bundles/org.eclipse.ecf.tests.presence/src/org/eclipse/ecf/tests/presence/AbstractConnectTest.java
+++ b/tests/bundles/org.eclipse.ecf.tests.presence/src/org/eclipse/ecf/tests/presence/AbstractConnectTest.java
@@ -20,7 +20,9 @@ import org.eclipse.ecf.core.identity.ID;
public abstract class AbstractConnectTest extends AbstractPresenceTestCase {
public static final int CLIENT_COUNT = 2;
- public static final int WAITTIME = 3000;
+ public static final int SLEEPTIME = new Integer(System.getProperty(
+ "org.eclipse.ecf.tests.presence.AbstractConnectTest.SLEEPTIME", "1000"))
+ .intValue();
protected void setUp() throws Exception {
super.setUp();
@@ -36,7 +38,7 @@ public abstract class AbstractConnectTest extends AbstractPresenceTestCase {
assertNotNull(serverConnectID);
connectClient(client, serverConnectID, getConnectContext(clientIndex));
assertEquals(serverConnectID, client.getConnectedID());
- sleep(WAITTIME);
+ sleep(SLEEPTIME);
client.disconnect();
assertNull(client.getConnectedID());
}
diff --git a/tests/bundles/org.eclipse.ecf.tests.provider.xmpp/src/org/eclipse/ecf/tests/provider/xmpp/datashare/ChannelTest.java b/tests/bundles/org.eclipse.ecf.tests.provider.xmpp/src/org/eclipse/ecf/tests/provider/xmpp/datashare/ChannelTest.java
index fd4771965..a1a529a59 100644
--- a/tests/bundles/org.eclipse.ecf.tests.provider.xmpp/src/org/eclipse/ecf/tests/provider/xmpp/datashare/ChannelTest.java
+++ b/tests/bundles/org.eclipse.ecf.tests.provider.xmpp/src/org/eclipse/ecf/tests/provider/xmpp/datashare/ChannelTest.java
@@ -26,6 +26,8 @@ public class ChannelTest extends ContainerAbstractTestCase {
private static final String CHANNEL_NAME = "channel";
+ private static final int SLEEPTIME = new Integer(System.getProperty("org.eclipse.ecf.tests.provider.xmpp.datashare.ChannelTest.SLEEPTIME","5000")).intValue();
+
private static final int SEND_MESSAGE_COUNT = 5;
private ID channelID;
@@ -65,7 +67,7 @@ public class ChannelTest extends ContainerAbstractTestCase {
*/
protected void tearDown() throws Exception {
// This is a possible workaround for what appears to be Smack bug: https://bugs.eclipse.org/bugs/show_bug.cgi?id=321032
- Thread.sleep(2000);
+ Thread.sleep(SLEEPTIME);
cleanUpClients();
super.tearDown();
}
@@ -74,7 +76,7 @@ public class ChannelTest extends ContainerAbstractTestCase {
final IChannel ch0 = getChannelContainer(0).getChannel(channelID);
ID target1 = getClient(1).getConnectedID();
ch0.sendMessage(target1, new String("hello").getBytes());
- sleep(3000);
+ sleep(SLEEPTIME);
}
public void testBiSendMessage() throws Exception {
@@ -86,7 +88,7 @@ public class ChannelTest extends ContainerAbstractTestCase {
ch0.sendMessage(target1, new String("hello").getBytes());
ch1.sendMessage(target0, new String("hello").getBytes());
- sleep(3000);
+ sleep(SLEEPTIME);
}
@@ -95,9 +97,8 @@ public class ChannelTest extends ContainerAbstractTestCase {
ID target1 = getClient(1).getConnectedID();
for(int i=0; i < SEND_MESSAGE_COUNT; i++) {
ch0.sendMessage(target1, new String("hello. msg#="+i).getBytes());
- sleep(500);
}
- sleep(3000);
+ sleep(SLEEPTIME);
}
public void testBiSendMessages() throws Exception {
@@ -109,10 +110,9 @@ public class ChannelTest extends ContainerAbstractTestCase {
for(int i=0; i < SEND_MESSAGE_COUNT; i++) {
ch0.sendMessage(target1, new String("hello. msg#="+i).getBytes());
- sleep(500);
ch1.sendMessage(target0, new String("hello. msg#="+i).getBytes());
}
- sleep(3000);
+ sleep(SLEEPTIME);
}
protected IChannelListener getIChannelListener(final ID containerid) throws Exception {
diff --git a/tests/bundles/org.eclipse.ecf.tests.provider.xmpp/src/org/eclipse/ecf/tests/provider/xmpp/remoteservice/RemoteServiceRetrieval.java b/tests/bundles/org.eclipse.ecf.tests.provider.xmpp/src/org/eclipse/ecf/tests/provider/xmpp/remoteservice/RemoteServiceRetrieval.java
index dca613ac1..e97bdc353 100644
--- a/tests/bundles/org.eclipse.ecf.tests.provider.xmpp/src/org/eclipse/ecf/tests/provider/xmpp/remoteservice/RemoteServiceRetrieval.java
+++ b/tests/bundles/org.eclipse.ecf.tests.provider.xmpp/src/org/eclipse/ecf/tests/provider/xmpp/remoteservice/RemoteServiceRetrieval.java
@@ -18,6 +18,7 @@ import org.eclipse.ecf.core.ContainerConnectException;
import org.eclipse.ecf.core.ContainerCreateException;
import org.eclipse.ecf.core.ContainerFactory;
import org.eclipse.ecf.core.IContainer;
+import org.eclipse.ecf.core.identity.ID;
import org.eclipse.ecf.core.security.ConnectContextFactory;
import org.eclipse.ecf.core.security.IConnectContext;
import org.eclipse.ecf.core.util.ECFException;
@@ -25,6 +26,7 @@ import org.eclipse.ecf.provider.xmpp.identity.XMPPID;
import org.eclipse.ecf.remoteservice.IRemoteService;
import org.eclipse.ecf.remoteservice.IRemoteServiceContainerAdapter;
import org.eclipse.ecf.remoteservice.IRemoteServiceReference;
+import org.eclipse.ecf.remoteservice.IRemoteServiceRegistration;
import org.eclipse.ecf.tests.provider.xmpp.XMPPS;
import org.osgi.framework.InvalidSyntaxException;
@@ -32,6 +34,11 @@ public class RemoteServiceRetrieval extends TestCase {
private XMPPClient[] xmppClients;
+ private static final int SLEEPTIME = new Integer(
+ System.getProperty(
+ "org.eclipse.ecf.tests.provider.xmpp.remoteservice.RemoteServiceRetrieval.SLEEPTIME",
+ "6000")).intValue();
+
public void setUp() {
try {
createXMPPClients();
@@ -57,8 +64,7 @@ public class RemoteServiceRetrieval extends TestCase {
/*
* Make sure that the right service is returned for the right client.
*/
- public void testRightServiceForClients() throws InvalidSyntaxException,
- ECFException {
+ public void testRightServiceForClients() throws Exception {
// Client 1 tries to retrieve services registered by client 2 & 3
IExampleService remoteService1 = getClient(0).getRemoteService(
@@ -94,21 +100,26 @@ public class RemoteServiceRetrieval extends TestCase {
assertEquals(getClient(1).getClientID(), remoteService6.getClientID());
}
- public void testConnectAndDisconnectClients() throws ECFException,
- InvalidSyntaxException {
+ public void testRegisterAndUnregisterRemoteServices() throws Exception {
// Client 0 tries to get service from client 1
IExampleService remoteService1 = getClient(0).getRemoteService(
getClient(1));
assertNotNull(remoteService1);
-
- // disconnect client 1, no services available for client 1
- getClient(1).disconnect();
+ // unregister remote service on client 1, no services available for
+ // client 1
+ getClient(1).unregisterRemoteService();
+ // wait for unregistration to propogate
+ Thread.sleep(SLEEPTIME);
+ // Now lookup and make sure the reference is now null
IExampleService remoteService2 = getClient(0).getRemoteService(
getClient(1));
assertNull(remoteService2);
- // connect client 1 again, services are available again
- getClient(1).connect();
+ // register remote service on client 1
+ registerRemoteServiceOnClient(getClient(1));
+ // wait for registration to propogate
+ Thread.sleep(SLEEPTIME);
+
IExampleService remoteService3 = getClient(0).getRemoteService(
getClient(1));
assertNotNull(remoteService3);
@@ -118,27 +129,18 @@ public class RemoteServiceRetrieval extends TestCase {
* Remote service registration without filterIDs.
*/
private void registerRemoteServicesNoFilterIDs() {
- IExampleService clientService1 = new ExampleService(getClient(0)
- .getClientID());
- IExampleService clientService2 = new ExampleService(getClient(1)
- .getClientID());
- IExampleService clientService3 = new ExampleService(getClient(2)
- .getClientID());
-
- getClient(0).getRemoteServiceAdapter().registerRemoteService(
- new String[] { IExampleService.class.getName() },
- clientService1, null);
- getClient(1).getRemoteServiceAdapter().registerRemoteService(
- new String[] { IExampleService.class.getName() },
- clientService2, null);
- getClient(2).getRemoteServiceAdapter().registerRemoteService(
- new String[] { IExampleService.class.getName() },
- clientService3, null);
+ registerRemoteServiceOnClient(getClient(0));
+ registerRemoteServiceOnClient(getClient(1));
+ registerRemoteServiceOnClient(getClient(2));
+ }
+
+ private void registerRemoteServiceOnClient(XMPPClient client) {
+ client.registerRemoteService(IExampleService.class.getName(), new ExampleService(client.getClientID()));
}
public void tearDown() {
for (int clientNumber = 0; clientNumber <= 2; clientNumber++) {
- getClient(clientNumber).disconnect();
+ getClient(clientNumber).tearDown();
}
}
@@ -169,6 +171,7 @@ public class RemoteServiceRetrieval extends TestCase {
private XMPPID clientID;
private IConnectContext connectContext;
private IRemoteServiceContainerAdapter adapter;
+ private IRemoteServiceRegistration registration;
public XMPPClient(String username, String password)
throws ContainerCreateException, URISyntaxException {
@@ -188,8 +191,15 @@ public class RemoteServiceRetrieval extends TestCase {
assertNotNull(connectContext);
}
- IRemoteServiceContainerAdapter getRemoteServiceAdapter() {
- return adapter;
+ void tearDown() {
+ unregisterRemoteService();
+ try {
+ Thread.sleep(SLEEPTIME);
+ } catch (InterruptedException e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ }
+ container.disconnect();
}
XMPPID getClientID() {
@@ -200,15 +210,27 @@ public class RemoteServiceRetrieval extends TestCase {
container.connect(clientID, connectContext);
}
- void disconnect() {
- container.disconnect();
+ public void registerRemoteService(String svcInterface, Object svc) {
+ this.registration = adapter.registerRemoteService(
+ new String[] { svcInterface }, svc, null);
+ }
+
+ void unregisterRemoteService() {
+ if (registration != null) {
+ // unregister the remote service registration
+ registration.unregister();
+ }
}
private IExampleService getRemoteService(XMPPClient toClient)
throws InvalidSyntaxException, ECFException {
IRemoteServiceReference[] remoteServiceReferences = adapter
- .getRemoteServiceReferences(toClient.getClientID(),
+ .getRemoteServiceReferences(
+ new ID[] { toClient.getClientID() },
IExampleService.class.getName(), null);
+ if (remoteServiceReferences == null
+ || remoteServiceReferences.length == 0)
+ return null;
assertEquals(1, remoteServiceReferences.length);
IRemoteService remoteService = adapter
diff --git a/tests/bundles/org.eclipse.ecf.tests.remoteservice.generic/src/org/eclipse/ecf/tests/remoteservice/generic/RemoteServiceProxyTest.java b/tests/bundles/org.eclipse.ecf.tests.remoteservice.generic/src/org/eclipse/ecf/tests/remoteservice/generic/RemoteServiceProxyTest.java
index f0d4a969e..d7635298c 100644
--- a/tests/bundles/org.eclipse.ecf.tests.remoteservice.generic/src/org/eclipse/ecf/tests/remoteservice/generic/RemoteServiceProxyTest.java
+++ b/tests/bundles/org.eclipse.ecf.tests.remoteservice.generic/src/org/eclipse/ecf/tests/remoteservice/generic/RemoteServiceProxyTest.java
@@ -161,7 +161,7 @@ public class RemoteServiceProxyTest extends AbstractRemoteServiceTest {
.callAsync(createRemoteConcat("ECF AsynchResults ", "are cool"));
traceCallEnd("callAsynch");
assertNotNull(result);
- Thread.sleep(ASYNC_WAITTIME);
+ Thread.sleep(SLEEPTIME);
}
}
diff --git a/tests/bundles/org.eclipse.ecf.tests.remoteservice.generic/src/org/eclipse/ecf/tests/remoteservice/generic/RemoteServiceTest.java b/tests/bundles/org.eclipse.ecf.tests.remoteservice.generic/src/org/eclipse/ecf/tests/remoteservice/generic/RemoteServiceTest.java
index def61ac4a..276bb87ff 100644
--- a/tests/bundles/org.eclipse.ecf.tests.remoteservice.generic/src/org/eclipse/ecf/tests/remoteservice/generic/RemoteServiceTest.java
+++ b/tests/bundles/org.eclipse.ecf.tests.remoteservice.generic/src/org/eclipse/ecf/tests/remoteservice/generic/RemoteServiceTest.java
@@ -103,7 +103,7 @@ public class RemoteServiceTest extends AbstractRemoteServiceTest {
.callAsync(createRemoteConcat("ECF AsynchResults ", "are cool"));
traceCallEnd("callAsynch");
assertNotNull(result);
- Thread.sleep(ASYNC_WAITTIME);
+ Thread.sleep(SLEEPTIME);
}
diff --git a/tests/bundles/org.eclipse.ecf.tests.remoteservice.generic/src/org/eclipse/ecf/tests/remoteservice/generic/RemoteServiceTrackerTest.java b/tests/bundles/org.eclipse.ecf.tests.remoteservice.generic/src/org/eclipse/ecf/tests/remoteservice/generic/RemoteServiceTrackerTest.java
index 28a873124..306bcec07 100644
--- a/tests/bundles/org.eclipse.ecf.tests.remoteservice.generic/src/org/eclipse/ecf/tests/remoteservice/generic/RemoteServiceTrackerTest.java
+++ b/tests/bundles/org.eclipse.ecf.tests.remoteservice.generic/src/org/eclipse/ecf/tests/remoteservice/generic/RemoteServiceTrackerTest.java
@@ -147,7 +147,7 @@ public class RemoteServiceTrackerTest extends AbstractRemoteServiceTest {
.callAsync(createRemoteConcat("ECF AsynchResults ", "are cool"));
traceCallEnd("callAsynch");
assertNotNull(result);
- Thread.sleep(ASYNC_WAITTIME);
+ Thread.sleep(SLEEPTIME);
}
}
diff --git a/tests/bundles/org.eclipse.ecf.tests.remoteservice/src/org/eclipse/ecf/tests/remoteservice/AbstractRemoteServiceTest.java b/tests/bundles/org.eclipse.ecf.tests.remoteservice/src/org/eclipse/ecf/tests/remoteservice/AbstractRemoteServiceTest.java
index ce593a0fc..8e309f626 100644
--- a/tests/bundles/org.eclipse.ecf.tests.remoteservice/src/org/eclipse/ecf/tests/remoteservice/AbstractRemoteServiceTest.java
+++ b/tests/bundles/org.eclipse.ecf.tests.remoteservice/src/org/eclipse/ecf/tests/remoteservice/AbstractRemoteServiceTest.java
@@ -40,7 +40,9 @@ import org.osgi.framework.InvalidSyntaxException;
public abstract class AbstractRemoteServiceTest extends
ContainerAbstractTestCase {
- protected static final long ASYNC_WAITTIME = new Long(System.getProperty("org.eclipse.ecf.tests.remoteservice.asyncWaittime","3000")).longValue();
+ protected static final int SLEEPTIME = new Integer(System.getProperty(
+ "org.eclipse.ecf.tests.remoteservice.AbstractRemoteServiceTest.SLEEPTIME", "5000"))
+ .intValue();
protected IRemoteServiceContainerAdapter[] adapters = null;
@@ -48,7 +50,7 @@ public abstract class AbstractRemoteServiceTest extends
/*
* (non-Javadoc)
- *
+ *
* @see
* org.eclipse.ecf.tests.ContainerAbstractTestCase#getClientContainerName()
*/
@@ -61,7 +63,8 @@ public abstract class AbstractRemoteServiceTest extends
}
protected void setupRemoteServiceAdapters() throws Exception {
- if (server != null) server.getAdapter(IRemoteServiceContainerAdapter.class);
+ if (server != null)
+ server.getAdapter(IRemoteServiceContainerAdapter.class);
final int clientCount = getClientCount();
for (int i = 0; i < clientCount; i++) {
adapters[i] = (IRemoteServiceContainerAdapter) getClients()[i]
@@ -73,10 +76,12 @@ public abstract class AbstractRemoteServiceTest extends
return adapters;
}
- protected IRemoteServiceListener createRemoteServiceListener(final boolean server) {
+ protected IRemoteServiceListener createRemoteServiceListener(
+ final boolean server) {
return new IRemoteServiceListener() {
public void handleServiceEvent(IRemoteServiceEvent event) {
- System.out.println((server?"server":"client")+"handleServiceEvent(" + event + ")");
+ System.out.println((server ? "server" : "client")
+ + "handleServiceEvent(" + event + ")");
if (event instanceof IRemoteServiceRegisteredEvent) {
if (server) {
ids[0] = event.getReference().getID();
@@ -90,7 +95,8 @@ public abstract class AbstractRemoteServiceTest extends
protected void addRemoteServiceListeners() {
for (int i = 0; i < adapters.length; i++) {
- adapters[i].addRemoteServiceListener(createRemoteServiceListener(i==0));
+ adapters[i]
+ .addRemoteServiceListener(createRemoteServiceListener(i == 0));
}
}
@@ -105,9 +111,11 @@ public abstract class AbstractRemoteServiceTest extends
}
protected IRemoteServiceReference[] getRemoteServiceReferences(
- IRemoteServiceContainerAdapter adapter, ID target, ID[] idFilter, String clazz, String filter) throws ContainerConnectException {
+ IRemoteServiceContainerAdapter adapter, ID target, ID[] idFilter,
+ String clazz, String filter) throws ContainerConnectException {
try {
- return adapter.getRemoteServiceReferences(target, idFilter, clazz, filter);
+ return adapter.getRemoteServiceReferences(target, idFilter, clazz,
+ filter);
} catch (final InvalidSyntaxException e) {
fail("should not happen");
}
@@ -115,7 +123,9 @@ public abstract class AbstractRemoteServiceTest extends
}
protected IRemoteService getRemoteService(
- IRemoteServiceContainerAdapter adapter, ID target, ID[] idFilter, String clazz, String filter, int sleepTime) throws ContainerConnectException {
+ IRemoteServiceContainerAdapter adapter, ID target, ID[] idFilter,
+ String clazz, String filter, int sleepTime)
+ throws ContainerConnectException {
final IRemoteServiceReference[] refs = getRemoteServiceReferences(
adapter, target, idFilter, clazz, filter);
if (refs == null || refs.length == 0)
@@ -143,8 +153,9 @@ public abstract class AbstractRemoteServiceTest extends
protected IRemoteService registerAndGetRemoteService(
IRemoteServiceContainerAdapter server,
- IRemoteServiceContainerAdapter client, ID target, ID[] idFilter, String serviceName,
- Dictionary serviceProperties, int sleepTime) throws ContainerConnectException {
+ IRemoteServiceContainerAdapter client, ID target, ID[] idFilter,
+ String serviceName, Dictionary serviceProperties, int sleepTime)
+ throws ContainerConnectException {
registerService(server, serviceName, createService(),
serviceProperties, sleepTime);
return getRemoteService(client, target, idFilter, serviceName,
@@ -184,63 +195,66 @@ public abstract class AbstractRemoteServiceTest extends
assertNotNull(adapters);
for (int i = 0; i < adapters.length; i++)
assertNotNull(adapters[i]);
- Thread.sleep(ASYNC_WAITTIME);
+ Thread.sleep(SLEEPTIME);
}
public void testRemoteServiceNamespace() throws Exception {
final IRemoteServiceContainerAdapter[] adapters = getRemoteServiceAdapters();
assertNotNull(adapters);
- for(int i=0; i < adapters.length; i++) {
+ for (int i = 0; i < adapters.length; i++) {
Namespace namespace = adapters[i].getRemoteServiceNamespace();
assertNotNull(namespace);
}
- Thread.sleep(ASYNC_WAITTIME);
+ Thread.sleep(SLEEPTIME);
}
public void testRegisterService() throws Exception {
final IRemoteServiceContainerAdapter[] adapters = getRemoteServiceAdapters();
// adapter [0] is the service 'server'
final IRemoteServiceRegistration reg = registerService(adapters[0],
- IConcatService.class.getName(), createService(), customizeProperties(null), 0);
+ IConcatService.class.getName(), createService(),
+ customizeProperties(null), 0);
assertNotNull(reg);
IRemoteServiceID remoteServiceID = reg.getID();
assertNotNull(remoteServiceID);
assertNotNull(remoteServiceID.getContainerID());
- Thread.sleep(ASYNC_WAITTIME);
+ Thread.sleep(SLEEPTIME);
}
public void testUnregisterService() throws Exception {
final IRemoteServiceContainerAdapter[] adapters = getRemoteServiceAdapters();
// adapter [0] is the service 'server'
final IRemoteServiceRegistration reg = registerService(adapters[0],
- IConcatService.class.getName(), createService(), customizeProperties(null), 0);
+ IConcatService.class.getName(), createService(),
+ customizeProperties(null), SLEEPTIME);
assertNotNull(reg);
assertNotNull(reg.getContainerID());
reg.unregister();
- Thread.sleep(ASYNC_WAITTIME);
+ Thread.sleep(SLEEPTIME);
}
protected ID getConnectTargetID() {
return null;
}
-
+
protected ID[] getIDFilter() {
return null;
}
-
+
public void testGetServiceReferences() throws Exception {
final IRemoteServiceContainerAdapter[] adapters = getRemoteServiceAdapters();
// Register service on client[0]
registerService(adapters[0], IConcatService.class.getName(),
- createService(), customizeProperties(null), 3000);
+ createService(), customizeProperties(null), SLEEPTIME);
final IRemoteServiceReference[] refs = getRemoteServiceReferences(
- adapters[1], getConnectTargetID(), getIDFilter(), IConcatService.class.getName(), null);
+ adapters[1], getConnectTargetID(), getIDFilter(),
+ IConcatService.class.getName(), null);
assertTrue(refs != null);
assertTrue(refs.length > 0);
- Thread.sleep(ASYNC_WAITTIME);
+ Thread.sleep(SLEEPTIME);
}
public void testGetServiceReferencesWithFilter() throws Exception {
@@ -249,15 +263,16 @@ public abstract class AbstractRemoteServiceTest extends
props.put("foo", "bar");
props.put("foo1", "bar");
registerService(adapters[0], IConcatService.class.getName(),
- createService(), customizeProperties(props), 3000);
+ createService(), customizeProperties(props), SLEEPTIME);
final IRemoteServiceReference[] refs = getRemoteServiceReferences(
- adapters[1], getConnectTargetID(), getIDFilter(), IConcatService.class.getName(),
+ adapters[1], getConnectTargetID(), getIDFilter(),
+ IConcatService.class.getName(),
getFilterFromServiceProperties(props));
assertTrue(refs != null);
assertTrue(refs.length > 0);
- Thread.sleep(ASYNC_WAITTIME);
+ Thread.sleep(SLEEPTIME);
}
public void testGetServiceReferencesWithFilterFail() throws Exception {
@@ -266,7 +281,7 @@ public abstract class AbstractRemoteServiceTest extends
props.put("foo", "bar");
props.put("foo1", "bar");
registerService(adapters[0], IConcatService.class.getName(),
- createService(), customizeProperties(props), 0);
+ createService(), customizeProperties(props), SLEEPTIME);
// Create dictionary that is *not* the same as props, so the filter
// should miss
@@ -275,10 +290,11 @@ public abstract class AbstractRemoteServiceTest extends
final String missFilter = getFilterFromServiceProperties(missProps);
final IRemoteServiceReference[] refs = getRemoteServiceReferences(
- adapters[1], getConnectTargetID(), getIDFilter(), IConcatService.class.getName(), missFilter);
+ adapters[1], getConnectTargetID(), getIDFilter(),
+ IConcatService.class.getName(), missFilter);
assertTrue(refs == null);
- Thread.sleep(ASYNC_WAITTIME);
+ Thread.sleep(SLEEPTIME);
}
public void testGetService() throws Exception {
@@ -287,17 +303,19 @@ public abstract class AbstractRemoteServiceTest extends
if (service == null)
return;
assertNotNull(service);
- Thread.sleep(ASYNC_WAITTIME);
+ Thread.sleep(SLEEPTIME);
}
protected IRemoteCall createRemoteConcat(String first, String second) {
return createRemoteCall("concat", new Object[] { first, second });
}
- protected IRemoteService registerAndGetRemoteService() throws ContainerConnectException {
+ protected IRemoteService registerAndGetRemoteService()
+ throws ContainerConnectException {
final IRemoteServiceContainerAdapter[] adapters = getRemoteServiceAdapters();
return registerAndGetRemoteService(adapters[0], adapters[1],
- getClient(0).getConnectedID(), getIDFilter(), IConcatService.class.getName(), customizeProperties(null), 5000);
+ getClient(0).getConnectedID(), getIDFilter(),
+ IConcatService.class.getName(), customizeProperties(null), SLEEPTIME);
}
protected IRemoteCallListener createRemoteCallListener() {
@@ -321,7 +339,7 @@ public abstract class AbstractRemoteServiceTest extends
assertNotNull(result);
assertTrue(result.equals("Eclipse ".concat("is cool")));
- Thread.sleep(ASYNC_WAITTIME);
+ Thread.sleep(SLEEPTIME);
}
protected void traceCallStart(String callType) {
@@ -361,7 +379,7 @@ public abstract class AbstractRemoteServiceTest extends
} catch (final ECFException e) {
// Exception should occur
}
- Thread.sleep(ASYNC_WAITTIME);
+ Thread.sleep(SLEEPTIME);
}
public void testCallAsynch() throws Exception {
@@ -372,7 +390,7 @@ public abstract class AbstractRemoteServiceTest extends
service.callAsync(createRemoteConcat("ECF ", "is cool"),
createRemoteCallListener());
traceCallEnd("callAsynch");
- Thread.sleep(ASYNC_WAITTIME);
+ Thread.sleep(SLEEPTIME);
}
public void testFireAsynch() throws Exception {
@@ -382,7 +400,7 @@ public abstract class AbstractRemoteServiceTest extends
traceCallStart("fireAsynch");
service.fireAsync(createRemoteConcat("Eclipse ", "sucks"));
traceCallEnd("fireAsynch");
- Thread.sleep(ASYNC_WAITTIME);
+ Thread.sleep(SLEEPTIME);
}
public void testProxy() throws Exception {
@@ -394,7 +412,7 @@ public abstract class AbstractRemoteServiceTest extends
traceCallStart("getProxy");
final String result = proxy.concat("ECF ", "sucks");
traceCallEnd("getProxy", result);
- Thread.sleep(ASYNC_WAITTIME);
+ Thread.sleep(SLEEPTIME);
}
public void testAsyncResult() throws Exception {
@@ -406,7 +424,7 @@ public abstract class AbstractRemoteServiceTest extends
"ECF AsynchResults ", "are cool"));
traceCallEnd("callAsynchResult", result);
assertNotNull(result);
- Thread.sleep(ASYNC_WAITTIME);
+ Thread.sleep(SLEEPTIME);
}
protected Dictionary customizeProperties(Dictionary props) {

Back to the top