RESOLVED - bug 319126: [RemoteSvcs] Wildcard causes IRemoteServiceContainerAdapter.registerRemoteService(String[], Object, Dictionary) to fail
https://bugs.eclipse.org/bugs/show_bug.cgi?id=319126
diff --git a/tests/bundles/org.eclipse.ecf.tests.osgi.services.distribution/src/org/eclipse/ecf/tests/osgi/services/distribution/AbstractRemoteServiceAccessTest.java b/tests/bundles/org.eclipse.ecf.tests.osgi.services.distribution/src/org/eclipse/ecf/tests/osgi/services/distribution/AbstractRemoteServiceAccessTest.java
index db3037b..a307a8b 100644
--- a/tests/bundles/org.eclipse.ecf.tests.osgi.services.distribution/src/org/eclipse/ecf/tests/osgi/services/distribution/AbstractRemoteServiceAccessTest.java
+++ b/tests/bundles/org.eclipse.ecf.tests.osgi.services.distribution/src/org/eclipse/ecf/tests/osgi/services/distribution/AbstractRemoteServiceAccessTest.java
@@ -26,17 +26,50 @@
public abstract class AbstractRemoteServiceAccessTest extends
AbstractDistributionTest {
- private static final String TESTPROP1_VALUE = "baz";
- private static final String TESTPROP_VALUE = "foobar";
- private static final String TESTPROP1_NAME = "org.eclipse.ecf.testprop1";
- private static final String TESTPROP_NAME = "org.eclipse.ecf.testprop";
protected static final int REGISTER_WAIT = Integer.parseInt(System.getProperty("waittime","15000"));
+ private final String classname = TestServiceInterface1.class.getName();
+ private ServiceTracker st;
+ private ServiceRegistration registration;
+
+ /* (non-Javadoc)
+ * @see org.eclipse.ecf.tests.osgi.services.distribution.AbstractDistributionTest#tearDown()
+ */
+ protected void tearDown() throws Exception {
+ // Unregister on server
+ if (registration != null) {
+ registration.unregister();
+ registration = null;
+ }
+ if (st != null) {
+ st.close();
+ st = null;
+ }
+ Thread.sleep(REGISTER_WAIT);
+
+ super.tearDown();
+ }
+
+ protected void createServiceTrackerAndRegister(final Properties props) throws Exception {
+ // Setup service tracker for client
+ st = createProxyServiceTracker(classname);
+
+ // Actually register
+ registration = registerService(classname,
+ new TestService1(), props);
+
+ // Wait
+ Thread.sleep(REGISTER_WAIT);
+ }
+
+ protected void createServiceTrackerAndRegister() throws Exception {
+ createServiceTrackerAndRegister(getServiceProperties());
+ }
+
protected Properties getServiceProperties() {
- Properties props = new Properties();
+ final Properties props = new Properties();
props.put(SERVICE_EXPORTED_CONFIGS, getServerContainerName());
- props.put(SERVICE_EXPORTED_INTERFACES,
- new String[] { SERVICE_EXPORTED_INTERFACES_WILDCARD });
+ props.put(SERVICE_EXPORTED_INTERFACES, SERVICE_EXPORTED_INTERFACES_WILDCARD);
return props;
}
@@ -60,177 +93,113 @@
public void testGetRemoteServiceReference() throws Exception {
- String classname = TestServiceInterface1.class.getName();
- // Setup service tracker for client container
- ServiceTracker st = createProxyServiceTracker(classname);
- // Get service properties...and allow subclasses to override to add
- // other service properties
- Properties props = getServiceProperties();
- // Service Host: register service
- ServiceRegistration registration = registerService(classname,
- new TestService1(), props);
- // Wait
- Thread.sleep(REGISTER_WAIT);
-
+ createServiceTrackerAndRegister();
+
// Service Consumer - Get (remote) ervice references
- ServiceReference[] remoteReferences = st.getServiceReferences();
+ final ServiceReference[] remoteReferences = st.getServiceReferences();
assertReferencesValidAndFirstHasCorrectType(remoteReferences, classname);
// Spec requires that the 'service.imported' property be set
assertTrue(remoteReferences[0].getProperty(SERVICE_IMPORTED) != null);
-
- if (registration != null) registration.unregister();
- st.close();
- Thread.sleep(REGISTER_WAIT);
}
public void testGetRemoteServiceReferenceWithExtraProperties() throws Exception {
- String classname = TestServiceInterface1.class.getName();
- // Setup service tracker for client container
- ServiceTracker st = createProxyServiceTracker(classname);
- // Get service properties...and allow subclasses to override to add
- // other service properties
- Properties props = getServiceProperties();
+ final String TESTPROP1_VALUE = "baz";
+ final String TESTPROP_VALUE = "foobar";
+ final String TESTPROP1_NAME = "org.eclipse.ecf.testprop1";
+ final String TESTPROP_NAME = "org.eclipse.ecf.testprop";
+
+ final Properties props = getServiceProperties();
// Add other properties
props.put(TESTPROP_NAME, TESTPROP_VALUE);
props.put(TESTPROP1_NAME,TESTPROP1_VALUE);
- // Service Host: register service
- ServiceRegistration registration = registerService(classname,
- new TestService1(), props);
- // Wait
- Thread.sleep(REGISTER_WAIT);
+ createServiceTrackerAndRegister(props);
// Service Consumer - Get (remote) ervice references
- ServiceReference[] remoteReferences = st.getServiceReferences();
+ final ServiceReference[] remoteReferences = st.getServiceReferences();
assertReferencesValidAndFirstHasCorrectType(remoteReferences, classname);
// Spec requires that the 'service.imported' property be set
assertTrue(remoteReferences[0].getProperty(SERVICE_IMPORTED) != null);
- String testProp = (String) remoteReferences[0].getProperty(TESTPROP_NAME);
- String testProp1 = (String) remoteReferences[0].getProperty(TESTPROP1_NAME);
+ final String testProp = (String) remoteReferences[0].getProperty(TESTPROP_NAME);
+ final String testProp1 = (String) remoteReferences[0].getProperty(TESTPROP1_NAME);
assertTrue(TESTPROP_VALUE.equals(testProp));
assertTrue(TESTPROP1_VALUE.equals(testProp1));
- if (registration != null) registration.unregister();
- st.close();
- Thread.sleep(REGISTER_WAIT);
}
public void testProxy() throws Exception {
- String classname = TestServiceInterface1.class.getName();
- // Setup service tracker for client
- ServiceTracker st = createProxyServiceTracker(classname);
-
- // Actually register and wait a while
- ServiceRegistration registration = registerService(classname,
- new TestService1(), getServiceProperties());
- Thread.sleep(REGISTER_WAIT);
-
+ createServiceTrackerAndRegister();
+
// Client - Get service references from service tracker
- ServiceReference[] remoteReferences = st.getServiceReferences();
+ final ServiceReference[] remoteReferences = st.getServiceReferences();
assertReferencesValidAndFirstHasCorrectType(remoteReferences, classname);
// Get proxy/service
- TestServiceInterface1 proxy = (TestServiceInterface1) getContext()
+ final TestServiceInterface1 proxy = (TestServiceInterface1) getContext()
.getService(remoteReferences[0]);
assertNotNull(proxy);
// Now use proxy
- String result = proxy.doStuff1();
+ final String result = proxy.doStuff1();
Trace.trace(Activator.PLUGIN_ID, "proxy.doStuff1 result=" + result);
assertTrue(TestServiceInterface1.TEST_SERVICE_STRING1.equals(result));
-
- // Unregister on server and wait
- if (registration != null) registration.unregister();
- st.close();
- Thread.sleep(REGISTER_WAIT);
}
public void testCallSyncFromProxy() throws Exception {
- String classname = TestServiceInterface1.class.getName();
- // Setup service tracker for client
- ServiceTracker st = createProxyServiceTracker(classname);
-
- // Actually register and wait a while
- ServiceRegistration registration = registerService(classname,
- new TestService1(), getServiceProperties());
- Thread.sleep(REGISTER_WAIT);
-
+ createServiceTrackerAndRegister();
+
// Client - Get service references from service tracker
- ServiceReference[] remoteReferences = st.getServiceReferences();
+ final ServiceReference[] remoteReferences = st.getServiceReferences();
assertReferencesValidAndFirstHasCorrectType(remoteReferences, classname);
// Get proxy
- TestServiceInterface1 proxy = (TestServiceInterface1) getContext()
+ final TestServiceInterface1 proxy = (TestServiceInterface1) getContext()
.getService(remoteReferences[0]);
assertProxyValid(proxy);
// Get IRemoteService from proxy
- IRemoteService remoteService = getRemoteServiceFromProxy(proxy);
+ final IRemoteService remoteService = getRemoteServiceFromProxy(proxy);
// Call remote service synchronously
- Object result = remoteService.callSync(createRemoteCall());
+ final Object result = remoteService.callSync(createRemoteCall());
Trace.trace(Activator.PLUGIN_ID, "proxy.doStuff1 result=" + result);
assertStringResultValid(result, TestServiceInterface1.TEST_SERVICE_STRING1);
-
- // Unregister on server and wait
- if (registration != null) registration.unregister();
- st.close();
- Thread.sleep(REGISTER_WAIT);
}
public void testCallSync() throws Exception {
- String classname = TestServiceInterface1.class.getName();
- // Setup service tracker for client
- ServiceTracker st = createProxyServiceTracker(classname);
-
- // Actually register and wait a while
- ServiceRegistration registration = registerService(classname,
- new TestService1(), getServiceProperties());
- Thread.sleep(REGISTER_WAIT);
-
+ createServiceTrackerAndRegister();
+
// Client - Get service references from service tracker
- ServiceReference[] remoteReferences = st.getServiceReferences();
+ final ServiceReference[] remoteReferences = st.getServiceReferences();
assertReferencesValidAndFirstHasCorrectType(remoteReferences, classname);
- Object o = remoteReferences[0].getProperty(SERVICE_IMPORTED);
+ final Object o = remoteReferences[0].getProperty(SERVICE_IMPORTED);
assertNotNull(o);
assertTrue(o instanceof IRemoteService);
- IRemoteService rs = (IRemoteService) o;
+ final IRemoteService rs = (IRemoteService) o;
// Call synchronously
- Object result = rs.callSync(createRemoteCall());
+ final Object result = rs.callSync(createRemoteCall());
Trace.trace(Activator.PLUGIN_ID, "callSync.doStuff1 result=" + result);
assertStringResultValid(result, TestServiceInterface1.TEST_SERVICE_STRING1);
-
- // Unregister on server
- if (registration != null) registration.unregister();
- st.close();
- Thread.sleep(REGISTER_WAIT);
}
public void testCallAsync() throws Exception {
- String classname = TestServiceInterface1.class.getName();
- // Setup service tracker for client
- ServiceTracker st = createProxyServiceTracker(classname);
-
- // Actually register and wait a while
- ServiceRegistration registration = registerService(classname,
- new TestService1(), getServiceProperties());
- Thread.sleep(REGISTER_WAIT);
-
+ createServiceTrackerAndRegister();
+
// Client - Get service references from service tracker
- ServiceReference[] remoteReferences = st.getServiceReferences();
+ final ServiceReference[] remoteReferences = st.getServiceReferences();
assertReferencesValid(remoteReferences);
- Object o = remoteReferences[0].getProperty(SERVICE_IMPORTED);
+ final Object o = remoteReferences[0].getProperty(SERVICE_IMPORTED);
assertNotNull(o);
assertTrue(o instanceof IRemoteService);
- IRemoteService rs = (IRemoteService) o;
+ final IRemoteService rs = (IRemoteService) o;
// Call asynchronously
rs.callAsync(createRemoteCall(), new IRemoteCallListener() {
- public void handleEvent(IRemoteCallEvent event) {
+ public void handleEvent(final IRemoteCallEvent event) {
if (event instanceof IRemoteCallCompleteEvent) {
- Object result = ((IRemoteCallCompleteEvent) event)
+ final Object result = ((IRemoteCallCompleteEvent) event)
.getResponse();
Trace.trace(Activator.PLUGIN_ID,
"callSync.doStuff1 result=" + result);
@@ -241,69 +210,41 @@
});
syncWaitForNotify(REGISTER_WAIT);
- // Unregister on server
- registration.unregister();
- st.close();
- Thread.sleep(REGISTER_WAIT);
}
public void testCallFuture() throws Exception {
- String classname = TestServiceInterface1.class.getName();
- // Setup service tracker for client
- ServiceTracker st = createProxyServiceTracker(classname);
-
- // Actually register and wait a while
- ServiceRegistration registration = registerService(classname,
- new TestService1(), getServiceProperties());
- Thread.sleep(REGISTER_WAIT);
-
+ createServiceTrackerAndRegister();
+
// Client - Get service references from service tracker
- ServiceReference[] remoteReferences = st.getServiceReferences();
+ final ServiceReference[] remoteReferences = st.getServiceReferences();
assertReferencesValid(remoteReferences);
- Object o = remoteReferences[0].getProperty(SERVICE_IMPORTED);
+ final Object o = remoteReferences[0].getProperty(SERVICE_IMPORTED);
assertNotNull(o);
assertTrue(o instanceof IRemoteService);
- IRemoteService rs = (IRemoteService) o;
+ final IRemoteService rs = (IRemoteService) o;
// Call asynchronously
- IFuture futureResult = rs.callAsync(createRemoteCall());
+ final IFuture futureResult = rs.callAsync(createRemoteCall());
// now get result from futureResult
- Object result = futureResult.get();
+ final Object result = futureResult.get();
Trace.trace(Activator.PLUGIN_ID, "callSync.doStuff1 result=" + result);
assertStringResultValid(result, TestServiceInterface1.TEST_SERVICE_STRING1);
-
- // Unregister on server
- if (registration != null) registration.unregister();
- st.close();
- Thread.sleep(REGISTER_WAIT);
}
public void testFireAsync() throws Exception {
- String classname = TestServiceInterface1.class.getName();
- // Setup service tracker for client
- ServiceTracker st = createProxyServiceTracker(classname);
-
- // Actually register and wait a while
- ServiceRegistration registration = registerService(classname,
- new TestService1(), getServiceProperties());
- Thread.sleep(REGISTER_WAIT);
-
+ createServiceTrackerAndRegister();
+
// Client - Get service references from service tracker
- ServiceReference[] remoteReferences = st.getServiceReferences();
+ final ServiceReference[] remoteReferences = st.getServiceReferences();
assertReferencesValid(remoteReferences);
- Object o = remoteReferences[0].getProperty(SERVICE_IMPORTED);
+ final Object o = remoteReferences[0].getProperty(SERVICE_IMPORTED);
assertNotNull(o);
assertTrue(o instanceof IRemoteService);
- IRemoteService rs = (IRemoteService) o;
+ final IRemoteService rs = (IRemoteService) o;
// Call asynchronously
rs.fireAsync(createRemoteCall());
- Thread.sleep(5000);
- // Unregister on server
- if (registration != null) registration.unregister();
- st.close();
Thread.sleep(REGISTER_WAIT);
}
-
}
diff --git a/tests/bundles/org.eclipse.ecf.tests.osgi.services.distribution/src/org/eclipse/ecf/tests/osgi/services/distribution/AbstractRemoteServiceRegisterTest.java b/tests/bundles/org.eclipse.ecf.tests.osgi.services.distribution/src/org/eclipse/ecf/tests/osgi/services/distribution/AbstractRemoteServiceRegisterTest.java
index e353d65..fba70b7 100644
--- a/tests/bundles/org.eclipse.ecf.tests.osgi.services.distribution/src/org/eclipse/ecf/tests/osgi/services/distribution/AbstractRemoteServiceRegisterTest.java
+++ b/tests/bundles/org.eclipse.ecf.tests.osgi.services.distribution/src/org/eclipse/ecf/tests/osgi/services/distribution/AbstractRemoteServiceRegisterTest.java
@@ -24,11 +24,20 @@
AbstractDistributionTest {
protected static final int REGISTER_WAIT = 2000;
+ private ServiceRegistration registration;
protected abstract String getServerContainerTypeName();
protected void tearDown() throws Exception {
+ // Then unregister
+ if(registration != null) {
+ registration.unregister();
+ registration = null;
+ }
+ Thread.sleep(REGISTER_WAIT);
+
super.tearDown();
+
IContainer [] containers = getContainerManager().getAllContainers();
for(int i=0; i < containers.length; i++) {
containers[i].dispose();
@@ -39,14 +48,13 @@
protected void registerWaitAndUnregister(Properties props, boolean verifyRegistration) throws Exception {
// Actually register with default service (IConcatService)
- ServiceRegistration registration = registerDefaultService(props);
+ registration = registerDefaultService(props);
// Wait a while
Thread.sleep(REGISTER_WAIT);
// Verify
- if (verifyRegistration) verifyRemoteServiceRegisteredWithServer();
- // Then unregister
- registration.unregister();
- Thread.sleep(REGISTER_WAIT);
+ if (verifyRegistration) {
+ verifyRemoteServiceRegisteredWithServer();
+ }
}
private void verifyRemoteServiceRegisteredWithServer() throws Exception {
@@ -75,20 +83,23 @@
}
public void testRegisterOnCreatedServer() throws Exception {
- Properties props = new Properties();
- props.put(SERVICE_EXPORTED_CONFIGS, getServerContainerTypeName());
- props.put(SERVICE_EXPORTED_INTERFACES, new String[] {SERVICE_EXPORTED_INTERFACES_WILDCARD});
+ Properties props = getServiceProperties();
registerWaitAndUnregister(props, true);
}
- public void testRegisterOnCreatedServerWithIdentity() throws Exception {
+ private Properties getServiceProperties() {
Properties props = new Properties();
// Set config to the server container name/provider config name (e.g. ecf.generic.server)
props.put(SERVICE_EXPORTED_CONFIGS, getServerContainerTypeName());
+ // Set the service exported interfaces to all
+ props.put(SERVICE_EXPORTED_INTERFACES, SERVICE_EXPORTED_INTERFACES_WILDCARD);
+ return props;
+ }
+
+ public void testRegisterOnCreatedServerWithIdentity() throws Exception {
+ Properties props = getServiceProperties();
// set the container factory arguments to the server identity (e.g. ecftcp://localhost:3282/server)
props.put(SERVICE_EXPORTED_CONTAINER_FACTORY_ARGUMENTS, new String[] { getServerIdentity() } );
- // Set the service exported interfaces to all
- props.put(SERVICE_EXPORTED_INTERFACES, new String[] {SERVICE_EXPORTED_INTERFACES_WILDCARD});
registerWaitAndUnregister(props, true);
}
@@ -97,9 +108,7 @@
// Create server container
this.server = ContainerFactory.getDefault().createContainer(getServerContainerTypeName(),new Object[] {createServerID()});
- Properties props = new Properties();
- props.put(SERVICE_EXPORTED_CONFIGS, getServerContainerTypeName());
- props.put(SERVICE_EXPORTED_INTERFACES, new String[] {SERVICE_EXPORTED_INTERFACES_WILDCARD});
+ Properties props = getServiceProperties();
registerWaitAndUnregister(props, true);
}
@@ -108,9 +117,7 @@
// Create server container
this.server = ContainerFactory.getDefault().createContainer(getServerContainerTypeName(),new Object[] {createServerID()});
- Properties props = new Properties();
- props.put(SERVICE_EXPORTED_CONFIGS, getServerContainerTypeName());
- props.put(SERVICE_EXPORTED_INTERFACES, new String[] {SERVICE_EXPORTED_INTERFACES_WILDCARD});
+ Properties props = getServiceProperties();
// Add intents
props.put(SERVICE_INTENTS, "passByValue");
registerWaitAndUnregister(props, true);
@@ -120,9 +127,7 @@
// Create server container
this.server = ContainerFactory.getDefault().createContainer(getServerContainerTypeName(),new Object[] {createServerID()});
- Properties props = new Properties();
- props.put(SERVICE_EXPORTED_CONFIGS, getServerContainerTypeName());
- props.put(SERVICE_EXPORTED_INTERFACES, new String[] {SERVICE_EXPORTED_INTERFACES_WILDCARD});
+ Properties props = getServiceProperties();
// Add intent that no one actually exposes
props.put(SERVICE_INTENTS, "foobar");
registerWaitAndUnregister(props, false);
@@ -132,9 +137,7 @@
// Create server container
this.server = ContainerFactory.getDefault().createContainer(getServerContainerTypeName(),new Object[] {createServerID()});
- Properties props = new Properties();
- props.put(SERVICE_EXPORTED_CONFIGS, getServerContainerTypeName());
- props.put(SERVICE_EXPORTED_INTERFACES, new String[] {SERVICE_EXPORTED_INTERFACES_WILDCARD});
+ Properties props = getServiceProperties();
// Add intents
props.put(SERVICE_EXPORTED_INTENTS, "passByValue");
registerWaitAndUnregister(props, true);
@@ -144,9 +147,7 @@
// Create server container
this.server = ContainerFactory.getDefault().createContainer(getServerContainerTypeName(),new Object[] {createServerID()});
- Properties props = new Properties();
- props.put(SERVICE_EXPORTED_CONFIGS, getServerContainerTypeName());
- props.put(SERVICE_EXPORTED_INTERFACES, new String[] {SERVICE_EXPORTED_INTERFACES_WILDCARD});
+ Properties props = getServiceProperties();
// Add intent that no one actually exposes
props.put(SERVICE_EXPORTED_INTENTS, "foobar");
registerWaitAndUnregister(props, false);
@@ -156,9 +157,7 @@
// Create server container
this.server = ContainerFactory.getDefault().createContainer(getServerContainerTypeName(),new Object[] {createServerID()});
- Properties props = new Properties();
- props.put(SERVICE_EXPORTED_CONFIGS, getServerContainerTypeName());
- props.put(SERVICE_EXPORTED_INTERFACES, new String[] {SERVICE_EXPORTED_INTERFACES_WILDCARD});
+ Properties props = getServiceProperties();
// Add intents
props.put(SERVICE_EXPORTED_INTENTS_EXTRA, "passByValue");
registerWaitAndUnregister(props, true);
@@ -168,9 +167,7 @@
// Create server container
this.server = ContainerFactory.getDefault().createContainer(getServerContainerTypeName(),new Object[] {createServerID()});
- Properties props = new Properties();
- props.put(SERVICE_EXPORTED_CONFIGS, getServerContainerTypeName());
- props.put(SERVICE_EXPORTED_INTERFACES, new String[] {SERVICE_EXPORTED_INTERFACES_WILDCARD});
+ Properties props = getServiceProperties();
// Add intent that no one actually exposes
props.put(SERVICE_EXPORTED_INTENTS_EXTRA, "foobar");
registerWaitAndUnregister(props, false);
@@ -180,8 +177,7 @@
// Create server container
this.server = ContainerFactory.getDefault().createContainer(getServerContainerTypeName(),new Object[] {createServerID()});
- Properties props = new Properties();
- props.put(SERVICE_EXPORTED_INTERFACES, new String[] {SERVICE_EXPORTED_INTERFACES_WILDCARD});
+ final Properties props = getServiceProperties();
props.put(SERVICE_EXPORTED_CONTAINER_ID, this.server.getID());
registerWaitAndUnregister(props, true);
}
@@ -190,11 +186,7 @@
// Create server container
this.server = ContainerFactory.getDefault().createContainer(getServerContainerTypeName(),getServerIdentity());
- Properties props = new Properties();
- // Set config to the server container name/provider config name (e.g. ecf.generic.server)
- props.put(SERVICE_EXPORTED_CONFIGS, getServerContainerTypeName());
- // Set the service exported interfaces to all
- props.put(SERVICE_EXPORTED_INTERFACES, new String[] {SERVICE_EXPORTED_INTERFACES_WILDCARD});
+ Properties props = getServiceProperties();
registerWaitAndUnregister(props, true);
}
diff --git a/tests/bundles/org.eclipse.ecf.tests.osgi.services.distribution/src/org/eclipse/ecf/tests/osgi/services/distribution/AbstractServicePublicationTest.java b/tests/bundles/org.eclipse.ecf.tests.osgi.services.distribution/src/org/eclipse/ecf/tests/osgi/services/distribution/AbstractServicePublicationTest.java
index 955b5f2..573cfb3 100644
--- a/tests/bundles/org.eclipse.ecf.tests.osgi.services.distribution/src/org/eclipse/ecf/tests/osgi/services/distribution/AbstractServicePublicationTest.java
+++ b/tests/bundles/org.eclipse.ecf.tests.osgi.services.distribution/src/org/eclipse/ecf/tests/osgi/services/distribution/AbstractServicePublicationTest.java
@@ -9,6 +9,7 @@
******************************************************************************/
package org.eclipse.ecf.tests.osgi.services.distribution;
+import java.util.Arrays;
import java.util.Collection;
import java.util.Dictionary;
import java.util.Hashtable;
@@ -22,19 +23,13 @@
import org.eclipse.ecf.osgi.services.distribution.IDistributionConstants;
import org.eclipse.ecf.tests.internal.osgi.services.distribution.Activator;
import org.osgi.framework.BundleContext;
+import org.osgi.framework.InvalidSyntaxException;
import org.osgi.framework.ServiceReference;
import org.osgi.framework.ServiceRegistration;
import org.osgi.util.tracker.ServiceTracker;
public abstract class AbstractServicePublicationTest extends TestCase implements IDistributionConstants, RemoteServicePublication {
- protected static void assertStringsEqual(final String[] s1, final String[] s2) {
- assertEquals(s1.length, s2.length);
- for (int i = 0; i < s1.length; i++) {
- assertEquals(s1[i], s2[i]);
- }
- }
-
// Member variables that should be set by subclasses
protected IContainer container;
protected String[] ifaces;
@@ -97,7 +92,7 @@
this.container = container;
}
- public void testServicePublication() throws InterruptedException {
+ public void testServicePublication() throws InterruptedException, InvalidSyntaxException {
final BundleContext context = Activator.getDefault().getContext();
// register a service with the marker property set
@@ -116,16 +111,23 @@
tracker.waitForService(10000);
// expected behavior: an endpoint is published
- final ServiceReference ref = context
- .getServiceReference(ServicePublication.class.getName());
- assertTrue(ref != null);
- // check the service publication properties
- final Object o = ref
+ final ServiceReference[] refs = context
+ .getServiceReferences(ServicePublication.class.getName(), null);
+ assertTrue(refs != null);
+
+ for (int i = 0; i < refs.length; i++) {
+ ServiceReference ref = refs[i];
+
+ // check the service publication properties
+ final Object o = ref
.getProperty(ServicePublication.SERVICE_INTERFACE_NAME);
- assertTrue(o instanceof Collection);
- final Collection refIfaces = (Collection) o;
- assertStringsEqual(getInterfaces(), (String []) refIfaces.toArray(new String[] {}));
- Thread.sleep(10000);
+ assertTrue(o instanceof Collection);
+ final Collection refIfaces = (Collection) o;
+ if(Arrays.equals(getInterfaces(), (String []) refIfaces.toArray(new String[] {}))) {
+ return;
+ }
+ }
+ fail("registered service not found.");
}
public void setInterfaces(String [] interfaces) {
this.ifaces = interfaces;