diff options
22 files changed, 557 insertions, 47 deletions
diff --git a/incubation/bundles/org.eclipse.ecf.tests.osgi.services.remoteserviceadmin/META-INF/MANIFEST.MF b/incubation/bundles/org.eclipse.ecf.tests.osgi.services.remoteserviceadmin/META-INF/MANIFEST.MF index 5ca436286..53aec2392 100644 --- a/incubation/bundles/org.eclipse.ecf.tests.osgi.services.remoteserviceadmin/META-INF/MANIFEST.MF +++ b/incubation/bundles/org.eclipse.ecf.tests.osgi.services.remoteserviceadmin/META-INF/MANIFEST.MF @@ -24,4 +24,4 @@ Import-Package: org.eclipse.ecf.core, Require-Bundle: org.eclipse.equinox.common;bundle-version="3.6.0", org.junit;bundle-version="4.8.1", org.eclipse.ecf.tests;bundle-version="2.1.0" -Export-Package: org.eclipse.ecf.tests.osgi.services.remoteserviceadmin +Export-Package: org.eclipse.ecf.tests.osgi.services.remoteserviceadmin;version="1.1.1" diff --git a/incubation/bundles/org.eclipse.ecf.tests.osgi.services.remoteserviceadmin/src/org/eclipse/ecf/tests/osgi/services/remoteserviceadmin/AbstractDistributionTest.java b/incubation/bundles/org.eclipse.ecf.tests.osgi.services.remoteserviceadmin/src/org/eclipse/ecf/tests/osgi/services/remoteserviceadmin/AbstractDistributionTest.java index 0b2be69ea..64d5247cc 100644 --- a/incubation/bundles/org.eclipse.ecf.tests.osgi.services.remoteserviceadmin/src/org/eclipse/ecf/tests/osgi/services/remoteserviceadmin/AbstractDistributionTest.java +++ b/incubation/bundles/org.eclipse.ecf.tests.osgi.services.remoteserviceadmin/src/org/eclipse/ecf/tests/osgi/services/remoteserviceadmin/AbstractDistributionTest.java @@ -9,6 +9,7 @@ ******************************************************************************/ package org.eclipse.ecf.tests.osgi.services.remoteserviceadmin; +import java.util.Arrays; import java.util.Dictionary; import java.util.Enumeration; import java.util.Properties; @@ -181,7 +182,7 @@ public abstract class AbstractDistributionTest extends .getProperty(org.osgi.framework.Constants.OBJECTCLASS); assertTrue(classes != null); // Check object class - assertTrue(classname.equals(classes[0])); + assertTrue(Arrays.asList(classes).contains(classname)); } protected void assertReferencesValidAndFirstHasCorrectType( diff --git a/incubation/bundles/org.eclipse.ecf.tests.osgi.services.remoteserviceadmin/src/org/eclipse/ecf/tests/osgi/services/remoteserviceadmin/AbstractEndpointDescriptionWriterTest.java b/incubation/bundles/org.eclipse.ecf.tests.osgi.services.remoteserviceadmin/src/org/eclipse/ecf/tests/osgi/services/remoteserviceadmin/AbstractEndpointDescriptionWriterTest.java new file mode 100644 index 000000000..c4effd789 --- /dev/null +++ b/incubation/bundles/org.eclipse.ecf.tests.osgi.services.remoteserviceadmin/src/org/eclipse/ecf/tests/osgi/services/remoteserviceadmin/AbstractEndpointDescriptionWriterTest.java @@ -0,0 +1,92 @@ +package org.eclipse.ecf.tests.osgi.services.remoteserviceadmin;
+
+import java.io.IOException;
+import java.io.StringWriter;
+import java.util.Properties;
+
+import org.eclipse.core.runtime.IStatus;
+import org.eclipse.core.runtime.Status;
+import org.eclipse.ecf.osgi.services.remoteserviceadmin.EndpointDescription;
+import org.eclipse.ecf.osgi.services.remoteserviceadmin.EndpointDescriptionWriter;
+import org.eclipse.ecf.osgi.services.remoteserviceadmin.IEndpointDescriptionAdvertiser;
+import org.osgi.framework.ServiceRegistration;
+import org.osgi.service.remoteserviceadmin.RemoteConstants;
+
+public abstract class AbstractEndpointDescriptionWriterTest extends
+ AbstractDistributionTest {
+
+ protected static final int REGISTER_WAIT = 2000;
+ private ServiceRegistration registration;
+
+ private ServiceRegistration writerEndpointDescriptionAdvertiser;
+ private EndpointDescriptionWriter writer;
+
+ protected void setUp() throws Exception {
+ super.setUp();
+ writer = new EndpointDescriptionWriter();
+ writerEndpointDescriptionAdvertiser = getContext().registerService(IEndpointDescriptionAdvertiser.class.getName(), createStandardOutputWriterServiceInfoFactory(), null);
+ }
+
+ private IEndpointDescriptionAdvertiser createStandardOutputWriterServiceInfoFactory() {
+ return new IEndpointDescriptionAdvertiser() {
+
+ @Override
+ public IStatus advertise(
+ org.osgi.service.remoteserviceadmin.EndpointDescription endpointDescription) {
+ // TODO Auto-generated method stub
+ try {
+ StringWriter sr = new StringWriter();
+ sr.append("<?xml version=\"1.0\" encoding=\"UTF-8\"?>").append("\n");
+ writer.writeEndpointDescriptions(sr, new EndpointDescription[] { (EndpointDescription) endpointDescription });
+ System.out.print(sr.toString());
+ } catch (IOException e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ }
+
+ return Status.OK_STATUS;
+ }
+
+ @Override
+ public IStatus unadvertise(
+ org.osgi.service.remoteserviceadmin.EndpointDescription endpointDescription) {
+ // TODO Auto-generated method stub
+ return Status.OK_STATUS;
+ }
+ };
+ }
+
+ protected void tearDown() throws Exception {
+ if (registration != null) {
+ registration.unregister();
+ registration = null;
+ }
+ if (writerEndpointDescriptionAdvertiser != null) {
+ writerEndpointDescriptionAdvertiser.unregister();
+ writerEndpointDescriptionAdvertiser = null;
+ }
+ super.tearDown();
+ }
+
+ public void testRegisterOnCreatedServer() throws Exception {
+ Properties props = getServiceProperties();
+ // Actually register with default service (IConcatService)
+ registration = registerDefaultService(props);
+ // Wait a while
+ Thread.sleep(REGISTER_WAIT);
+ }
+
+ protected abstract String getServerContainerTypeName();
+
+ private Properties getServiceProperties() {
+ Properties props = new Properties();
+ // Set config to the server container name/provider config name (e.g.
+ // ecf.generic.server)
+ props.put(RemoteConstants.SERVICE_EXPORTED_CONFIGS,
+ getServerContainerTypeName());
+ // Set the service exported interfaces to all
+ props.put(RemoteConstants.SERVICE_EXPORTED_INTERFACES, "*");
+ return props;
+ }
+
+}
diff --git a/incubation/bundles/org.eclipse.ecf.tests.osgi.services.remoteserviceadmin/src/org/eclipse/ecf/tests/osgi/services/remoteserviceadmin/AbstractMetadataFactoryTest.java b/incubation/bundles/org.eclipse.ecf.tests.osgi.services.remoteserviceadmin/src/org/eclipse/ecf/tests/osgi/services/remoteserviceadmin/AbstractMetadataFactoryTest.java index 51ec506a2..727ad91f4 100644 --- a/incubation/bundles/org.eclipse.ecf.tests.osgi.services.remoteserviceadmin/src/org/eclipse/ecf/tests/osgi/services/remoteserviceadmin/AbstractMetadataFactoryTest.java +++ b/incubation/bundles/org.eclipse.ecf.tests.osgi.services.remoteserviceadmin/src/org/eclipse/ecf/tests/osgi/services/remoteserviceadmin/AbstractMetadataFactoryTest.java @@ -94,7 +94,6 @@ public abstract class AbstractMetadataFactoryTest extends ECFAbstractTestCase { Map<String,Object> props = new HashMap<String,Object>();
// Add required OSGi properties
addRequiredOSGiProperties(props);
- ID containerID = createECFContainerID(props);
createECFRemoteServiceId(props);
// Add extra properties
addExtraProperties(props);
@@ -108,11 +107,6 @@ public abstract class AbstractMetadataFactoryTest extends ECFAbstractTestCase { // Add full OSGi properties
addOptionalOSGiProperties(props);
// required ECF properties
- ID containerID = createECFContainerID(props);
- createECFRemoteServiceId(props);
- ID targetID = createECFTargetID(props);
- ID[] idFilter = createECFIDFilterIDs(props);
- String rsFilter = createECFRSFilter(props);
// Add extra properties
addExtraProperties(props);
return new EndpointDescription(props);
@@ -127,7 +121,6 @@ public abstract class AbstractMetadataFactoryTest extends ECFAbstractTestCase { Map<String,Object> props = new HashMap<String,Object>();
// Add only ECF properties
// no OSGi properties
- ID containerID = createECFContainerID(props);
createECFRemoteServiceId(props);
// This should throw a runtime exception
return new EndpointDescription(props);
diff --git a/incubation/bundles/org.eclipse.ecf.tests.osgi.services.remoteserviceadmin/src/org/eclipse/ecf/tests/osgi/services/remoteserviceadmin/AbstractRemoteServiceAccessTest.java b/incubation/bundles/org.eclipse.ecf.tests.osgi.services.remoteserviceadmin/src/org/eclipse/ecf/tests/osgi/services/remoteserviceadmin/AbstractRemoteServiceAccessTest.java index 8038947eb..b4815dd81 100644 --- a/incubation/bundles/org.eclipse.ecf.tests.osgi.services.remoteserviceadmin/src/org/eclipse/ecf/tests/osgi/services/remoteserviceadmin/AbstractRemoteServiceAccessTest.java +++ b/incubation/bundles/org.eclipse.ecf.tests.osgi.services.remoteserviceadmin/src/org/eclipse/ecf/tests/osgi/services/remoteserviceadmin/AbstractRemoteServiceAccessTest.java @@ -18,9 +18,6 @@ import org.eclipse.ecf.remoteservice.IRemoteService; import org.eclipse.ecf.remoteservice.events.IRemoteCallCompleteEvent; import org.eclipse.ecf.remoteservice.events.IRemoteCallEvent; import org.eclipse.equinox.concurrent.future.IFuture; -import org.osgi.framework.AllServiceListener; -import org.osgi.framework.ServiceEvent; -import org.osgi.framework.ServiceListener; import org.osgi.framework.ServiceReference; import org.osgi.framework.ServiceRegistration; import org.osgi.service.remoteserviceadmin.RemoteConstants; diff --git a/incubation/bundles/org.eclipse.ecf.tests.osgi.services.remoteserviceadmin/src/org/eclipse/ecf/tests/osgi/services/remoteserviceadmin/AbstractTwoRemoteServiceAccessTest.java b/incubation/bundles/org.eclipse.ecf.tests.osgi.services.remoteserviceadmin/src/org/eclipse/ecf/tests/osgi/services/remoteserviceadmin/AbstractTwoRemoteServiceAccessTest.java new file mode 100644 index 000000000..54add6c4b --- /dev/null +++ b/incubation/bundles/org.eclipse.ecf.tests.osgi.services.remoteserviceadmin/src/org/eclipse/ecf/tests/osgi/services/remoteserviceadmin/AbstractTwoRemoteServiceAccessTest.java @@ -0,0 +1,158 @@ +/******************************************************************************* + * Copyright (c) 2011 Composent and others. All rights reserved. This + * program and the accompanying materials are made available under the terms of + * the Eclipse Public License v1.0 which accompanies this distribution, and is + * available at http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Composent - initial API and implementation + ******************************************************************************/ +package org.eclipse.ecf.tests.osgi.services.remoteserviceadmin; + +import java.util.Properties; + +import org.eclipse.ecf.core.util.Trace; +import org.eclipse.ecf.remoteservice.IRemoteCall; +import org.osgi.framework.ServiceReference; +import org.osgi.framework.ServiceRegistration; +import org.osgi.service.remoteserviceadmin.RemoteConstants; +import org.osgi.util.tracker.ServiceTracker; + +public abstract class AbstractTwoRemoteServiceAccessTest extends + AbstractDistributionTest { + + protected static final int REGISTER_WAIT = Integer.parseInt(System.getProperty("waittime","15000")); + + private final String[] classes = new String[] { TestServiceInterface1.class.getName(), TestServiceInterface2.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(String lookupClass, final Properties props) throws Exception { + // Setup service tracker for client + st = createProxyServiceTracker(lookupClass); + + // Actually register + registration = registerService(classes, + new TestService1(), props); + + // Wait + Thread.sleep(REGISTER_WAIT); + } + + protected void createServiceTrackerAndRegister(String lookupClass) throws Exception { + createServiceTrackerAndRegister(lookupClass, getServiceProperties()); + } + + protected Properties getServiceProperties() { + final Properties props = new Properties(); + props.put(RemoteConstants.SERVICE_EXPORTED_CONFIGS, getServerContainerName()); + props.put(RemoteConstants.SERVICE_EXPORTED_INTERFACES, "*"); + return props; + } + + protected IRemoteCall createRemoteCall() { + return new IRemoteCall() { + + public String getMethod() { + return "doStuff1"; + } + + public Object[] getParameters() { + return new Object[] {}; + } + + public long getTimeout() { + return 30000; + } + + }; + } + + + public void testGetRemoteService1Reference() throws Exception { + String lookupClass = TestServiceInterface1.class.getName(); + createServiceTrackerAndRegister(lookupClass); + + // Service Consumer - Get (remote) ervice references + final ServiceReference[] remoteReferences = st.getServiceReferences(); + assertReferencesValidAndFirstHasCorrectType(remoteReferences, lookupClass); + // Spec requires that the 'service.imported' property be set + assertTrue(remoteReferences[0].getProperty(RemoteConstants.SERVICE_IMPORTED) != null); + } + + public void testGetRemoteService2Reference() throws Exception { + String lookupClass = TestServiceInterface2.class.getName(); + createServiceTrackerAndRegister(lookupClass); + + // Service Consumer - Get (remote) ervice references + final ServiceReference[] remoteReferences = st.getServiceReferences(); + assertReferencesValidAndFirstHasCorrectType(remoteReferences, lookupClass); + // Spec requires that the 'service.imported' property be set + assertTrue(remoteReferences[0].getProperty(RemoteConstants.SERVICE_IMPORTED) != null); + } + + + public void testProxyWithService1() throws Exception { + String lookupClass = TestServiceInterface1.class.getName(); + createServiceTrackerAndRegister(lookupClass); + + // Client - Get service references from service tracker + final ServiceReference[] remoteReferences = st.getServiceReferences(); + assertReferencesValidAndFirstHasCorrectType(remoteReferences, lookupClass); + + // Get proxy/service + final TestServiceInterface1 proxy = (TestServiceInterface1) getContext() + .getService(remoteReferences[0]); + assertNotNull(proxy); + // Now use proxy + final String result = proxy.doStuff1(); + Trace.trace(Activator.PLUGIN_ID, "proxy.doStuff1 result=" + result); + assertTrue(TestServiceInterface1.TEST_SERVICE_STRING1.equals(result)); + } + + public void testProxyWithService2() throws Exception { + + String lookupClass = TestServiceInterface2.class.getName(); + + createServiceTrackerAndRegister(lookupClass); + + // Client - Get service references from service tracker + final ServiceReference[] remoteReferences = st.getServiceReferences(); + assertReferencesValidAndFirstHasCorrectType(remoteReferences, lookupClass); + + // Get proxy/service + final TestServiceInterface2 proxy = (TestServiceInterface2) getContext() + .getService(remoteReferences[0]); + assertNotNull(proxy); + // Now use proxy + String result = proxy.doStuff1(); + Trace.trace(Activator.PLUGIN_ID, "proxy.doStuff1 result=" + result); + assertTrue(TestServiceInterface1.TEST_SERVICE_STRING1.equals(result)); + + // Now use proxy + result = proxy.doStuff2(); + Trace.trace(Activator.PLUGIN_ID, "proxy.doStuff2 result=" + result); + assertTrue(TestServiceInterface2.TEST_SERVICE_STRING2.equals(result)); + + } + +} diff --git a/incubation/bundles/org.eclipse.ecf.tests.osgi.services.remoteserviceadmin/src/org/eclipse/ecf/tests/osgi/services/remoteserviceadmin/TestService1.java b/incubation/bundles/org.eclipse.ecf.tests.osgi.services.remoteserviceadmin/src/org/eclipse/ecf/tests/osgi/services/remoteserviceadmin/TestService1.java index d1bfb7770..40644d7d1 100644 --- a/incubation/bundles/org.eclipse.ecf.tests.osgi.services.remoteserviceadmin/src/org/eclipse/ecf/tests/osgi/services/remoteserviceadmin/TestService1.java +++ b/incubation/bundles/org.eclipse.ecf.tests.osgi.services.remoteserviceadmin/src/org/eclipse/ecf/tests/osgi/services/remoteserviceadmin/TestService1.java @@ -10,10 +10,14 @@ *****************************************************************************/ package org.eclipse.ecf.tests.osgi.services.remoteserviceadmin; -public final class TestService1 implements TestServiceInterface1 { +public final class TestService1 implements TestServiceInterface1, TestServiceInterface2 { public String doStuff1() { return TestServiceInterface1.TEST_SERVICE_STRING1; } + public String doStuff2() { + return TestServiceInterface2.TEST_SERVICE_STRING2; + } + } diff --git a/incubation/bundles/org.eclipse.ecf.tests.osgi.services.remoteserviceadmin/src/org/eclipse/ecf/tests/osgi/services/remoteserviceadmin/TestServiceInterface2.java b/incubation/bundles/org.eclipse.ecf.tests.osgi.services.remoteserviceadmin/src/org/eclipse/ecf/tests/osgi/services/remoteserviceadmin/TestServiceInterface2.java index e078e56c5..313d22410 100644 --- a/incubation/bundles/org.eclipse.ecf.tests.osgi.services.remoteserviceadmin/src/org/eclipse/ecf/tests/osgi/services/remoteserviceadmin/TestServiceInterface2.java +++ b/incubation/bundles/org.eclipse.ecf.tests.osgi.services.remoteserviceadmin/src/org/eclipse/ecf/tests/osgi/services/remoteserviceadmin/TestServiceInterface2.java @@ -10,8 +10,11 @@ *****************************************************************************/ package org.eclipse.ecf.tests.osgi.services.remoteserviceadmin; -public interface TestServiceInterface2 { +public interface TestServiceInterface2 extends TestServiceInterface1 { - void doStuff2(); + public static final String TEST_SERVICE_STRING2 = "TestService2"; + + + String doStuff2(); } diff --git a/providers/bundles/org.eclipse.ecf.provider.remoteservice/META-INF/MANIFEST.MF b/providers/bundles/org.eclipse.ecf.provider.remoteservice/META-INF/MANIFEST.MF index 27a21b08a..3221dda16 100644 --- a/providers/bundles/org.eclipse.ecf.provider.remoteservice/META-INF/MANIFEST.MF +++ b/providers/bundles/org.eclipse.ecf.provider.remoteservice/META-INF/MANIFEST.MF @@ -2,7 +2,7 @@ Manifest-Version: 1.0 Bundle-ManifestVersion: 2 Bundle-Name: %pluginName Bundle-SymbolicName: org.eclipse.ecf.provider.remoteservice;singleton:=true -Bundle-Version: 3.5.0.qualifier +Bundle-Version: 4.0.0.qualifier Bundle-Activator: org.eclipse.ecf.internal.provider.remoteservice.Activator Bundle-Vendor: %providerName Bundle-Localization: plugin 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 29938c6be..61dfad5f9 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 @@ -805,8 +805,7 @@ public class RegistrySharedObject extends BaseSharedObject implements IRemoteSer // generic private Request createRequest(RemoteServiceRegistrationImpl remoteRegistration, IRemoteCall call, IRemoteCallListener listener) { - final RemoteServiceReferenceImpl refImpl = (RemoteServiceReferenceImpl) remoteRegistration.getReference(); - return new Request(this.getLocalContainerID(), remoteRegistration.getServiceId(), RemoteCallImpl.createRemoteCall(refImpl.getRemoteClass(), call.getMethod(), call.getParameters(), call.getTimeout()), listener); + return new Request(this.getLocalContainerID(), remoteRegistration.getServiceId(), RemoteCallImpl.createRemoteCall(null, call.getMethod(), call.getParameters(), call.getTimeout()), listener); } void doFireRemoteServiceListeners(IRemoteServiceEvent event) { @@ -1862,7 +1861,7 @@ public class RegistrySharedObject extends BaseSharedObject implements IRemoteSer } /** - * @since 3.5 + * @since 4.0 */ protected IRemoteServiceCallPolicy getRemoteServiceCallPolicy() { synchronized (remoteServiceCallPolicyLock) { @@ -1871,7 +1870,7 @@ public class RegistrySharedObject extends BaseSharedObject implements IRemoteSer } /** - * @since 3.5 + * @since 4.0 */ public boolean setRemoteServiceCallPolicy(IRemoteServiceCallPolicy policy) { synchronized (remoteServiceCallPolicyLock) { diff --git a/providers/bundles/org.eclipse.ecf.provider.remoteservice/src/org/eclipse/ecf/provider/remoteservice/generic/RemoteCallImpl.java b/providers/bundles/org.eclipse.ecf.provider.remoteservice/src/org/eclipse/ecf/provider/remoteservice/generic/RemoteCallImpl.java index 117cd191e..8e8f83016 100644 --- a/providers/bundles/org.eclipse.ecf.provider.remoteservice/src/org/eclipse/ecf/provider/remoteservice/generic/RemoteCallImpl.java +++ b/providers/bundles/org.eclipse.ecf.provider.remoteservice/src/org/eclipse/ecf/provider/remoteservice/generic/RemoteCallImpl.java @@ -19,18 +19,13 @@ public class RemoteCallImpl extends SharedObjectMsg implements IRemoteCall, Seri long timeout = IRemoteCall.DEFAULT_TIMEOUT; + /** + * @since 4.0 + */ public static RemoteCallImpl createRemoteCall(String clazz, String method, Object[] parameters, long timeout) { return new RemoteCallImpl(clazz, method, parameters, timeout); } - public static RemoteCallImpl createRemoteCall(String clazz, String method, Object[] parameters) { - return RemoteCallImpl.createRemoteCall(clazz, method, parameters, IRemoteCall.DEFAULT_TIMEOUT); - } - - public static RemoteCallImpl createRemoteCall(String clazz, String method) { - return RemoteCallImpl.createRemoteCall(clazz, method, null, IRemoteCall.DEFAULT_TIMEOUT); - } - protected RemoteCallImpl(String clazz, String method, Object[] parameters, long timeout) { super(clazz, method, parameters); this.timeout = timeout; diff --git a/providers/bundles/org.eclipse.ecf.provider.remoteservice/src/org/eclipse/ecf/provider/remoteservice/generic/RemoteServiceContainer.java b/providers/bundles/org.eclipse.ecf.provider.remoteservice/src/org/eclipse/ecf/provider/remoteservice/generic/RemoteServiceContainer.java index af101bf76..2346da015 100644 --- a/providers/bundles/org.eclipse.ecf.provider.remoteservice/src/org/eclipse/ecf/provider/remoteservice/generic/RemoteServiceContainer.java +++ b/providers/bundles/org.eclipse.ecf.provider.remoteservice/src/org/eclipse/ecf/provider/remoteservice/generic/RemoteServiceContainer.java @@ -139,7 +139,7 @@ public class RemoteServiceContainer extends TCPClientSOContainer implements IRem } /** - * @since 3.5 + * @since 4.0 */ public boolean setRemoteServiceCallPolicy(IRemoteServiceCallPolicy policy) { return registry.setRemoteServiceCallPolicy(policy); diff --git a/providers/bundles/org.eclipse.ecf.provider.remoteservice/src/org/eclipse/ecf/provider/remoteservice/generic/RemoteServiceReferenceImpl.java b/providers/bundles/org.eclipse.ecf.provider.remoteservice/src/org/eclipse/ecf/provider/remoteservice/generic/RemoteServiceReferenceImpl.java index f9029c530..23d315083 100644 --- a/providers/bundles/org.eclipse.ecf.provider.remoteservice/src/org/eclipse/ecf/provider/remoteservice/generic/RemoteServiceReferenceImpl.java +++ b/providers/bundles/org.eclipse.ecf.provider.remoteservice/src/org/eclipse/ecf/provider/remoteservice/generic/RemoteServiceReferenceImpl.java @@ -47,17 +47,8 @@ public class RemoteServiceReferenceImpl implements IRemoteServiceReference { return registration; } - protected void setRemoteClass(String clazz) { - this.clazz = clazz; - } - - protected String getRemoteClass() { - return clazz; - } - public String toString() { StringBuffer buf = new StringBuffer("RemoteServiceReferenceImpl["); //$NON-NLS-1$ - buf.append("class=").append(getRemoteClass()).append(";"); //$NON-NLS-1$ //$NON-NLS-2$ buf.append("registration=").append(getRegistration()).append("]"); //$NON-NLS-1$ //$NON-NLS-2$ return buf.toString(); } diff --git a/providers/bundles/org.eclipse.ecf.provider.remoteservice/src/org/eclipse/ecf/provider/remoteservice/generic/RemoteServiceRegistrationImpl.java b/providers/bundles/org.eclipse.ecf.provider.remoteservice/src/org/eclipse/ecf/provider/remoteservice/generic/RemoteServiceRegistrationImpl.java index bad05f2d2..2661c60c3 100644 --- a/providers/bundles/org.eclipse.ecf.provider.remoteservice/src/org/eclipse/ecf/provider/remoteservice/generic/RemoteServiceRegistrationImpl.java +++ b/providers/bundles/org.eclipse.ecf.provider.remoteservice/src/org/eclipse/ecf/provider/remoteservice/generic/RemoteServiceRegistrationImpl.java @@ -12,6 +12,8 @@ import java.io.Serializable; import java.lang.reflect.Array; import java.util.*; import org.eclipse.ecf.core.identity.ID; +import org.eclipse.ecf.core.sharedobject.SharedObjectMsg; +import org.eclipse.ecf.core.util.reflection.ClassUtil; import org.eclipse.ecf.remoteservice.*; /** @@ -339,7 +341,7 @@ public class RemoteServiceRegistrationImpl implements IRemoteServiceRegistration } public Object callService(RemoteCallImpl call) throws Exception { - return call.invoke(service); + return ClassUtil.getMethod(service.getClass(), call.getMethod(), SharedObjectMsg.getTypesForParameters(call.getParameters())).invoke(service, call.getParameters()); } public String toString() { diff --git a/providers/bundles/org.eclipse.ecf.provider.remoteservice/src/org/eclipse/ecf/provider/remoteservice/generic/RemoteServiceRegistryImpl.java b/providers/bundles/org.eclipse.ecf.provider.remoteservice/src/org/eclipse/ecf/provider/remoteservice/generic/RemoteServiceRegistryImpl.java index d2ac1a59f..c2641278a 100644 --- a/providers/bundles/org.eclipse.ecf.provider.remoteservice/src/org/eclipse/ecf/provider/remoteservice/generic/RemoteServiceRegistryImpl.java +++ b/providers/bundles/org.eclipse.ecf.provider.remoteservice/src/org/eclipse/ecf/provider/remoteservice/generic/RemoteServiceRegistryImpl.java @@ -138,9 +138,6 @@ public class RemoteServiceRegistryImpl implements Serializable { final IRemoteServiceReference reference = registration.getReference(); if ((filter == null) || filter.match(reference)) { - // Must be RemoteServiceReferenceImpl - final RemoteServiceReferenceImpl impl = (RemoteServiceReferenceImpl) reference; - impl.setRemoteClass(clazz); references.add(reference); } } diff --git a/tests/bundles/org.eclipse.ecf.tests.osgi.services.distribution.generic/src/org/eclipse/ecf/tests/osgi/services/distribution/generic/GenericTwoRemoteServiceAccessTest.java b/tests/bundles/org.eclipse.ecf.tests.osgi.services.distribution.generic/src/org/eclipse/ecf/tests/osgi/services/distribution/generic/GenericTwoRemoteServiceAccessTest.java new file mode 100644 index 000000000..26330ba31 --- /dev/null +++ b/tests/bundles/org.eclipse.ecf.tests.osgi.services.distribution.generic/src/org/eclipse/ecf/tests/osgi/services/distribution/generic/GenericTwoRemoteServiceAccessTest.java @@ -0,0 +1,40 @@ +/******************************************************************************* +* Copyright (c) 2011 Composent, Inc. and others. All rights reserved. This +* program and the accompanying materials are made available under the terms of +* the Eclipse Public License v1.0 which accompanies this distribution, and is +* available at http://www.eclipse.org/legal/epl-v10.html +* +* Contributors: +* Composent - initial API and implementation +******************************************************************************/ +package org.eclipse.ecf.tests.osgi.services.distribution.generic; + +import org.eclipse.ecf.tests.osgi.services.distribution.AbstractTwoRemoteServiceAccessTest; + + +public class GenericTwoRemoteServiceAccessTest extends AbstractTwoRemoteServiceAccessTest { + + /* + * (non-Javadoc) + * + * @see junit.framework.TestCase#setUp() + */ + protected void setUp() throws Exception { + super.setUp(); + setClientCount(1); + createServerAndClients(); + connectClients(); + setupRemoteServiceAdapters(); + } + + + protected void tearDown() throws Exception { + cleanUpServerAndClients(); + super.tearDown(); + } + + protected String getClientContainerName() { + return "ecf.generic.client"; + } + +} diff --git a/tests/bundles/org.eclipse.ecf.tests.osgi.services.distribution.r-osgi/src/org/eclipse/ecf/tests/osgi/services/distribution/r_osgi/R_OSGiTwoRemoteServiceAccessTest.java b/tests/bundles/org.eclipse.ecf.tests.osgi.services.distribution.r-osgi/src/org/eclipse/ecf/tests/osgi/services/distribution/r_osgi/R_OSGiTwoRemoteServiceAccessTest.java new file mode 100644 index 000000000..508fd1dbc --- /dev/null +++ b/tests/bundles/org.eclipse.ecf.tests.osgi.services.distribution.r-osgi/src/org/eclipse/ecf/tests/osgi/services/distribution/r_osgi/R_OSGiTwoRemoteServiceAccessTest.java @@ -0,0 +1,73 @@ +/******************************************************************************* +* Copyright (c) 2011 Composent, Inc. and others. All rights reserved. This +* program and the accompanying materials are made available under the terms of +* the Eclipse Public License v1.0 which accompanies this distribution, and is +* available at http://www.eclipse.org/legal/epl-v10.html +* +* Contributors: +* Composent - initial API and implementation +******************************************************************************/ +package org.eclipse.ecf.tests.osgi.services.distribution.r_osgi; + +import java.util.Properties; + +import org.eclipse.ecf.core.ContainerFactory; +import org.eclipse.ecf.core.IContainer; +import org.eclipse.ecf.core.identity.IDFactory; +import org.eclipse.ecf.osgi.services.distribution.IDistributionConstants; +import org.eclipse.ecf.tests.osgi.services.distribution.AbstractTwoRemoteServiceAccessTest; + + +public class R_OSGiTwoRemoteServiceAccessTest extends AbstractTwoRemoteServiceAccessTest { + + private static final String CONTAINER_TYPE_NAME = "ecf.r_osgi.peer"; + + private static final String SERVER_IDENTITY = "r-osgi://localhost:9278"; + + /* + * (non-Javadoc) + * + * @see junit.framework.TestCase#setUp() + */ + protected void setUp() throws Exception { + super.setUp(); + setClientCount(1); + createServerAndClients(); + setupRemoteServiceAdapters(); + } + + + protected void tearDown() throws Exception { + cleanUpServerAndClients(); + super.tearDown(); + } + + protected IContainer createClient(int index) throws Exception { + return ContainerFactory.getDefault().createContainer("ecf.r_osgi.peer", + new Object[] { IDFactory.getDefault().createStringID( + "r-osgi://localhost:"+(9279+index)) }); + } + + protected IContainer createServer() throws Exception { + serverID = IDFactory.getDefault().createID("ecf.namespace.r_osgi",SERVER_IDENTITY); + return ContainerFactory.getDefault().createContainer(CONTAINER_TYPE_NAME,serverID); + } + + protected String getClientContainerName() { + return CONTAINER_TYPE_NAME; + } + + protected String getServerIdentity() { + return SERVER_IDENTITY; + } + + protected String getServerContainerName() { + return CONTAINER_TYPE_NAME; + } + + protected Properties getServiceProperties() { + Properties props = super.getServiceProperties(); + props.put(IDistributionConstants.SERVICE_EXPORTED_CONTAINER_ID, serverID); + return props; + } +} diff --git a/tests/bundles/org.eclipse.ecf.tests.osgi.services.distribution/src/org/eclipse/ecf/tests/osgi/services/distribution/AbstractDistributionTest.java b/tests/bundles/org.eclipse.ecf.tests.osgi.services.distribution/src/org/eclipse/ecf/tests/osgi/services/distribution/AbstractDistributionTest.java index 4625c90fe..40dec6641 100644 --- a/tests/bundles/org.eclipse.ecf.tests.osgi.services.distribution/src/org/eclipse/ecf/tests/osgi/services/distribution/AbstractDistributionTest.java +++ b/tests/bundles/org.eclipse.ecf.tests.osgi.services.distribution/src/org/eclipse/ecf/tests/osgi/services/distribution/AbstractDistributionTest.java @@ -9,6 +9,7 @@ ******************************************************************************/ package org.eclipse.ecf.tests.osgi.services.distribution; +import java.util.Arrays; import java.util.Dictionary; import java.util.Enumeration; import java.util.Properties; @@ -185,7 +186,7 @@ public abstract class AbstractDistributionTest extends .getProperty(org.osgi.framework.Constants.OBJECTCLASS); assertTrue(classes != null); // Check object class - assertTrue(classname.equals(classes[0])); + assertTrue(Arrays.asList(classes).contains(classname)); } protected void assertReferencesValidAndFirstHasCorrectType( diff --git a/tests/bundles/org.eclipse.ecf.tests.osgi.services.distribution/src/org/eclipse/ecf/tests/osgi/services/distribution/AbstractTwoRemoteServiceAccessTest.java b/tests/bundles/org.eclipse.ecf.tests.osgi.services.distribution/src/org/eclipse/ecf/tests/osgi/services/distribution/AbstractTwoRemoteServiceAccessTest.java new file mode 100644 index 000000000..35c1f558a --- /dev/null +++ b/tests/bundles/org.eclipse.ecf.tests.osgi.services.distribution/src/org/eclipse/ecf/tests/osgi/services/distribution/AbstractTwoRemoteServiceAccessTest.java @@ -0,0 +1,158 @@ +/******************************************************************************* + * Copyright (c) 2011 Composent and others. All rights reserved. This + * program and the accompanying materials are made available under the terms of + * the Eclipse Public License v1.0 which accompanies this distribution, and is + * available at http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Composent - initial API and implementation + ******************************************************************************/ +package org.eclipse.ecf.tests.osgi.services.distribution; + +import java.util.Properties; + +import org.eclipse.ecf.core.util.Trace; +import org.eclipse.ecf.remoteservice.IRemoteCall; +import org.eclipse.ecf.tests.internal.osgi.services.distribution.Activator; +import org.osgi.framework.ServiceReference; +import org.osgi.framework.ServiceRegistration; +import org.osgi.util.tracker.ServiceTracker; + +public abstract class AbstractTwoRemoteServiceAccessTest extends + AbstractDistributionTest { + + protected static final int REGISTER_WAIT = Integer.parseInt(System.getProperty("waittime","15000")); + + private final String[] classes = new String[] { TestServiceInterface1.class.getName(), TestServiceInterface2.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(String lookupClass, final Properties props) throws Exception { + // Setup service tracker for client + st = createProxyServiceTracker(lookupClass); + + // Actually register + registration = registerService(classes, + new TestService1(), props); + + // Wait + Thread.sleep(REGISTER_WAIT); + } + + protected void createServiceTrackerAndRegister(String lookupClass) throws Exception { + createServiceTrackerAndRegister(lookupClass, getServiceProperties()); + } + + protected Properties getServiceProperties() { + final Properties props = new Properties(); + props.put(SERVICE_EXPORTED_CONFIGS, getServerContainerName()); + props.put(SERVICE_EXPORTED_INTERFACES, SERVICE_EXPORTED_INTERFACES_WILDCARD); + return props; + } + + protected IRemoteCall createRemoteCall() { + return new IRemoteCall() { + + public String getMethod() { + return "doStuff1"; + } + + public Object[] getParameters() { + return new Object[] {}; + } + + public long getTimeout() { + return 30000; + } + + }; + } + + + public void testGetRemoteService1Reference() throws Exception { + String lookupClass = TestServiceInterface1.class.getName(); + createServiceTrackerAndRegister(lookupClass); + + // Service Consumer - Get (remote) ervice references + final ServiceReference[] remoteReferences = st.getServiceReferences(); + assertReferencesValidAndFirstHasCorrectType(remoteReferences, lookupClass); + // Spec requires that the 'service.imported' property be set + assertTrue(remoteReferences[0].getProperty(SERVICE_IMPORTED) != null); + } + + public void testGetRemoteService2Reference() throws Exception { + String lookupClass = TestServiceInterface2.class.getName(); + createServiceTrackerAndRegister(lookupClass); + + // Service Consumer - Get (remote) ervice references + final ServiceReference[] remoteReferences = st.getServiceReferences(); + assertReferencesValidAndFirstHasCorrectType(remoteReferences, lookupClass); + // Spec requires that the 'service.imported' property be set + assertTrue(remoteReferences[0].getProperty(SERVICE_IMPORTED) != null); + } + + + public void testProxyWithService1() throws Exception { + String lookupClass = TestServiceInterface1.class.getName(); + createServiceTrackerAndRegister(lookupClass); + + // Client - Get service references from service tracker + final ServiceReference[] remoteReferences = st.getServiceReferences(); + assertReferencesValidAndFirstHasCorrectType(remoteReferences, lookupClass); + + // Get proxy/service + final TestServiceInterface1 proxy = (TestServiceInterface1) getContext() + .getService(remoteReferences[0]); + assertNotNull(proxy); + // Now use proxy + final String result = proxy.doStuff1(); + Trace.trace(Activator.PLUGIN_ID, "proxy.doStuff1 result=" + result); + assertTrue(TestServiceInterface1.TEST_SERVICE_STRING1.equals(result)); + } + + public void testProxyWithService2() throws Exception { + + String lookupClass = TestServiceInterface2.class.getName(); + + createServiceTrackerAndRegister(lookupClass); + + // Client - Get service references from service tracker + final ServiceReference[] remoteReferences = st.getServiceReferences(); + assertReferencesValidAndFirstHasCorrectType(remoteReferences, lookupClass); + + // Get proxy/service + final TestServiceInterface2 proxy = (TestServiceInterface2) getContext() + .getService(remoteReferences[0]); + assertNotNull(proxy); + // Now use proxy + String result = proxy.doStuff1(); + Trace.trace(Activator.PLUGIN_ID, "proxy.doStuff1 result=" + result); + assertTrue(TestServiceInterface1.TEST_SERVICE_STRING1.equals(result)); + + // Now use proxy + result = proxy.doStuff2(); + Trace.trace(Activator.PLUGIN_ID, "proxy.doStuff2 result=" + result); + assertTrue(TestServiceInterface2.TEST_SERVICE_STRING2.equals(result)); + + } + +} diff --git a/tests/bundles/org.eclipse.ecf.tests.osgi.services.distribution/src/org/eclipse/ecf/tests/osgi/services/distribution/TestService1.java b/tests/bundles/org.eclipse.ecf.tests.osgi.services.distribution/src/org/eclipse/ecf/tests/osgi/services/distribution/TestService1.java index e1e8962f4..d5b3dcac8 100644 --- a/tests/bundles/org.eclipse.ecf.tests.osgi.services.distribution/src/org/eclipse/ecf/tests/osgi/services/distribution/TestService1.java +++ b/tests/bundles/org.eclipse.ecf.tests.osgi.services.distribution/src/org/eclipse/ecf/tests/osgi/services/distribution/TestService1.java @@ -10,10 +10,14 @@ *****************************************************************************/ package org.eclipse.ecf.tests.osgi.services.distribution; -public final class TestService1 implements TestServiceInterface1 { +public final class TestService1 implements TestServiceInterface1, TestServiceInterface2 { public String doStuff1() { return TestServiceInterface1.TEST_SERVICE_STRING1; } + public String doStuff2() { + return TestServiceInterface2.TEST_SERVICE_STRING2; + } + } diff --git a/tests/bundles/org.eclipse.ecf.tests.osgi.services.distribution/src/org/eclipse/ecf/tests/osgi/services/distribution/TestServiceInterface2.java b/tests/bundles/org.eclipse.ecf.tests.osgi.services.distribution/src/org/eclipse/ecf/tests/osgi/services/distribution/TestServiceInterface2.java index eded56808..dbbd1bd4f 100644 --- a/tests/bundles/org.eclipse.ecf.tests.osgi.services.distribution/src/org/eclipse/ecf/tests/osgi/services/distribution/TestServiceInterface2.java +++ b/tests/bundles/org.eclipse.ecf.tests.osgi.services.distribution/src/org/eclipse/ecf/tests/osgi/services/distribution/TestServiceInterface2.java @@ -10,8 +10,10 @@ *****************************************************************************/ package org.eclipse.ecf.tests.osgi.services.distribution; -public interface TestServiceInterface2 { +public interface TestServiceInterface2 extends TestServiceInterface1 { - void doStuff2(); + public static final String TEST_SERVICE_STRING2 = "TestService2"; + + String doStuff2(); } diff --git a/tests/bundles/org.eclipse.ecf.tests.remoteservice/META-INF/MANIFEST.MF b/tests/bundles/org.eclipse.ecf.tests.remoteservice/META-INF/MANIFEST.MF index de3895f51..2add14b11 100755..100644 --- a/tests/bundles/org.eclipse.ecf.tests.remoteservice/META-INF/MANIFEST.MF +++ b/tests/bundles/org.eclipse.ecf.tests.remoteservice/META-INF/MANIFEST.MF @@ -11,7 +11,7 @@ Require-Bundle: org.eclipse.equinox.common, org.eclipse.ecf.remoteservice, org.junit, org.eclipse.equinox.app;bundle-version="1.2.0" -Export-Package: org.eclipse.ecf.tests.remoteservice +Export-Package: org.eclipse.ecf.tests.remoteservice;version="2.0.0" Import-Package: org.eclipse.equinox.concurrent.future;version="1.0.0", org.eclipse.osgi.util, org.osgi.framework;version="1.4.0", |