diff --git a/itests/felix/pom.xml b/itests/felix/pom.xml index f75361f49..eefe1af3b 100644 --- a/itests/felix/pom.xml +++ b/itests/felix/pom.xml @@ -30,12 +30,12 @@ org.apache.felix org.apache.felix.configadmin - 1.8.8 + 1.8.14 org.apache.felix org.apache.felix.scr - 2.0.2 + 2.0.10 @@ -134,7 +134,7 @@ org.ops4j.pax.exam - pax-exam-container-forked + pax-exam-container-native test @@ -150,7 +150,7 @@ org.apache.felix org.apache.felix.framework - 5.0.1 + 5.6.1 test @@ -166,7 +166,7 @@ org.apache.servicemix.tooling depends-maven-plugin - 1.3.1 + 1.4.0 generate-depends-file diff --git a/itests/felix/src/test/java/org/apache/aries/rsa/itests/felix/RsaTestBase.java b/itests/felix/src/test/java/org/apache/aries/rsa/itests/felix/RsaTestBase.java index 8a53ab0c2..b6bbbd93e 100644 --- a/itests/felix/src/test/java/org/apache/aries/rsa/itests/felix/RsaTestBase.java +++ b/itests/felix/src/test/java/org/apache/aries/rsa/itests/felix/RsaTestBase.java @@ -37,7 +37,6 @@ import org.ops4j.pax.exam.Option; import org.ops4j.pax.exam.options.MavenArtifactProvisionOption; import org.ops4j.pax.exam.options.OptionalCompositeOption; -import org.ops4j.pax.exam.options.SystemPropertyOption; import org.osgi.framework.Bundle; import org.osgi.framework.BundleContext; import org.osgi.service.cm.ConfigurationAdmin; @@ -71,7 +70,7 @@ public void testInstalled() throws Exception { } } - protected static int getFreePort() throws IOException { + protected int getFreePort() throws IOException { ServerSocket socket = new ServerSocket(); try { socket.setReuseAddress(true); // enables quickly reopening socket on same port @@ -82,51 +81,62 @@ protected static int getFreePort() throws IOException { } } + protected Bundle getBundle(String symName) { + Bundle serviceBundle = null; + Bundle[] bundles = bundleContext.getBundles(); + for (Bundle bundle : bundles) { + if(symName.equals(bundle.getSymbolicName())) { + serviceBundle = bundle; + break; + } + } + return serviceBundle; + } + protected static Option echoTcpAPI() { return mvn("org.apache.aries.rsa.examples.echotcp", "org.apache.aries.rsa.examples.echotcp.api"); } - + protected static Option echoTcpConsumer() { return CoreOptions.composite( - mvn("org.apache.felix", "org.apache.felix.scr"), - mvn("org.apache.aries.rsa.examples.echotcp", "org.apache.aries.rsa.examples.echotcp.api"), - // Consumer is needed to trigger service import. Pax exam inject does not trigger it + echoTcpAPI(), + // Consumer bundle is needed to trigger service import. Pax exam inject does not trigger it mvn("org.apache.aries.rsa.examples.echotcp", "org.apache.aries.rsa.examples.echotcp.consumer") ); } protected static Option echoTcpService() { return composite( - mvn("org.apache.felix", "org.apache.felix.scr"), - mvn("org.apache.aries.rsa.examples.echotcp", "org.apache.aries.rsa.examples.echotcp.api"), + echoTcpAPI(), mvn("org.apache.aries.rsa.examples.echotcp", "org.apache.aries.rsa.examples.echotcp.service") ); } - + protected static Option rsaCore() { - return composite(junitBundles(), + return composite(junitBundles(), localRepo(), systemProperty("pax.exam.osgi.unresolved.fail").value("true"), systemProperty("org.ops4j.pax.logging.DefaultServiceLog.level").value("INFO"), systemProperty("aries.rsa.hostname").value("localhost"), mvn("org.apache.felix", "org.apache.felix.configadmin"), + mvn("org.apache.felix", "org.apache.felix.scr"), mvn("org.apache.aries.rsa", "org.apache.aries.rsa.core"), mvn("org.apache.aries.rsa", "org.apache.aries.rsa.spi"), mvn("org.apache.aries.rsa", "org.apache.aries.rsa.topology-manager"), mvn("org.apache.aries.rsa.discovery", "org.apache.aries.rsa.discovery.local") ); } - + protected static Option debug() { return CoreOptions.vmOption("-Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=5005"); } - + protected static Option rsaDiscoveryConfig() { return composite( mvn("org.apache.aries.rsa.discovery", "org.apache.aries.rsa.discovery.config") ); } - + protected static Option rsaDiscoveryZookeeper() { return composite( systemProperty("zkPort").value("15201"), @@ -135,14 +145,11 @@ protected static Option rsaDiscoveryZookeeper() { ); } - protected static Option rsaTcp() { - return composite( - systemProperty("java.net.preferIPv4Stack").value("true"), - mvn("org.apache.aries.rsa.provider", "org.apache.aries.rsa.provider.tcp") - ); + protected static Option rsaProviderTcp() { + return mvn("org.apache.aries.rsa.provider", "org.apache.aries.rsa.provider.tcp"); } - protected static Option rsaFastBin() { + protected static Option rsaProviderFastBin() { return composite(mvn("org.fusesource.hawtbuf", "hawtbuf"), mvn("org.fusesource.hawtdispatch", "hawtdispatch"), mvn("org.apache.aries.rsa.provider", "org.apache.aries.rsa.provider.fastbin")); @@ -160,7 +167,7 @@ protected static Option configZKServer() { .asOption(); } - protected static Option configFastBin(String port) { + protected static Option configFastBinPort(String port) { return newConfiguration("org.apache.aries.rsa.provider.fastbin") // .put("uri", "tcp://0.0.0.0:" + port) // .asOption(); diff --git a/itests/felix/src/test/java/org/apache/aries/rsa/itests/felix/TwoContainerPaxExam.java b/itests/felix/src/test/java/org/apache/aries/rsa/itests/felix/TwoContainerPaxExam.java index f839dea76..db941fc0d 100644 --- a/itests/felix/src/test/java/org/apache/aries/rsa/itests/felix/TwoContainerPaxExam.java +++ b/itests/felix/src/test/java/org/apache/aries/rsa/itests/felix/TwoContainerPaxExam.java @@ -29,6 +29,12 @@ import org.ops4j.pax.exam.junit.PaxExam; import org.ops4j.pax.exam.spi.PaxExamRuntime; +/** + * Can be used instead of the PaxExam runner to start a second + * OSGi container that typically hosts the server side for the test. + * + * Use the @ServerConfiguration annotation to mark the config of your server side + */ public class TwoContainerPaxExam extends PaxExam { private Class testClass; diff --git a/itests/felix/src/test/java/org/apache/aries/rsa/itests/felix/discovery/config/TestConfigDiscoveryRoundTrip.java b/itests/felix/src/test/java/org/apache/aries/rsa/itests/felix/discovery/config/TestConfigDiscoveryRoundTrip.java index f5eef3f62..179b2edf2 100644 --- a/itests/felix/src/test/java/org/apache/aries/rsa/itests/felix/discovery/config/TestConfigDiscoveryRoundTrip.java +++ b/itests/felix/src/test/java/org/apache/aries/rsa/itests/felix/discovery/config/TestConfigDiscoveryRoundTrip.java @@ -19,23 +19,20 @@ */ -import static org.junit.Assert.assertEquals; -import static org.ops4j.pax.exam.cm.ConfigurationAdminOptions.factoryConfiguration; - -import java.io.IOException; - -import javax.inject.Inject; - import org.apache.aries.rsa.examples.echotcp.api.EchoService; import org.apache.aries.rsa.itests.felix.RsaTestBase; import org.apache.aries.rsa.itests.felix.ServerConfiguration; import org.apache.aries.rsa.itests.felix.TwoContainerPaxExam; -import org.junit.Ignore; import org.junit.Test; import org.junit.runner.RunWith; import org.ops4j.pax.exam.Configuration; import org.ops4j.pax.exam.Option; -import org.ops4j.pax.exam.options.SystemPropertyOption; + +import javax.inject.Inject; +import java.io.IOException; + +import static org.junit.Assert.assertEquals; +import static org.ops4j.pax.exam.cm.ConfigurationAdminOptions.factoryConfiguration; @RunWith(TwoContainerPaxExam.class) public class TestConfigDiscoveryRoundTrip extends RsaTestBase { @@ -43,42 +40,40 @@ public class TestConfigDiscoveryRoundTrip extends RsaTestBase { @Inject EchoService echoService; - static String tcpPort = "8201"; - @ServerConfiguration public static Option[] remoteConfig() throws IOException { - return new Option[] { - rsaCore(), - rsaTcp(), - echoTcpService() + return new Option[] // + { + rsaCore(), // + rsaProviderTcp(), // + echoTcpService() }; } @Configuration public static Option[] configure() throws Exception { - return new Option[] { - rsaCore(), - rsaDiscoveryConfig(), - rsaTcp(), - echoTcpConsumer(), - configTcpConfigDiscovery() + return new Option[] // + { + rsaCore(), // + rsaDiscoveryConfig(), // + rsaProviderTcp(), // + echoTcpConsumer(), // + configImportEchoService() }; } - - protected static Option configTcpConfigDiscovery() { + protected static Option configImportEchoService() { return factoryConfiguration("org.apache.aries.rsa.discovery.config") .put("service.imported", "true") .put("service.imported.configs", "aries.tcp") .put("objectClass", "org.apache.aries.rsa.examples.echotcp.api.EchoService") - .put("endpoint.id", "tcp://localhost:"+tcpPort) + .put("endpoint.id", "tcp://localhost:8201") .put("aries.tcp.hostname", "localhost") - .put("aries.tcp.port", tcpPort) + .put("aries.tcp.port", "8201") .asOption(); } @Test - @Ignore //cannot get this to work on the new buildslaves in openstack public void testCall() throws Exception { assertEquals("test", echoService.echo("test")); } diff --git a/itests/felix/src/test/java/org/apache/aries/rsa/itests/felix/fastbin/TestFastbinRoundTrip.java b/itests/felix/src/test/java/org/apache/aries/rsa/itests/felix/fastbin/TestFastbinRoundTrip.java index ecd2d74e5..32db35400 100644 --- a/itests/felix/src/test/java/org/apache/aries/rsa/itests/felix/fastbin/TestFastbinRoundTrip.java +++ b/itests/felix/src/test/java/org/apache/aries/rsa/itests/felix/fastbin/TestFastbinRoundTrip.java @@ -36,32 +36,35 @@ @RunWith(TwoContainerPaxExam.class) public class TestFastbinRoundTrip extends RsaTestBase { + private static final String FASTBIN_PORT_SERVER = "2544"; + private static final String FASTBIN_PORT_CLIENT = "2545"; @Inject EchoService echoService; @ServerConfiguration public static Option[] remoteConfig() throws IOException { return new Option[] // - { - rsaCore(), - rsaDiscoveryZookeeper(), - rsaFastBin(), - echoTcpService(), - configZKServer(), - configZKDiscovery(), - configFastBin("2544"), + { + rsaCore(), // + rsaDiscoveryZookeeper(), // + rsaProviderFastBin(), // + echoTcpService(), // + configZKServer(), // + configZKDiscovery(), // + configFastBinPort(FASTBIN_PORT_SERVER), }; } @Configuration public static Option[] configure() throws Exception { - return new Option[] { - rsaCore(), - rsaDiscoveryZookeeper(), - rsaFastBin(), - echoTcpConsumer(), - configZKDiscovery(), - configFastBin("2545") + return new Option[] // + { + rsaCore(), // + rsaDiscoveryZookeeper(), // + rsaProviderFastBin(), // + echoTcpConsumer(), // + configZKDiscovery(), // + configFastBinPort(FASTBIN_PORT_CLIENT) }; } diff --git a/itests/felix/src/test/java/org/apache/aries/rsa/itests/felix/rsa/TestRSAListener.java b/itests/felix/src/test/java/org/apache/aries/rsa/itests/felix/rsa/TestRSAListener.java index 5c9374f4d..8a0c9f98a 100644 --- a/itests/felix/src/test/java/org/apache/aries/rsa/itests/felix/rsa/TestRSAListener.java +++ b/itests/felix/src/test/java/org/apache/aries/rsa/itests/felix/rsa/TestRSAListener.java @@ -19,12 +19,13 @@ */ -import static org.junit.Assert.*; +import static org.junit.Assert.assertEquals; import java.util.concurrent.TimeoutException; import javax.inject.Inject; +import org.apache.aries.rsa.examples.echotcp.api.EchoService; import org.apache.aries.rsa.itests.felix.RsaTestBase; import org.junit.Test; import org.junit.runner.RunWith; @@ -32,39 +33,44 @@ import org.ops4j.pax.exam.Option; import org.ops4j.pax.exam.junit.PaxExam; import org.osgi.framework.Bundle; -import org.osgi.framework.BundleContext; import org.osgi.framework.ServiceRegistration; +import org.osgi.service.remoteserviceadmin.RemoteServiceAdmin; import org.osgi.service.remoteserviceadmin.RemoteServiceAdminEvent; import org.osgi.service.remoteserviceadmin.RemoteServiceAdminListener; @RunWith(PaxExam.class) public class TestRSAListener extends RsaTestBase implements RemoteServiceAdminListener { - - @Inject - BundleContext context; - + private static final int EVENT_TIMEOUT = 2000; private RemoteServiceAdminEvent lastEvent; - - + private Bundle serviceBundle; + + @Inject + EchoService echoService; + + @Inject + RemoteServiceAdmin rsa; + @Configuration public static Option[] configure() throws Exception { - return new Option[] { - rsaCore(), - rsaFastBin(), - echoTcpService(), - configFastBin("2545"), + return new Option[] // + { + rsaCore(), // + rsaProviderFastBin(), // + echoTcpService(), // + configFastBinPort("2545"), }; } @Test public void testListener() throws Exception { - Bundle serviceBundle = getBundle("org.apache.aries.rsa.examples.echotcp.service"); - serviceBundle.stop(); - ServiceRegistration sreg = context.registerService(RemoteServiceAdminListener.class, this, null); + serviceBundle = getBundle("org.apache.aries.rsa.examples.echotcp.service"); + serviceBundle.stop(); + ServiceRegistration sreg = bundleContext.registerService(RemoteServiceAdminListener.class, this, null); + serviceBundle.start(); assertEvent(RemoteServiceAdminEvent.EXPORT_REGISTRATION); - + serviceBundle.stop(); assertEvent(RemoteServiceAdminEvent.EXPORT_UNREGISTRATION); @@ -73,37 +79,23 @@ public void testListener() throws Exception { @Override public synchronized void remoteAdminEvent(RemoteServiceAdminEvent event) { - lastEvent = event; - this.notifyAll(); + if (event.getExportReference() != null && serviceBundle == event.getExportReference().getExportedService().getBundle()) { + lastEvent = event; + this.notifyAll(); + } } private void assertEvent(int eventType) throws InterruptedException, TimeoutException { waitEvent(); assertEquals(eventType, lastEvent.getType()); - assertNotNull("ExportReference must be available",lastEvent.getExportReference()); this.lastEvent = null; } private synchronized void waitEvent() throws InterruptedException, TimeoutException { - long start = System.currentTimeMillis(); - while (this.lastEvent == null) { - this.wait(1000); - if (System.currentTimeMillis() - start > 2000) { - throw new TimeoutException("Timeout waiting for Event"); - } - } - } - - private Bundle getBundle(String symName) { - Bundle serviceBundle = null; - Bundle[] bundles = context.getBundles(); - for (Bundle bundle : bundles) { - if(symName.equals(bundle.getSymbolicName())) { - serviceBundle = bundle; - break; - } + this.wait(EVENT_TIMEOUT); + if (this.lastEvent == null) { + throw new TimeoutException("Timeout waiting for Event"); } - return serviceBundle; } } diff --git a/itests/felix/src/test/java/org/apache/aries/rsa/itests/felix/tcp/TestDiscoveryExport.java b/itests/felix/src/test/java/org/apache/aries/rsa/itests/felix/tcp/TestDiscoveryExport.java index 151d02ebf..218316e76 100644 --- a/itests/felix/src/test/java/org/apache/aries/rsa/itests/felix/tcp/TestDiscoveryExport.java +++ b/itests/felix/src/test/java/org/apache/aries/rsa/itests/felix/tcp/TestDiscoveryExport.java @@ -52,7 +52,7 @@ public static Option[] configure() throws Exception { return new Option[] { rsaCore(), rsaDiscoveryZookeeper(), - rsaTcp(), + rsaProviderTcp(), echoTcpService(), localRepo(), configZKDiscovery(), diff --git a/itests/felix/src/test/java/org/apache/aries/rsa/itests/felix/tcp/TestFindHook.java b/itests/felix/src/test/java/org/apache/aries/rsa/itests/felix/tcp/TestFindHook.java index f866f7b78..8d4ab9778 100644 --- a/itests/felix/src/test/java/org/apache/aries/rsa/itests/felix/tcp/TestFindHook.java +++ b/itests/felix/src/test/java/org/apache/aries/rsa/itests/felix/tcp/TestFindHook.java @@ -49,7 +49,7 @@ public static Option[] remoteConfig() throws IOException { return new Option[] { rsaCore(), rsaDiscoveryZookeeper(), - rsaTcp(), + rsaProviderTcp(), echoTcpService(), configZKServer(), configZKDiscovery(), @@ -61,7 +61,7 @@ public static Option[] configure() throws Exception { return new Option[] { rsaCore(), rsaDiscoveryZookeeper(), - rsaTcp(), + rsaProviderTcp(), echoTcpAPI(), configZKDiscovery() }; diff --git a/itests/felix/src/test/java/org/apache/aries/rsa/itests/felix/tcp/TestRoundTrip.java b/itests/felix/src/test/java/org/apache/aries/rsa/itests/felix/tcp/TestRoundTrip.java index 577d56bdb..2a038b8c5 100644 --- a/itests/felix/src/test/java/org/apache/aries/rsa/itests/felix/tcp/TestRoundTrip.java +++ b/itests/felix/src/test/java/org/apache/aries/rsa/itests/felix/tcp/TestRoundTrip.java @@ -45,7 +45,7 @@ public static Option[] remoteConfig() throws IOException { return new Option[] { rsaCore(), rsaDiscoveryZookeeper(), - rsaTcp(), + rsaProviderTcp(), echoTcpService(), configZKServer(), configZKDiscovery(), @@ -57,7 +57,7 @@ public static Option[] configure() throws Exception { return new Option[] { rsaCore(), rsaDiscoveryZookeeper(), - rsaTcp(), + rsaProviderTcp(), RsaTestBase.echoTcpConsumer(), configZKDiscovery() }; diff --git a/itests/pom.xml b/itests/pom.xml index 9799dd5dc..523114594 100644 --- a/itests/pom.xml +++ b/itests/pom.xml @@ -27,7 +27,6 @@ .. - 4.8.0 @@ -44,32 +43,32 @@ org.ops4j.pax.exam pax-exam-junit4 - ${pax-exam.version} + ${exam.version} org.ops4j.pax.exam pax-exam-cm - ${pax-exam.version} + ${exam.version} org.ops4j.pax.exam pax-exam-inject - ${pax-exam.version} + ${exam.version} org.ops4j.pax.exam pax-exam-container-forked - ${pax-exam.version} + ${exam.version} org.ops4j.pax.exam pax-exam-container-native - ${pax-exam.version} + ${exam.version} org.ops4j.pax.exam pax-exam-link-mvn - ${pax-exam.version} + ${exam.version} org.ops4j.pax.url diff --git a/parent/pom.xml b/parent/pom.xml index 818b2a6b3..83b7b55cf 100644 --- a/parent/pom.xml +++ b/parent/pom.xml @@ -27,13 +27,13 @@ UTF-8 1.9.0 true - 3.4.7 + 3.4.10 1.0.0 1.7.14 1.2.6 1.21 1.11 - 4.8.0 + 4.10.0 @@ -204,18 +204,16 @@ org.apache.felix maven-bundle-plugin - 3.0.1 + 3.3.0 true org.apache.maven.plugins maven-compiler-plugin - 3.5.1 + 3.6.1 1.8 1.8 - 256M - false diff --git a/provider/fastbin/src/main/java/org/apache/aries/rsa/provider/fastbin/util/ClassLoaderObjectInputStream.java b/provider/fastbin/src/main/java/org/apache/aries/rsa/provider/fastbin/util/ClassLoaderObjectInputStream.java index 674093831..f9a0bdc38 100644 --- a/provider/fastbin/src/main/java/org/apache/aries/rsa/provider/fastbin/util/ClassLoaderObjectInputStream.java +++ b/provider/fastbin/src/main/java/org/apache/aries/rsa/provider/fastbin/util/ClassLoaderObjectInputStream.java @@ -72,7 +72,7 @@ private Class load(String className) } else { try{ //try to load it with our own classloader (could be e.g. a service exception) - return Class.forName(className, false, this.getClassLoader()); + return Class.forName(className, false, getClass().getClassLoader()); } catch(ClassNotFoundException e2) { //ignore } diff --git a/rsa/src/main/java/org/apache/aries/rsa/core/RemoteServiceAdminCore.java b/rsa/src/main/java/org/apache/aries/rsa/core/RemoteServiceAdminCore.java index 321e6be64..e72582c15 100644 --- a/rsa/src/main/java/org/apache/aries/rsa/core/RemoteServiceAdminCore.java +++ b/rsa/src/main/java/org/apache/aries/rsa/core/RemoteServiceAdminCore.java @@ -202,7 +202,11 @@ private ExportRegistration exportService(List interfaceNames, try { Class[] interfaces = getInterfaces(interfaceNames, serviceReference.getBundle()); Map eprops = createEndpointProps(serviceProperties, interfaces); - BundleContext serviceContext = serviceReference.getBundle().getBundleContext(); + Bundle bundle = serviceReference.getBundle(); + if (bundle == null) { + throw new IllegalStateException("Service is already unregistered"); + } + BundleContext serviceContext = bundle.getBundleContext(); // TODO unget service when export is destroyed Object serviceO = serviceContext.getService(serviceReference); diff --git a/topology-manager/src/test/java/org/apache/aries/rsa/topologymanager/exporter/TopologyManagerExportTest.java b/topology-manager/src/test/java/org/apache/aries/rsa/topologymanager/exporter/TopologyManagerExportTest.java index 2d3b68f60..f0de808fc 100644 --- a/topology-manager/src/test/java/org/apache/aries/rsa/topologymanager/exporter/TopologyManagerExportTest.java +++ b/topology-manager/src/test/java/org/apache/aries/rsa/topologymanager/exporter/TopologyManagerExportTest.java @@ -186,16 +186,10 @@ private ServiceReference createUserService(IMocksControl c) { } private ServiceReference createUserService(IMocksControl c, Object exportedInterfaces) { - final ServiceReference sref = c.createMock(ServiceReference.class); + final ServiceReference sref = c.createMock(ServiceReference.class); EasyMock.expect(sref.getProperty(EasyMock.same(RemoteConstants.SERVICE_EXPORTED_INTERFACES))) .andReturn(exportedInterfaces).anyTimes(); Bundle srefBundle = c.createMock(Bundle.class); - BundleContext srefContext = c.createMock(BundleContext.class); - EasyMock.expect(srefBundle.getState()).andReturn(Bundle.ACTIVE).anyTimes(); - EasyMock.expect(srefBundle.getBundleContext()).andReturn(srefContext).anyTimes(); - Object serviceInstance = new Object(); - EasyMock.expect(srefContext.getService(sref)).andReturn(serviceInstance).anyTimes(); - EasyMock.expect(srefContext.ungetService(sref)).andReturn(true).anyTimes(); if(!"".equals(exportedInterfaces)) { EasyMock.expect(sref.getBundle()).andReturn(srefBundle).atLeastOnce(); EasyMock.expect(srefBundle.getSymbolicName()).andReturn("serviceBundleName").atLeastOnce();