You are viewing a plain text version of this content. The canonical link for it is here.
Posted to scm@geronimo.apache.org by ri...@apache.org on 2010/03/26 12:58:34 UTC
svn commit: r927784 - in /geronimo/specs/trunk/geronimo-osgi-support:
geronimo-osgi-itesta/
geronimo-osgi-locator/src/main/java/org/apache/geronimo/osgi/locator/
geronimo-osgi-registry-itests/
geronimo-osgi-registry-itests/src/test/java/org/apache/gero...
Author: rickmcguire
Date: Fri Mar 26 11:58:33 2010
New Revision: 927784
URL: http://svn.apache.org/viewvc?rev=927784&view=rev
Log:
Fix the ProviderLocator to not fail if the registry service is not started. Also fix unit tests, which were not fully running
Added:
geronimo/specs/trunk/geronimo-osgi-support/geronimo-osgi-registry-itests/src/test/java/org/apache/geronimo/osgi/registry/itest/OSGiNoRegistryTest.java (with props)
Modified:
geronimo/specs/trunk/geronimo-osgi-support/geronimo-osgi-itesta/pom.xml
geronimo/specs/trunk/geronimo-osgi-support/geronimo-osgi-locator/src/main/java/org/apache/geronimo/osgi/locator/ProviderLocator.java
geronimo/specs/trunk/geronimo-osgi-support/geronimo-osgi-registry-itests/pom.xml
geronimo/specs/trunk/geronimo-osgi-support/geronimo-osgi-registry-itests/src/test/java/org/apache/geronimo/osgi/registry/itest/OSGiLocatorTest.java
geronimo/specs/trunk/geronimo-osgi-support/geronimo-osgi-registry-itests/src/test/java/org/apache/geronimo/osgi/registry/itest/OSGiServiceLocatorTest.java
geronimo/specs/trunk/geronimo-osgi-support/geronimo-osgi-registry/src/main/java/org/apache/geronimo/osgi/registry/ProviderRegistryImpl.java
Modified: geronimo/specs/trunk/geronimo-osgi-support/geronimo-osgi-itesta/pom.xml
URL: http://svn.apache.org/viewvc/geronimo/specs/trunk/geronimo-osgi-support/geronimo-osgi-itesta/pom.xml?rev=927784&r1=927783&r2=927784&view=diff
==============================================================================
--- geronimo/specs/trunk/geronimo-osgi-support/geronimo-osgi-itesta/pom.xml (original)
+++ geronimo/specs/trunk/geronimo-osgi-support/geronimo-osgi-itesta/pom.xml Fri Mar 26 11:58:33 2010
@@ -53,10 +53,10 @@ provider resolution scenarios.
<Bundle-SymbolicName>${groupId}.${artifactId};singleton=true</Bundle-SymbolicName>
<Private-Package>org.apache.geronimo.osgi.testa</Private-Package>
<SPI-Provider>true</SPI-Provider>
- <Export-Provider>
- org.apache.geronimo.osgi.testa.TestTarget2,
- org.apache.geronimo.osgi.testa.NoClass
- </Export-Provider>
+ <Export-SPI-Provider>
+ org.apache.geronimo.osgi.itesta.TestTarget2,
+ org.apache.geronimo.osgi.itesta.NoClass
+ </Export-SPI-Provider>
</instructions>
</configuration>
</plugin>
Modified: geronimo/specs/trunk/geronimo-osgi-support/geronimo-osgi-locator/src/main/java/org/apache/geronimo/osgi/locator/ProviderLocator.java
URL: http://svn.apache.org/viewvc/geronimo/specs/trunk/geronimo-osgi-support/geronimo-osgi-locator/src/main/java/org/apache/geronimo/osgi/locator/ProviderLocator.java?rev=927784&r1=927783&r2=927784&view=diff
==============================================================================
--- geronimo/specs/trunk/geronimo-osgi-support/geronimo-osgi-locator/src/main/java/org/apache/geronimo/osgi/locator/ProviderLocator.java (original)
+++ geronimo/specs/trunk/geronimo-osgi-support/geronimo-osgi-locator/src/main/java/org/apache/geronimo/osgi/locator/ProviderLocator.java Fri Mar 26 11:58:33 2010
@@ -59,8 +59,9 @@ public class ProviderLocator {
try {
// just create a tracker for our lookup service
// NB: We use the hard coded name in case the registry service has not
- // been started first. Once this does get started, then everything should
- // resolved.
+ // been started first. The ServiceTracker itself only uses the string name.
+ // We need to avoid trying to load the ProviderRegistry interface until the
+ // registry tracker returns a non-null service instance.
registryTracker = new ServiceTracker(c, "org.apache.geronimo.osgi.registry.api.ProviderRegistry", null);
((ServiceTracker)registryTracker).open();
// do this last...it helps indicate if we have an initialized registry.
@@ -94,20 +95,17 @@ public class ProviderLocator {
* loaded.
*/
static public Class<?> locate(String providerId) {
- // if not initialized in an OSGi environment, this is a failure
- if (registryTracker == null) {
- return null;
- }
- // get the service, if it exists. NB: if the tracker exists, then we
- // were able to load the interface class in the first place, so we don't
- // need to protect against that.
- ProviderRegistry registry = (ProviderRegistry)((ServiceTracker)registryTracker).getService();
- // it is also a failure if the service is not there.
+ Object registry = getRegistry();
+ // if no registry service available, this is a failure
if (registry == null) {
return null;
}
+ // get the service, if it exists. NB, if there is a service object,
+ // then the extender and the interface class are available, so this cast should be
+ // safe now.
+
// the rest of the work is done by the registry
- return registry.locate(providerId);
+ return ((ProviderRegistry)registry).locate(providerId);
}
/**
@@ -120,20 +118,18 @@ public class ProviderLocator {
* matching classes can be located.
*/
static public List<Class<?>> locateAll(String providerId) {
- // if not initialized in an OSGi environment, this is a lookup failure
- if (registryTracker == null) {
- return new ArrayList<Class<?>>();
- }
- // get the service, if it exists. NB: if the tracker exists, then we
- // were able to load the interface class in the first place, so we don't
- // need to protect against that.
- ProviderRegistry registry = (ProviderRegistry)((ServiceTracker)registryTracker).getService();
- // it is also a failure if the service is not there.
+ Object registry = getRegistry();
+
+ // if no registry service available, this is a failure
if (registry == null) {
return new ArrayList<Class<?>>();
}
+ // get the service, if it exists. NB, if there is a service object,
+ // then the extender and the interface class are available, so this cast should be
+ // safe now.
+
// the rest of the work is done by the registry
- return registry.locateAll(providerId);
+ return ((ProviderRegistry)registry).locateAll(providerId);
}
/**
@@ -219,21 +215,19 @@ public class ProviderLocator {
// if we are working in an OSGi environment, then process the service
// registry first. Ideally, we would do this last, but because of boot delegation
// issues with some API implementations, we must try the OSGi version first
- if (registryTracker != null) {
- // get the service, if it exists. NB: if the tracker exists, then we
- // were able to load the interface class in the first place, so we don't
- // need to protect against that.
- ProviderRegistry registry = (ProviderRegistry)((ServiceTracker)registryTracker).getService();
- // if the service is not here, we fall through to the traditional method
- if (registry != null) {
- // the rest of the work is done by the registry
- Object service = registry.getService(iface);
- if (service != null) {
- return service;
- }
+ Object registry = getRegistry();
+ if (registry != null) {
+ // get the service, if it exists. NB, if there is a service object,
+ // then the extender and the interface class are available, so this cast should be
+ // safe now.
+ // the rest of the work is done by the registry
+ Object service = ((ProviderRegistry)registry).getService(iface);
+ if (service != null) {
+ return service;
}
}
- // try for a classpath locatable instance first. If we find an appropriate class mapping,
+
+ // try for a classpath locatable instance next. If we find an appropriate class mapping,
// create an instance and return it.
Class<?> cls = locateServiceClass(iface, contextClass, loader);
if (cls != null) {
@@ -263,18 +257,16 @@ public class ProviderLocator {
// if we are working in an OSGi environment, then process the service
// registry first. Ideally, we would do this last, but because of boot delegation
// issues with some API implementations, we must try the OSGi version first
- if (registryTracker != null) {
- // get the service, if it exists. NB: if the tracker exists, then we
- // were able to load the interface class in the first place, so we don't
- // need to protect against that.
- ProviderRegistry registry = (ProviderRegistry)((ServiceTracker)registryTracker).getService();
- // it is also a failure if the service is not there.
- if (registry != null) {
- // If we've located stuff in the registry, then return it
- Class<?> cls = registry.getServiceClass(iface);
- if (cls != null) {
- return cls;
- }
+ Object registry = getRegistry();
+ if (registry != null) {
+ // get the service, if it exists. NB, if there is a service object,
+ // then the extender and the interface class are available, so this cast should be
+ // safe now.
+
+ // If we've located stuff in the registry, then return it
+ Class<?> cls = ((ProviderRegistry)registry).getServiceClass(iface);
+ if (cls != null) {
+ return cls;
}
}
@@ -305,20 +297,16 @@ public class ProviderLocator {
// because of boot delegation issues with some of the API implementations, it is necessary
// to process the OSGi registered versions first to allow override of JRE provided APIs.
- // if not initialized in an OSGi environment, we're finished
- if (registryTracker != null) {
- // get the service, if it exists. NB: if the tracker exists, then we
- // were able to load the interface class in the first place, so we don't
- // need to protect against that.
- ProviderRegistry registry = (ProviderRegistry)((ServiceTracker)registryTracker).getService();
- // it is also the end if the service is not there.
- if (registry != null) {
- // get any registered service instances now
- List<Object> globalServices = registry.getServices(iface);
- // add to our list also
- if (globalServices != null) {
- services.addAll(globalServices);
- }
+ Object registry = getRegistry();
+ if (registry != null) {
+ // get the service, if it exists. NB, if there is a service object,
+ // then the extender and the interface class are available, so this cast should be
+ // safe now.
+ // get any registered service instances now
+ List<Object> globalServices = ((ProviderRegistry)registry).getServices(iface);
+ // add to our list also
+ if (globalServices != null) {
+ services.addAll(globalServices);
}
}
@@ -358,20 +346,16 @@ public class ProviderLocator {
// because of boot delegation issues with some of the API implementations, it is necessary
// to process the OSGi registered versions first to allow override of JRE provided APIs.
- // if not initialized in an OSGi environment, we're finished
- if (registryTracker != null) {
- // get the service, if it exists. NB: if the tracker exists, then we
- // were able to load the interface class in the first place, so we don't
- // need to protect against that.
- ProviderRegistry registry = (ProviderRegistry)((ServiceTracker)registryTracker).getService();
- // it is also the end if the service is not there.
- if (registry != null) {
- // get any registered service provider classes now
- List<Class<?>> globalServices = registry.getServiceClasses(iface);
- // add to our list also
- if (globalServices != null) {
- serviceClasses.addAll(globalServices);
- }
+ Object registry = getRegistry();
+ if (registry != null) {
+ // get the service, if it exists. NB, if there is a service object,
+ // then the extender and the interface class are available, so this cast should be
+ // safe now.
+ // get any registered service provider classes now
+ List<Class<?>> globalServices = ((ProviderRegistry)registry).getServiceClasses(iface);
+ // add to our list also
+ if (globalServices != null) {
+ serviceClasses.addAll(globalServices);
}
}
@@ -621,4 +605,26 @@ public class ProviderLocator {
}
return null;
}
+
+
+ /**
+ * Retrieve the registry from the tracker if it is available,
+ * all without causing the interface class to load.
+ *
+ * @return The registry service instance, or null if it is not
+ * available for any reason.
+ */
+ private static Object getRegistry() {
+ // if not initialized in an OSGi environment, this is a failure
+ if (registryTracker == null) {
+ return null;
+ }
+ // get the service, if it exists. NB: it is only safe to reference the
+ // interface class if the tracker returns a non-null service object. The
+ // interface class will not be loaded in our bundle context until the
+ // service class can be statisfied. Therefore, we always return this as
+ // just an object and the call needs to perform the cast, which will
+ // force the classload at that time.
+ return ((ServiceTracker)registryTracker).getService();
+ }
}
Modified: geronimo/specs/trunk/geronimo-osgi-support/geronimo-osgi-registry-itests/pom.xml
URL: http://svn.apache.org/viewvc/geronimo/specs/trunk/geronimo-osgi-support/geronimo-osgi-registry-itests/pom.xml?rev=927784&r1=927783&r2=927784&view=diff
==============================================================================
--- geronimo/specs/trunk/geronimo-osgi-support/geronimo-osgi-registry-itests/pom.xml (original)
+++ geronimo/specs/trunk/geronimo-osgi-support/geronimo-osgi-registry-itests/pom.xml Fri Mar 26 11:58:33 2010
@@ -152,6 +152,12 @@ Tests for the OSGi provider registry ins
<configuration>
<redirectTestOutputToFile>true</redirectTestOutputToFile>
<failIfNoTests>false</failIfNoTests>
+ <includes>
+ <include>**/OSGiLocatorTest.java</include>
+ <include>**/OSGiNoRegistryTest.java</include>
+ <include>**/OSGiLocatorMultipleProviderTest.java</include>
+ <include>**/OSGiServiceLocatorTest.java</include>
+ </includes>
</configuration>
</plugin>
</plugins>
Modified: geronimo/specs/trunk/geronimo-osgi-support/geronimo-osgi-registry-itests/src/test/java/org/apache/geronimo/osgi/registry/itest/OSGiLocatorTest.java
URL: http://svn.apache.org/viewvc/geronimo/specs/trunk/geronimo-osgi-support/geronimo-osgi-registry-itests/src/test/java/org/apache/geronimo/osgi/registry/itest/OSGiLocatorTest.java?rev=927784&r1=927783&r2=927784&view=diff
==============================================================================
--- geronimo/specs/trunk/geronimo-osgi-support/geronimo-osgi-registry-itests/src/test/java/org/apache/geronimo/osgi/registry/itest/OSGiLocatorTest.java (original)
+++ geronimo/specs/trunk/geronimo-osgi-support/geronimo-osgi-registry-itests/src/test/java/org/apache/geronimo/osgi/registry/itest/OSGiLocatorTest.java Fri Mar 26 11:58:33 2010
@@ -123,12 +123,12 @@ public class OSGiLocatorTest {
assertEquals("org.apache.geronimo.osgi.itesta.TestTargetTwo", targets.get(0).getName());
// this class is defined using the header form. It should map back to itself.
- target = ProviderLocator.locate("org.apache.geronimo.osgi.itesta..TestTarget2");
+ target = ProviderLocator.locate("org.apache.geronimo.osgi.itesta.TestTarget2");
assertNotNull(target);
// this should return the given class instance
assertEquals("org.apache.geronimo.osgi.itesta.TestTarget2", target.getName());
- targets = ProviderLocator.locateAll("org.apache.geronimo.osgi.itesta..TestTarget2");
+ targets = ProviderLocator.locateAll("org.apache.geronimo.osgi.itesta.TestTarget2");
// should return one entry and it should be the same class mapping
assertEquals(1, targets.size());
assertEquals("org.apache.geronimo.osgi.itesta.TestTarget2", targets.get(0).getName());
@@ -147,14 +147,12 @@ public class OSGiLocatorTest {
target = ProviderLocator.locate("org.apache.geronimo.osgi.itesta..NoClass");
assertNull(target);
- // Now test some of the class loading support. This will search the bundle classpath first,
- // then the provider registry. Since there is a matching local class this time, it should
- // find that test class rather than the registered one.
- // check for the target class a verify we got the correct one
+ // Now test some of the class loading support. This will search the provider registry first,
+ // then the classpath. We should still get the registered class returned.
target = ProviderLocator.loadClass("org.apache.geronimo.osgi.registry.itest.TestTarget", this.getClass());
assertNotNull(target);
// this should return the given class instance
- assertEquals(TestTarget.class.getName(), target.getName());
+ assertEquals("org.apache.geronimo.osgi.itesta.TestTarget", target.getName());
// similar to the above, but since the context class is not provided, this will fail to resolve the
// locally resident class.
target = ProviderLocator.loadClass("org.apache.geronimo.osgi.registry.itest.TestTarget", null);
@@ -162,6 +160,12 @@ public class OSGiLocatorTest {
// this should return the given class instance
assertEquals("org.apache.geronimo.osgi.itesta.TestTarget", target.getName());
+ // And just a straight load class of a bundle-local class.
+ target = ProviderLocator.loadClass("org.apache.geronimo.osgi.registry.itest.TestTargetTwo", this.getClass());
+ assertNotNull(target);
+ // this should return the given class instance
+ assertEquals("org.apache.geronimo.osgi.registry.itest.TestTargetTwo", target.getName());
+
// this one should be handled from the provider registry and resolve to a class
// defined in the test bundle.
target = ProviderLocator.loadClass("org.apache.geronimo.osgi.registry.itest.TestTarget4", this.getClass());
Added: geronimo/specs/trunk/geronimo-osgi-support/geronimo-osgi-registry-itests/src/test/java/org/apache/geronimo/osgi/registry/itest/OSGiNoRegistryTest.java
URL: http://svn.apache.org/viewvc/geronimo/specs/trunk/geronimo-osgi-support/geronimo-osgi-registry-itests/src/test/java/org/apache/geronimo/osgi/registry/itest/OSGiNoRegistryTest.java?rev=927784&view=auto
==============================================================================
--- geronimo/specs/trunk/geronimo-osgi-support/geronimo-osgi-registry-itests/src/test/java/org/apache/geronimo/osgi/registry/itest/OSGiNoRegistryTest.java (added)
+++ geronimo/specs/trunk/geronimo-osgi-support/geronimo-osgi-registry-itests/src/test/java/org/apache/geronimo/osgi/registry/itest/OSGiNoRegistryTest.java Fri Mar 26 11:58:33 2010
@@ -0,0 +1,165 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.geronimo.osgi.registry.itest;
+
+import java.io.File;
+import java.io.IOException;
+import java.io.InputStream;
+import java.util.List;
+
+import org.apache.geronimo.osgi.locator.Activator;
+import org.apache.geronimo.osgi.locator.ProviderLocator;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertNull;
+import static org.junit.Assert.assertSame;
+import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.fail;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.ops4j.pax.exam.CoreOptions;
+import static org.ops4j.pax.exam.CoreOptions.bundle;
+import static org.ops4j.pax.exam.CoreOptions.equinox;
+import static org.ops4j.pax.exam.CoreOptions.felix;
+import static org.ops4j.pax.exam.CoreOptions.options;
+import static org.ops4j.pax.exam.CoreOptions.provision;
+import static org.ops4j.pax.exam.CoreOptions.wrappedBundle;
+import org.ops4j.pax.exam.Customizer;
+import org.ops4j.pax.exam.Inject;
+import org.ops4j.pax.exam.Option;
+import static org.ops4j.pax.exam.OptionUtils.combine;
+import org.ops4j.pax.exam.junit.JUnit4TestRunner;
+import org.ops4j.pax.exam.options.MavenArtifactProvisionOption;
+import static org.ops4j.pax.swissbox.tinybundles.core.TinyBundles.*;
+import org.osgi.framework.Bundle;
+import org.osgi.framework.BundleContext;
+import org.osgi.framework.Constants;
+
+@RunWith(JUnit4TestRunner.class)
+public class OSGiNoRegistryTest {
+ @Inject
+ protected BundleContext bundleContext;
+
+ @org.ops4j.pax.exam.junit.Configuration
+ public static Option[] configuration() throws Exception {
+ Option[] options = options(
+ // NOTE: This test is supposed to test that the ProviderLocator
+ // does not raise exceptions if the provider registry is not
+ // available and the ProviderRegistry api class is not resolvable.
+// mavenBundle("org.apache.geronimo.specs", "geronimo-osgi-registry"),
+ // bundle containing test resources
+ mavenBundle("org.apache.geronimo.specs", "geronimo-osgi-itesta"),
+ mavenBundle("org.ops4j.pax.logging", "pax-logging-api"),
+ felix(),
+ equinox().version("3.5.0"),
+ // we want to specify an activator for the test probe bundle that
+ // is the standard one for adding the locator service to a spec
+ // bundle. We'll use our activator instance to perform class lookups
+ new Customizer()
+ {
+ @Override
+ public InputStream customizeTestProbe( InputStream testProbe )
+ throws IOException
+ {
+ return modifyBundle(testProbe)
+ // these two classes need to be in every participating bundle
+ .add(org.apache.geronimo.osgi.locator.Activator.class)
+ .add(org.apache.geronimo.osgi.locator.ProviderLocator.class)
+ // we don't have any direct references to this class, so force it to be
+ // included.
+ .add(org.apache.geronimo.osgi.registry.itest.TestTargetLocal.class)
+ // set the required activator also
+ .set(Constants.BUNDLE_ACTIVATOR, org.apache.geronimo.osgi.locator.Activator.class.getName())
+ // we need an import for activator to function properly...make sure the resolution
+ // is optional, which is the typical way of dealing with this
+ .set(Constants.IMPORT_PACKAGE, "org.apache.geronimo.osgi.registry.api;resolution:=optional")
+ .build();
+ }
+ }
+ );
+ options = updateOptions(options);
+ return options;
+ }
+
+
+ @Test
+ public void testLocator() throws Exception {
+ // Ok, just a few quick tests to make sure things fail gracefully.
+ Class<?> target = ProviderLocator.locate("org.apache.geronimo.osgi.registry.itest.TestTarget");
+ assertNull(target);
+
+ List<Class<?>> targets = ProviderLocator.locateAll("org.apache.geronimo.osgi.registry.itest.TestTarget");
+ // should return an empty list
+ assertNotNull(targets);
+ assertEquals(0, targets.size());
+
+ // this should not be located at all
+ try {
+ target = ProviderLocator.loadClass("org.apache.geronimo.osgi.registry.itest.ClassNotFound", this.getClass());
+ fail("Expected ClassNotFoundException not thrown");
+ } catch (ClassNotFoundException e) {
+ }
+
+ // now some service tests
+ Object service = ProviderLocator.getService("org.apache.geronimo.osgi.registry.itest.TestTarget", this.getClass(), Thread.currentThread().getContextClassLoader());
+ assertNull(service);
+
+ // now testing a multiple instances get. This should only pick up the definition from the
+ // bundle that includes the SPI-Provider header (testa)
+ List services = ProviderLocator.getServices("org.apache.geronimo.osgi.registry.itest.TestTarget", this.getClass(), Thread.currentThread().getContextClassLoader());
+ assertNotNull(services);
+ assertEquals(0, services.size());
+
+ // same set of tests, but this time we're looking for classes, not instances
+ target = ProviderLocator.getServiceClass("org.apache.geronimo.osgi.registry.itest.TestTarget", this.getClass(), Thread.currentThread().getContextClassLoader());
+ assertNull(target);
+
+ List<Class<?>> classes = ProviderLocator.getServiceClasses("org.apache.geronimo.osgi.registry.itest.TestTarget", this.getClass(), Thread.currentThread().getContextClassLoader());
+ assertNotNull(classes);
+ assertEquals(0, classes.size());
+ }
+
+ protected Bundle getInstalledBundle(String symbolicName) {
+ for (Bundle b : bundleContext.getBundles()) {
+ if (b.getSymbolicName().equals(symbolicName)) {
+ return b;
+ }
+ }
+ return null;
+ }
+
+ public static MavenArtifactProvisionOption mavenBundle(String groupId, String artifactId) {
+ return CoreOptions.mavenBundle().groupId(groupId).artifactId(artifactId).versionAsInProject();
+ }
+
+ protected static Option[] updateOptions(Option[] options) {
+ // We need to add pax-exam-junit here when running with the ibm
+ // jdk to avoid the following exception during the test run:
+ // ClassNotFoundException: org.ops4j.pax.exam.junit.Configuration
+ if ("IBM Corporation".equals(System.getProperty("java.vendor"))) {
+ Option[] ibmOptions = options(
+ wrappedBundle(mavenBundle("org.ops4j.pax.exam", "pax-exam-junit"))
+ );
+ options = combine(ibmOptions, options);
+ }
+
+ return options;
+ }
+}
Propchange: geronimo/specs/trunk/geronimo-osgi-support/geronimo-osgi-registry-itests/src/test/java/org/apache/geronimo/osgi/registry/itest/OSGiNoRegistryTest.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: geronimo/specs/trunk/geronimo-osgi-support/geronimo-osgi-registry-itests/src/test/java/org/apache/geronimo/osgi/registry/itest/OSGiNoRegistryTest.java
------------------------------------------------------------------------------
svn:keywords = Date Revision
Propchange: geronimo/specs/trunk/geronimo-osgi-support/geronimo-osgi-registry-itests/src/test/java/org/apache/geronimo/osgi/registry/itest/OSGiNoRegistryTest.java
------------------------------------------------------------------------------
svn:mime-type = text/plain
Modified: geronimo/specs/trunk/geronimo-osgi-support/geronimo-osgi-registry-itests/src/test/java/org/apache/geronimo/osgi/registry/itest/OSGiServiceLocatorTest.java
URL: http://svn.apache.org/viewvc/geronimo/specs/trunk/geronimo-osgi-support/geronimo-osgi-registry-itests/src/test/java/org/apache/geronimo/osgi/registry/itest/OSGiServiceLocatorTest.java?rev=927784&r1=927783&r2=927784&view=diff
==============================================================================
--- geronimo/specs/trunk/geronimo-osgi-support/geronimo-osgi-registry-itests/src/test/java/org/apache/geronimo/osgi/registry/itest/OSGiServiceLocatorTest.java (original)
+++ geronimo/specs/trunk/geronimo-osgi-support/geronimo-osgi-registry-itests/src/test/java/org/apache/geronimo/osgi/registry/itest/OSGiServiceLocatorTest.java Fri Mar 26 11:58:33 2010
@@ -151,12 +151,10 @@ public class OSGiServiceLocatorTest {
} catch (ClassNotFoundException e) {
}
- // as should this
- try {
- services = ProviderLocator.getServices("org.apache.geronimo.osgi.registry.itest.NoClass", this.getClass(), Thread.currentThread().getContextClassLoader());
- fail("Expected ClassNotFoundException not thrown");
- } catch (ClassNotFoundException e) {
- }
+ // this should return an empty list
+ services = ProviderLocator.getServices("org.apache.geronimo.osgi.registry.itest.NoClass", this.getClass(), Thread.currentThread().getContextClassLoader());
+ assertNotNull(services);
+ assertTrue(services.isEmpty());
// this should result in an exception
try {
@@ -165,12 +163,10 @@ public class OSGiServiceLocatorTest {
} catch (NullPointerException e) {
}
- // as should this
- try {
- services = ProviderLocator.getServices("org.apache.geronimo.osgi.registry.itest.BadClass", this.getClass(), Thread.currentThread().getContextClassLoader());
- fail("Expected Exception not thrown");
- } catch (NullPointerException e) {
- }
+ // but this should just give an empty list again
+ services = ProviderLocator.getServices("org.apache.geronimo.osgi.registry.itest.BadClass", this.getClass(), Thread.currentThread().getContextClassLoader());
+ assertNotNull(services);
+ assertTrue(services.isEmpty());
// this should result in an exception
try {
@@ -179,12 +175,10 @@ public class OSGiServiceLocatorTest {
} catch (InstantiationException e) {
}
- // as should this
- try {
- services = ProviderLocator.getServices("org.apache.geronimo.osgi.registry.itest.NoConstructor", this.getClass(), Thread.currentThread().getContextClassLoader());
- fail("Expected Exception not thrown");
- } catch (InstantiationException e) {
- }
+ // and again, an empty list
+ services = ProviderLocator.getServices("org.apache.geronimo.osgi.registry.itest.NoConstructor", this.getClass(), Thread.currentThread().getContextClassLoader());
+ assertNotNull(services);
+ assertTrue(services.isEmpty());
// this should result in an exception
try {
@@ -193,12 +187,10 @@ public class OSGiServiceLocatorTest {
} catch (IllegalAccessException e) {
}
- // as should this
- try {
- services = ProviderLocator.getServices("org.apache.geronimo.osgi.registry.itest.NoAccess", this.getClass(), Thread.currentThread().getContextClassLoader());
- fail("Expected Exception not thrown");
- } catch (IllegalAccessException e) {
- }
+ // empty list
+ services = ProviderLocator.getServices("org.apache.geronimo.osgi.registry.itest.NoAccess", this.getClass(), Thread.currentThread().getContextClassLoader());
+ assertNotNull(services);
+ assertTrue(services.isEmpty());
// same set of tests, but this time we're looking for classes, not instances
Class<?> target = ProviderLocator.getServiceClass("org.apache.geronimo.osgi.registry.itest.TestTarget", this.getClass(), Thread.currentThread().getContextClassLoader());
@@ -215,12 +207,12 @@ public class OSGiServiceLocatorTest {
assertEquals("org.apache.geronimo.osgi.itesta.TestTarget2", classes.get(0).getName());
// this is multiple instances defined in a single services file.
- classes = ProviderLocator.getServiceClasses("org.apache.geronimo.osgi.registry.itest.MultiTarget", this.getClass(), Thread.currentThread().getContextClassLoader());
+ classes = ProviderLocator.getServiceClasses("org.apache.geronimo.osgi.registry.itesta.MultiTarget", this.getClass(), Thread.currentThread().getContextClassLoader());
assertNotNull(classes);
assertEquals(2, classes.size());
// this should return an instance created from the services definition
- assertEquals("org.apache.geronimo.osgi.itestb.TestTarget", classes.get(0).getName());
- assertEquals("org.apache.geronimo.osgi.itestb.TestTarget2", classes.get(1).getName());
+ assertEquals("org.apache.geronimo.osgi.itesta.TestTarget", classes.get(0).getName());
+ assertEquals("org.apache.geronimo.osgi.itesta.TestTarget2", classes.get(1).getName());
// this should not be found
target = ProviderLocator.getServiceClass("org.apache.geronimo.osgi.registry.itest.NotFound", this.getClass(), Thread.currentThread().getContextClassLoader());
@@ -238,12 +230,10 @@ public class OSGiServiceLocatorTest {
} catch (ClassNotFoundException e) {
}
- // as should this
- try {
- classes = ProviderLocator.getServiceClasses("org.apache.geronimo.osgi.registry.itest.NoClass", this.getClass(), Thread.currentThread().getContextClassLoader());
- fail("Expected ClassNotFoundException not thrown");
- } catch (ClassNotFoundException e) {
- }
+ // an empty list again
+ classes = ProviderLocator.getServiceClasses("org.apache.geronimo.osgi.registry.itest.NoClass", this.getClass(), Thread.currentThread().getContextClassLoader());
+ assertNotNull(classes);
+ assertTrue(classes.isEmpty());
// now stop the first bundle, which should remove the service defintions.
bundle1.stop();
Modified: geronimo/specs/trunk/geronimo-osgi-support/geronimo-osgi-registry/src/main/java/org/apache/geronimo/osgi/registry/ProviderRegistryImpl.java
URL: http://svn.apache.org/viewvc/geronimo/specs/trunk/geronimo-osgi-support/geronimo-osgi-registry/src/main/java/org/apache/geronimo/osgi/registry/ProviderRegistryImpl.java?rev=927784&r1=927783&r2=927784&view=diff
==============================================================================
--- geronimo/specs/trunk/geronimo-osgi-support/geronimo-osgi-registry/src/main/java/org/apache/geronimo/osgi/registry/ProviderRegistryImpl.java (original)
+++ geronimo/specs/trunk/geronimo-osgi-support/geronimo-osgi-registry/src/main/java/org/apache/geronimo/osgi/registry/ProviderRegistryImpl.java Fri Mar 26 11:58:33 2010
@@ -156,6 +156,7 @@ public class ProviderRegistryImpl implem
// try to load this. We always return null
return loader.loadClass();
} catch (Exception e) {
+ e.printStackTrace();
// just swallow this and return null. The exception has already
// been logged.
}
@@ -336,7 +337,7 @@ public class ProviderRegistryImpl implem
List<BundleProviderLoader> directoryProviders = processDefinitions("OSGI-INF/providers/");
if (directoryProviders != null) {
- directoryProviders.addAll(directoryProviders);
+ locatedProviders.addAll(directoryProviders);
}
// if we have anything, add to global registry
if (!locatedProviders.isEmpty()) {
@@ -345,6 +346,8 @@ public class ProviderRegistryImpl implem
// add to the mapping table
registerProvider(loader);
}
+ // remember this list so we can unregister when the bundle is stopped
+ providers = new ArrayList(locatedProviders);
}
}