Return-Path: X-Original-To: apmail-aries-commits-archive@www.apache.org Delivered-To: apmail-aries-commits-archive@www.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id 9EB7B9A77 for ; Wed, 8 Feb 2012 22:27:07 +0000 (UTC) Received: (qmail 4199 invoked by uid 500); 8 Feb 2012 22:27:07 -0000 Delivered-To: apmail-aries-commits-archive@aries.apache.org Received: (qmail 4115 invoked by uid 500); 8 Feb 2012 22:27:06 -0000 Mailing-List: contact commits-help@aries.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@aries.apache.org Delivered-To: mailing list commits@aries.apache.org Received: (qmail 4107 invoked by uid 99); 8 Feb 2012 22:27:06 -0000 Received: from athena.apache.org (HELO athena.apache.org) (140.211.11.136) by apache.org (qpsmtpd/0.29) with ESMTP; Wed, 08 Feb 2012 22:27:06 +0000 X-ASF-Spam-Status: No, hits=-2000.0 required=5.0 tests=ALL_TRUSTED,T_FILL_THIS_FORM_SHORT X-Spam-Check-By: apache.org Received: from [140.211.11.4] (HELO eris.apache.org) (140.211.11.4) by apache.org (qpsmtpd/0.29) with ESMTP; Wed, 08 Feb 2012 22:27:04 +0000 Received: from eris.apache.org (localhost [127.0.0.1]) by eris.apache.org (Postfix) with ESMTP id 2B05C2388900; Wed, 8 Feb 2012 22:26:44 +0000 (UTC) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r1242146 - in /aries/trunk/subsystem: subsystem-core/src/main/java/org/apache/aries/subsystem/core/internal/ subsystem-itests/src/test/java/org/apache/aries/subsystem/itests/ subsystem-itests/src/test/resources/feature3/ Date: Wed, 08 Feb 2012 22:26:43 -0000 To: commits@aries.apache.org From: jwross@apache.org X-Mailer: svnmailer-1.0.8-patched Message-Id: <20120208222644.2B05C2388900@eris.apache.org> Author: jwross Date: Wed Feb 8 22:26:43 2012 New Revision: 1242146 URL: http://svn.apache.org/viewvc?rev=1242146&view=rev Log: ARIES-825: Update subsystems to latest Subsystem, Resolver, and Repository APIs. (1) Removed support for subsystem event admin events. (2) Added support for subsystem service events. (3) Updated tests for subsystem service events. (4) Started new RootSubsystemTest in conjunction with service events. Added: aries/trunk/subsystem/subsystem-core/src/main/java/org/apache/aries/subsystem/core/internal/SubsystemServiceRegistrar.java aries/trunk/subsystem/subsystem-itests/src/test/java/org/apache/aries/subsystem/itests/RootSubsystemTest.java Modified: aries/trunk/subsystem/subsystem-core/src/main/java/org/apache/aries/subsystem/core/internal/Activator.java aries/trunk/subsystem/subsystem-core/src/main/java/org/apache/aries/subsystem/core/internal/AriesSubsystem.java aries/trunk/subsystem/subsystem-itests/src/test/java/org/apache/aries/subsystem/itests/FeatureTest.java aries/trunk/subsystem/subsystem-itests/src/test/java/org/apache/aries/subsystem/itests/IntegrationTest.java aries/trunk/subsystem/subsystem-itests/src/test/java/org/apache/aries/subsystem/itests/SubsystemTest.java aries/trunk/subsystem/subsystem-itests/src/test/resources/feature3/tb3.jar Modified: aries/trunk/subsystem/subsystem-core/src/main/java/org/apache/aries/subsystem/core/internal/Activator.java URL: http://svn.apache.org/viewvc/aries/trunk/subsystem/subsystem-core/src/main/java/org/apache/aries/subsystem/core/internal/Activator.java?rev=1242146&r1=1242145&r2=1242146&view=diff ============================================================================== --- aries/trunk/subsystem/subsystem-core/src/main/java/org/apache/aries/subsystem/core/internal/Activator.java (original) +++ aries/trunk/subsystem/subsystem-core/src/main/java/org/apache/aries/subsystem/core/internal/Activator.java Wed Feb 8 22:26:43 2012 @@ -57,6 +57,8 @@ public class Activator implements Bundle private final List> registrations = new ArrayList>(); private BundleContext bundleContext; + private SubsystemServiceRegistrar registrar; + private AriesSubsystem root; private ServiceProviderImpl serviceProvider; public synchronized BundleContext getBundleContext() { @@ -72,6 +74,13 @@ public class Activator implements Bundle logger.debug(LOG_EXIT, "getServiceProvider", result); return result; } + + public synchronized SubsystemServiceRegistrar getSubsystemServiceRegistrar() { + logger.debug(LOG_ENTRY, "getSubsystemServiceRegistrar"); + SubsystemServiceRegistrar result = registrar; + logger.debug(LOG_EXIT, "getSubsystemServiceRegistrar", result); + return result; + } @Override public synchronized void start(final BundleContext context) throws Exception { @@ -86,15 +95,18 @@ public class Activator implements Bundle // TODO The registration of the Resolver service should be temporary, unless Felix // does not have an official release at the time. registrations.add(bundleContext.registerService(Resolver.class, new ResolverImpl(null), null)); - AriesSubsystem root = new AriesSubsystem(); - registrations.add(bundleContext.registerService(Subsystem.class.getName(), root, null)); + registrar = new SubsystemServiceRegistrar(bundleContext); + root = new AriesSubsystem(); root.install(); + root.start(); logger.debug(LOG_EXIT, "start"); } @Override public synchronized void stop(BundleContext context) /*throws Exception*/ { logger.debug(LOG_ENTRY, "stop", context); + root.stop(); + registrar.unregisterAll(); for (int i = registrations.size() - 1; i >= 0; i--) { try { registrations.get(i).unregister(); Modified: aries/trunk/subsystem/subsystem-core/src/main/java/org/apache/aries/subsystem/core/internal/AriesSubsystem.java URL: http://svn.apache.org/viewvc/aries/trunk/subsystem/subsystem-core/src/main/java/org/apache/aries/subsystem/core/internal/AriesSubsystem.java?rev=1242146&r1=1242145&r2=1242146&view=diff ============================================================================== --- aries/trunk/subsystem/subsystem-core/src/main/java/org/apache/aries/subsystem/core/internal/AriesSubsystem.java (original) +++ aries/trunk/subsystem/subsystem-core/src/main/java/org/apache/aries/subsystem/core/internal/AriesSubsystem.java Wed Feb 8 22:26:43 2012 @@ -212,20 +212,27 @@ public class AriesSubsystem implements S private final ArrayList parents = new ArrayList(); private final Region region; - private Subsystem.State state; + private Subsystem.State state = State.INSTALLING; public AriesSubsystem() throws Exception { // Create the root subsystem. LOGGER.debug(LOG_ENTRY, "init"); - id = 0; - location = ROOT_LOCATION; - region = createRegion(null); - setState(State.ACTIVE); - environment = new SubsystemEnvironment(this); // TODO The directory field is kept separate from the archive so that it can be referenced // by any embedded child subsystems during archive initialization. See the constructors. directory = Activator.getInstance().getBundleContext().getDataFile(""); archive = new SubsystemArchive(directory); + DataFile data = archive.getDataFile(); + if (data == null) { + id = 0; + location = ROOT_LOCATION; + region = createRegion(null); + } + else { + id = data.getSubsystemId(); + location = data.getLocation(); + region = createRegion(data.getRegionName()); + state = data.getState(); + } // TODO The creation of the subsystem manifest is in two places. See other constructor. SubsystemManifest manifest = archive.getSubsystemManifest(); if (manifest == null) { @@ -239,6 +246,7 @@ public class AriesSubsystem implements S // Need to generate a new subsystem manifest in order to generated a new deployment manifest based // on any persisted resources. manifest = SubsystemManifest.newInstance(getSymbolicName(), getVersion(), archive.getResources()); + environment = new SubsystemEnvironment(this); archive.setDeploymentManifest(DeploymentManifest.newInstance(manifest, environment)); StaticDataFile sdf = archive.getStaticDataFile(); LOGGER.debug("Data file: {}", sdf); @@ -476,14 +484,6 @@ public class AriesSubsystem implements S @Override public Version getVersion() { - if (archive == null) { - // If the archive is null, this is either the root subsystem or an installing subsystem not yet initialized. - if (State.INSTALLING.equals(getState())) - // The root subsystem's state will never be INSTALLING, so this is an uninitialized subsystem. - throw new IllegalStateException(); - // This is the root subsystem. - return ROOT_VERSION; - } return ((VersionHeader)archive.getSubsystemManifest().getSubsystemVersion()).getVersion(); } @@ -554,7 +554,6 @@ public class AriesSubsystem implements S */ @Override public synchronized void start() throws SubsystemException { - checkRoot(); State state = getState(); if (state == State.UNINSTALLING || state == State.UNINSTALLED) { throw new SubsystemException("Cannot stop from state " + state); @@ -615,7 +614,6 @@ public class AriesSubsystem implements S */ @Override public synchronized void stop() throws SubsystemException { - checkRoot(); if (getState() == State.UNINSTALLING || getState() == State.UNINSTALLED) { throw new SubsystemException("Cannot stop from state " + getState()); } @@ -689,6 +687,7 @@ public class AriesSubsystem implements S locationToSubsystem.remove(location); deleteFile(directory); setState(State.UNINSTALLED); + Activator.getInstance().getSubsystemServiceRegistrar().unregister(this); } void bundleChanged(BundleEvent event) { @@ -719,6 +718,7 @@ public class AriesSubsystem implements S } void install() throws Exception { + Activator.getInstance().getSubsystemServiceRegistrar().register(this); List contentResources = new ArrayList(); List transitiveDependencies = new ArrayList(); DeploymentManifest manifest = getDeploymentManifest(); @@ -767,6 +767,8 @@ public class AriesSubsystem implements S coordination.end(); } } + if (getState().equals(State.INSTALLING)) + setState(State.INSTALLED); } protected boolean contains(Resource resource) { @@ -784,8 +786,6 @@ public class AriesSubsystem implements S } protected synchronized void setState(Subsystem.State state) { - // TODO Need to update service registration properties so that a - // ServiceEvent goes out with the updated state. this.state = state; // The archive will be null if this is the root subsystem. if (archive != null) { @@ -800,6 +800,7 @@ public class AriesSubsystem implements S } } } + Activator.getInstance().getSubsystemServiceRegistrar().update(this); notifyAll(); } @@ -928,7 +929,6 @@ public class AriesSubsystem implements S subsystem = new AriesSubsystem(archive, this); locationToSubsystem.put(subsystem.getLocation(), subsystem); } - subsystem.setState(State.INSTALLING); Set subsystems = new HashSet(); subsystems.add(this); resourceToSubsystems.put(subsystem, subsystems); @@ -937,7 +937,7 @@ public class AriesSubsystem implements S subsystem.install(); coordination.addParticipant(new Participant() { public void ended(Coordination coordination) throws Exception { - subsystem.setState(State.INSTALLED); + // noop } public void failed(Coordination coordination) throws Exception { Added: aries/trunk/subsystem/subsystem-core/src/main/java/org/apache/aries/subsystem/core/internal/SubsystemServiceRegistrar.java URL: http://svn.apache.org/viewvc/aries/trunk/subsystem/subsystem-core/src/main/java/org/apache/aries/subsystem/core/internal/SubsystemServiceRegistrar.java?rev=1242146&view=auto ============================================================================== --- aries/trunk/subsystem/subsystem-core/src/main/java/org/apache/aries/subsystem/core/internal/SubsystemServiceRegistrar.java (added) +++ aries/trunk/subsystem/subsystem-core/src/main/java/org/apache/aries/subsystem/core/internal/SubsystemServiceRegistrar.java Wed Feb 8 22:26:43 2012 @@ -0,0 +1,64 @@ +package org.apache.aries.subsystem.core.internal; + +import java.util.Dictionary; +import java.util.HashMap; +import java.util.Hashtable; +import java.util.Iterator; +import java.util.Map; + +import org.osgi.framework.BundleContext; +import org.osgi.framework.ServiceRegistration; +import org.osgi.service.subsystem.Subsystem; +import org.osgi.service.subsystem.SubsystemConstants; + +public class SubsystemServiceRegistrar { + private final BundleContext context; + private final Map> map = new HashMap>(); + + public SubsystemServiceRegistrar(BundleContext context) { + if (context == null) + throw new NullPointerException("Missing required parameter: context"); + this.context = context; + } + + public synchronized void register(Subsystem subsystem) { + if (map.containsKey(subsystem)) + throw new IllegalArgumentException("Subsystem '" + subsystem + "' already has service registration '" + map.get(subsystem) + "'"); + Dictionary properties = properties(subsystem); + ServiceRegistration registration = context.registerService(Subsystem.class, subsystem, properties); + map.put(subsystem, registration); + } + + public synchronized void unregister(Subsystem subsystem) { + ServiceRegistration registration = map.remove(subsystem); + if (registration == null) + throw new IllegalArgumentException("Subsystem '" + subsystem + "' is not registered"); + registration.unregister(); + } + + public synchronized void unregisterAll() { + for (Iterator> i = map.values().iterator(); i.hasNext();) { + ServiceRegistration registration = i.next(); + registration.unregister(); + i.remove(); + } + } + + public synchronized void update(Subsystem subsystem) { + ServiceRegistration registration = map.get(subsystem); + if (registration == null) + throw new IllegalArgumentException("Subsystem '" + subsystem + "' is not registered"); + Dictionary properties = properties(subsystem); + registration.setProperties(properties); + } + + private Dictionary properties(Subsystem subsystem) { + Dictionary properties = new Hashtable(); + properties.put(SubsystemConstants.SUBSYSTEM_ID_PROPERTY, subsystem.getSubsystemId()); + properties.put(SubsystemConstants.SUBSYSTEM_SYMBOLICNAME_PROPERTY, subsystem.getSymbolicName()); + properties.put(SubsystemConstants.SUBSYSTEM_VERSION_PROPERTY, subsystem.getVersion()); + properties.put(SubsystemConstants.SUBSYSTEM_TYPE_PROPERTY, subsystem.getType()); + properties.put(SubsystemConstants.SUBSYSTEM_STATE_PROPERTY, subsystem.getState()); + return properties; + } +} Modified: aries/trunk/subsystem/subsystem-itests/src/test/java/org/apache/aries/subsystem/itests/FeatureTest.java URL: http://svn.apache.org/viewvc/aries/trunk/subsystem/subsystem-itests/src/test/java/org/apache/aries/subsystem/itests/FeatureTest.java?rev=1242146&r1=1242145&r2=1242146&view=diff ============================================================================== --- aries/trunk/subsystem/subsystem-itests/src/test/java/org/apache/aries/subsystem/itests/FeatureTest.java (original) +++ aries/trunk/subsystem/subsystem-itests/src/test/java/org/apache/aries/subsystem/itests/FeatureTest.java Wed Feb 8 22:26:43 2012 @@ -89,25 +89,22 @@ public class FeatureTest extends Subsyst assertConstituents(5, feature1); assertChildren(1, feature1); feature2 = feature1.getChildren().iterator().next(); -// assertEvent(feature2, Subsystem.State.INSTALLING, 5000); -// assertEvent(feature2, Subsystem.State.INSTALLED, 5000); + assertEvent(feature2, Subsystem.State.INSTALLING, 5000); + assertEvent(feature2, Subsystem.State.INSTALLED, 5000); assertSymbolicName("org.apache.aries.subsystem.feature2", feature2); assertVersion("1.0.0", feature2); assertConstituent(feature2, "org.apache.aries.subsystem.itests.tb2", Version.parseVersion("2.0.0"), ResourceConstants.IDENTITY_TYPE_BUNDLE); assertConstituent(feature2, "org.apache.aries.subsystem.itests.tb3", Version.parseVersion("1.0.0"), ResourceConstants.IDENTITY_TYPE_BUNDLE); assertConstituents(2, feature2); assertChildren(0, feature2); - // TODO Test internal events for installation. startSubsystem(feature1); -// assertEvent(feature2, Subsystem.State.RESOLVING, 5000); -// assertEvent(feature2, Subsystem.State.RESOLVED, 5000); -// assertEvent(feature2, Subsystem.State.STARTING, 5000); -// assertEvent(feature2, Subsystem.State.ACTIVE, 5000); - // TODO Test internal events for starting. + assertEvent(feature2, Subsystem.State.RESOLVING, 5000); + assertEvent(feature2, Subsystem.State.RESOLVED, 5000); + assertEvent(feature2, Subsystem.State.STARTING, 5000); + assertEvent(feature2, Subsystem.State.ACTIVE, 5000); stopSubsystem(feature1); -// assertEvent(feature2, Subsystem.State.STOPPING, 5000); -// assertEvent(feature2, Subsystem.State.RESOLVED, 5000); - // TODO Test internal events for stopping. + assertEvent(feature2, Subsystem.State.STOPPING, 5000); + assertEvent(feature2, Subsystem.State.RESOLVED, 5000); } catch (AssertionError e) { error = e; @@ -117,9 +114,8 @@ public class FeatureTest extends Subsyst try { uninstallSubsystem(feature1); if (feature2 != null) { -// assertEvent(feature2, Subsystem.State.UNINSTALLING, 5000); -// assertEvent(feature2, Subsystem.State.UNINSTALLED, 5000); - // TODO Test internal events for uninstalling. + assertEvent(feature2, Subsystem.State.UNINSTALLING, 5000); + assertEvent(feature2, Subsystem.State.UNINSTALLED, 5000); assertNotChild(feature1, feature2); } } @@ -151,7 +147,6 @@ public class FeatureTest extends Subsyst feature3After = root.getChildren().iterator().next(); assertLastId(2); assertFeature3(feature3After); - assertEquals(feature3Before, feature3After); } catch (AssertionError e) { error = e; @@ -159,8 +154,10 @@ public class FeatureTest extends Subsyst } finally { try { - if (feature3After != null) + if (feature3After != null) { + stopSubsystem(feature3After); uninstallSubsystem(feature3After); + } } catch (AssertionError e) { if (error == null) Modified: aries/trunk/subsystem/subsystem-itests/src/test/java/org/apache/aries/subsystem/itests/IntegrationTest.java URL: http://svn.apache.org/viewvc/aries/trunk/subsystem/subsystem-itests/src/test/java/org/apache/aries/subsystem/itests/IntegrationTest.java?rev=1242146&r1=1242145&r2=1242146&view=diff ============================================================================== --- aries/trunk/subsystem/subsystem-itests/src/test/java/org/apache/aries/subsystem/itests/IntegrationTest.java (original) +++ aries/trunk/subsystem/subsystem-itests/src/test/java/org/apache/aries/subsystem/itests/IntegrationTest.java Wed Feb 8 22:26:43 2012 @@ -116,7 +116,7 @@ public abstract class IntegrationTest { } protected Bundle installBundle(String groupId, String artifactId) throws Exception { - MavenArtifactProvisionOption mvnUrl = mavenBundle(groupId, artifactId); + MavenArtifactProvisionOption mvnUrl = mavenBundleInTest(groupId, artifactId); return bundleContext.installBundle(mvnUrl.getURL()); } @@ -204,13 +204,7 @@ public abstract class IntegrationTest { } protected Bundle findBundleBySymbolicName(String symbolicName) { - Bundle result = null; - for (Bundle bundle : bundleContext.getBundles()) { - if (bundle.getSymbolicName().equals(symbolicName)) { - result = bundle; - break; - } - } + Bundle result = getInstalledBundle(symbolicName); assertNotNull("Unable to find bundle with symbolic name: " + symbolicName, result); return result; } Added: aries/trunk/subsystem/subsystem-itests/src/test/java/org/apache/aries/subsystem/itests/RootSubsystemTest.java URL: http://svn.apache.org/viewvc/aries/trunk/subsystem/subsystem-itests/src/test/java/org/apache/aries/subsystem/itests/RootSubsystemTest.java?rev=1242146&view=auto ============================================================================== --- aries/trunk/subsystem/subsystem-itests/src/test/java/org/apache/aries/subsystem/itests/RootSubsystemTest.java (added) +++ aries/trunk/subsystem/subsystem-itests/src/test/java/org/apache/aries/subsystem/itests/RootSubsystemTest.java Wed Feb 8 22:26:43 2012 @@ -0,0 +1,73 @@ +package org.apache.aries.subsystem.itests; + +import static org.junit.Assert.assertEquals; + +import org.junit.Test; +import org.junit.runner.RunWith; +import org.ops4j.pax.exam.junit.JUnit4TestRunner; +import org.osgi.framework.Bundle; +import org.osgi.framework.ServiceEvent; +import org.osgi.framework.Version; +import org.osgi.service.subsystem.Subsystem; + +@RunWith(JUnit4TestRunner.class) +public class RootSubsystemTest extends SubsystemTest { + // TODO Test root subsystem headers. + + @Test + public void testId() { + assertEquals("Wrong root ID", getRootSubsystem().getSubsystemId(), 0); + } + + @Test + public void testLocation() { + assertEquals("Wrong root location", getRootSubsystem().getLocation(), "subsystem://?Subsystem-SymbolicName=org.osgi.service.subsystem.root&Subsystem-Version=1.0.0"); + } + + @Test + public void testServiceEventsFresh() throws Exception { + Subsystem root = getRootSubsystem(); + Bundle core = getSubsystemCoreBundle(); + core.stop(); + assertEvent(root, Subsystem.State.STOPPING, subsystemEvents.poll(root.getSubsystemId(), 5000)); + assertEvent(root, Subsystem.State.RESOLVED, subsystemEvents.poll(root.getSubsystemId(), 5000)); + // Don't forget about the unregistering event, which will have the same state as before. + assertEvent(root, Subsystem.State.RESOLVED, subsystemEvents.poll(root.getSubsystemId(), 5000), ServiceEvent.UNREGISTERING); + core.uninstall(); + core = installBundle("org.apache.aries.subsystem", "org.apache.aries.subsystem.core"); + core.start(); + // When starting for the very first time, the root subsystem should transition through all states. + assertEvent(root, Subsystem.State.INSTALLING, subsystemEvents.poll(root.getSubsystemId(), 5000)); + assertEvent(root, Subsystem.State.INSTALLED, subsystemEvents.poll(root.getSubsystemId(), 5000)); + assertEvent(root, Subsystem.State.RESOLVING, subsystemEvents.poll(root.getSubsystemId(), 5000)); + assertEvent(root, Subsystem.State.RESOLVED, subsystemEvents.poll(root.getSubsystemId(), 5000)); + assertEvent(root, Subsystem.State.STARTING, subsystemEvents.poll(root.getSubsystemId(), 5000)); + assertEvent(root, Subsystem.State.ACTIVE, subsystemEvents.poll(root.getSubsystemId(), 5000)); + } + + @Test + public void testServiceEventsPersisted() throws Exception { + Subsystem root = getRootSubsystem(); + Bundle core = getSubsystemCoreBundle(); + core.stop(); + assertEvent(root, Subsystem.State.STOPPING, subsystemEvents.poll(root.getSubsystemId(), 5000)); + assertEvent(root, Subsystem.State.RESOLVED, subsystemEvents.poll(root.getSubsystemId(), 5000)); + // Don't forget about the unregistering event, which will have the same state as before. + assertEvent(root, Subsystem.State.RESOLVED, subsystemEvents.poll(root.getSubsystemId(), 5000), ServiceEvent.UNREGISTERING); + core.start(); + // On subsequent, post-installation starts, the root subsystem should start in the resolved state. + assertEvent(root, Subsystem.State.RESOLVED, subsystemEvents.poll(root.getSubsystemId(), 5000), ServiceEvent.REGISTERED); + assertEvent(root, Subsystem.State.STARTING, subsystemEvents.poll(root.getSubsystemId(), 5000)); + assertEvent(root, Subsystem.State.ACTIVE, subsystemEvents.poll(root.getSubsystemId(), 5000)); + } + + @Test + public void testSymbolicName() { + assertEquals("Wrong root symbolic name", getRootSubsystem().getSymbolicName(), "org.osgi.service.subsystem.root"); + } + + @Test + public void testVersion() { + assertEquals("Wrong root version", getRootSubsystem().getVersion(), Version.parseVersion("1.0.0")); + } +} Modified: aries/trunk/subsystem/subsystem-itests/src/test/java/org/apache/aries/subsystem/itests/SubsystemTest.java URL: http://svn.apache.org/viewvc/aries/trunk/subsystem/subsystem-itests/src/test/java/org/apache/aries/subsystem/itests/SubsystemTest.java?rev=1242146&r1=1242145&r2=1242146&view=diff ============================================================================== --- aries/trunk/subsystem/subsystem-itests/src/test/java/org/apache/aries/subsystem/itests/SubsystemTest.java (original) +++ aries/trunk/subsystem/subsystem-itests/src/test/java/org/apache/aries/subsystem/itests/SubsystemTest.java Wed Feb 8 22:26:43 2012 @@ -57,7 +57,49 @@ import org.osgi.service.subsystem.Subsys public abstract class SubsystemTest extends IntegrationTest { protected static class SubsystemEventHandler implements ServiceListener { - private final Map> subsystemIdToEvents = new HashMap>(); + private static class ServiceEventInfo { + private final ServiceEvent event; + private final long id; + private final State state; + private final String symbolicName; + private final String type; + private final Version version; + + public ServiceEventInfo(ServiceEvent event) { + id = (Long)event.getServiceReference().getProperty(SubsystemConstants.SUBSYSTEM_ID_PROPERTY); + state = (State)event.getServiceReference().getProperty(SubsystemConstants.SUBSYSTEM_STATE_PROPERTY); + symbolicName = (String)event.getServiceReference().getProperty(SubsystemConstants.SUBSYSTEM_SYMBOLICNAME_PROPERTY); + type = (String)event.getServiceReference().getProperty(SubsystemConstants.SUBSYSTEM_TYPE_PROPERTY); + version = (Version)event.getServiceReference().getProperty(SubsystemConstants.SUBSYSTEM_VERSION_PROPERTY); + this.event = event; + } + + public int getEventType() { + return event.getType(); + } + + public long getId() { + return id; + } + + public State getState() { + return state; + } + + public String getSymbolicName() { + return symbolicName; + } + + public String getType() { + return type; + } + + public Version getVersion() { + return version; + } + } + + private final Map> subsystemIdToEvents = new HashMap>(); public void clear() { synchronized (subsystemIdToEvents) { @@ -65,16 +107,16 @@ public abstract class SubsystemTest exte } } - public ServiceEvent poll(long subsystemId) throws InterruptedException { + public ServiceEventInfo poll(long subsystemId) throws InterruptedException { return poll(subsystemId, 0); } - public ServiceEvent poll(long subsystemId, long timeout) throws InterruptedException { - List events; + public ServiceEventInfo poll(long subsystemId, long timeout) throws InterruptedException { + List events; synchronized (subsystemIdToEvents) { events = subsystemIdToEvents.get(subsystemId); if (events == null) { - events = new ArrayList(); + events = new ArrayList(); subsystemIdToEvents.put(subsystemId, events); } } @@ -92,13 +134,13 @@ public abstract class SubsystemTest exte public void serviceChanged(ServiceEvent event) { Long subsystemId = (Long)event.getServiceReference().getProperty(SubsystemConstants.SUBSYSTEM_ID_PROPERTY); synchronized (subsystemIdToEvents) { - List events = subsystemIdToEvents.get(subsystemId); + List events = subsystemIdToEvents.get(subsystemId); if (events == null) { - events = new ArrayList(); + events = new ArrayList(); subsystemIdToEvents.put(subsystemId, events); } synchronized (events) { - events.add(event); + events.add(new ServiceEventInfo(event)); events.notify(); } } @@ -153,7 +195,7 @@ public abstract class SubsystemTest exte new RepositoryGenerator(bundleContext).generateOBR(); serviceRegistrations.add(bundleContext.registerService(Repository.class, new RepositoryAdminRepository(getOsgiService(RepositoryAdmin.class)), null)); try { - bundleContext.addServiceListener(subsystemEvents, '(' + Constants.OBJECTCLASS + '=' + Subsystem.class + ')'); + bundleContext.getBundle(0).getBundleContext().addServiceListener(subsystemEvents, '(' + Constants.OBJECTCLASS + '=' + Subsystem.class.getName() + ')'); } catch (InvalidSyntaxException e) { fail("Invalid filter: " + e.getMessage()); @@ -214,22 +256,29 @@ public abstract class SubsystemTest exte assertFalse("Subsystem data file exists", file.exists()); } -// protected void assertEvent(Subsystem subsystem, Subsystem.State state) throws InterruptedException { -// assertEvent(subsystem, state, 0); -// } -// -// protected void assertEvent(Subsystem subsystem, Subsystem.State state, long timeout) throws InterruptedException { -// assertEvent(subsystem, state, subsystemEvents.poll(subsystem.getSubsystemId(), timeout)); -// } -// -// protected void assertEvent(Subsystem subsystem, Subsystem.State state, ServiceEvent event) { -// // TODO Could accept a ServiceRegistration as an argument and verify it against the one in the event. -// assertEquals("Wrong ID", subsystem.getSubsystemId(), event.getServiceReference().getProperty(SubsystemConstants.SUBSYSTEM_ID_PROPERTY)); -// assertEquals("Wrong symbolic name", subsystem.getSymbolicName(), event.getServiceReference().getProperty(SubsystemConstants.SUBSYSTEM_SYMBOLICNAME_PROPERTY)); -// assertEquals("Wrong version", String.valueOf(subsystem.getVersion()), event.getServiceReference().getProperty(SubsystemConstants.SUBSYSTEM_VERSION_PROPERTY)); -// assertEquals("Wrong type", subsystem.getType(), event.getServiceReference().getProperty(SubsystemConstants.SUBSYSTEM_TYPE_PROPERTY)); -// assertEquals("Wrong state", String.valueOf(state), event.getServiceReference().getProperty(SubsystemConstants.SUBSYSTEM_STATE_PROPERTY)); -// } + protected void assertEvent(Subsystem subsystem, Subsystem.State state) throws InterruptedException { + assertEvent(subsystem, state, 0); + } + + protected void assertEvent(Subsystem subsystem, Subsystem.State state, long timeout) throws InterruptedException { + assertEvent(subsystem, state, subsystemEvents.poll(subsystem.getSubsystemId(), timeout)); + } + protected void assertEvent(Subsystem subsystem, Subsystem.State state, SubsystemEventHandler.ServiceEventInfo event) { + if (State.INSTALLING.equals(state)) + assertEvent(subsystem, state, event, ServiceEvent.REGISTERED); + else + assertEvent(subsystem, state, event, ServiceEvent.MODIFIED); + } + + protected void assertEvent(Subsystem subsystem, Subsystem.State state, SubsystemEventHandler.ServiceEventInfo event, int type) { + // TODO Could accept a ServiceRegistration as an argument and verify it against the one in the event. + assertEquals("Wrong ID", subsystem.getSubsystemId(), event.getId()); + assertEquals("Wrong symbolic name", subsystem.getSymbolicName(), event.getSymbolicName()); + assertEquals("Wrong version", subsystem.getVersion(), event.getVersion()); + assertEquals("Wrong type", subsystem.getType(), event.getType()); + assertEquals("Wrong state", state, event.getState()); + assertEquals("Wrong event type", type, event.getEventType()); + } protected void assertId(Subsystem subsystem) { assertId(subsystem.getSubsystemId()); @@ -289,24 +338,23 @@ public abstract class SubsystemTest exte Subsystem subsystem = rootSubsystem.install(file.toURI().toURL().toExternalForm()); assertNotNull("The subsystem was null", subsystem); assertState(EnumSet.of(State.INSTALLING, State.INSTALLED), subsystem.getState()); -// assertEvent(subsystem, Subsystem.State.INSTALLING, subsystemEvents.poll(subsystem.getSubsystemId(), 5000)); -// assertEvent(subsystem, Subsystem.State.INSTALLED, subsystemEvents.poll(subsystem.getSubsystemId(), 5000)); + assertEvent(subsystem, Subsystem.State.INSTALLING, subsystemEvents.poll(subsystem.getSubsystemId(), 5000)); + assertEvent(subsystem, Subsystem.State.INSTALLED, subsystemEvents.poll(subsystem.getSubsystemId(), 5000)); assertChild(rootSubsystem, subsystem); subsystem.start(); assertState(EnumSet.of(State.RESOLVING, State.RESOLVED, State.STARTING, State.ACTIVE), subsystem.getState()); -// assertEvent(subsystem, Subsystem.State.RESOLVING, subsystemEvents.poll(subsystem.getSubsystemId(), 5000)); -// assertEvent(subsystem, Subsystem.State.RESOLVED, subsystemEvents.poll(subsystem.getSubsystemId(), 5000)); -// assertEvent(subsystem, Subsystem.State.STARTING, subsystemEvents.poll(subsystem.getSubsystemId(), 5000)); -// assertEvent(subsystem, Subsystem.State.ACTIVE, subsystemEvents.poll(subsystem.getSubsystemId(), 5000)); + assertEvent(subsystem, Subsystem.State.RESOLVING, subsystemEvents.poll(subsystem.getSubsystemId(), 5000)); + assertEvent(subsystem, Subsystem.State.RESOLVED, subsystemEvents.poll(subsystem.getSubsystemId(), 5000)); + assertEvent(subsystem, Subsystem.State.STARTING, subsystemEvents.poll(subsystem.getSubsystemId(), 5000)); + assertEvent(subsystem, Subsystem.State.ACTIVE, subsystemEvents.poll(subsystem.getSubsystemId(), 5000)); subsystem.stop(); assertState(EnumSet.of(State.STOPPING, State.RESOLVED), subsystem.getState()); -// assertEvent(subsystem, Subsystem.State.STOPPING, subsystemEvents.poll(subsystem.getSubsystemId(), 5000)); -// assertEvent(subsystem, Subsystem.State.RESOLVED, subsystemEvents.poll(subsystem.getSubsystemId(), 5000)); - // TODO Add update. + assertEvent(subsystem, Subsystem.State.STOPPING, subsystemEvents.poll(subsystem.getSubsystemId(), 5000)); + assertEvent(subsystem, Subsystem.State.RESOLVED, subsystemEvents.poll(subsystem.getSubsystemId(), 5000)); subsystem.uninstall(); assertState(EnumSet.of(State.UNINSTALLING, State.UNINSTALLED), subsystem.getState()); -// assertEvent(subsystem, Subsystem.State.UNINSTALLING, subsystemEvents.poll(subsystem.getSubsystemId(), 5000)); -// assertEvent(subsystem, Subsystem.State.UNINSTALLED, subsystemEvents.poll(subsystem.getSubsystemId(), 5000)); + assertEvent(subsystem, Subsystem.State.UNINSTALLING, subsystemEvents.poll(subsystem.getSubsystemId(), 5000)); + assertEvent(subsystem, Subsystem.State.UNINSTALLED, subsystemEvents.poll(subsystem.getSubsystemId(), 5000)); assertNotChild(rootSubsystem, subsystem); return subsystem; } @@ -371,8 +419,8 @@ public abstract class SubsystemTest exte subsystemEvents.clear(); Subsystem subsystem = getRootSubsystem().install(location, content); assertSubsystemNotNull(subsystem); -// assertEvent(subsystem, Subsystem.State.INSTALLING, subsystemEvents.poll(subsystem.getSubsystemId(), 5000)); -// assertEvent(subsystem, Subsystem.State.INSTALLED, subsystemEvents.poll(subsystem.getSubsystemId(), 5000)); + assertEvent(subsystem, Subsystem.State.INSTALLING, subsystemEvents.poll(subsystem.getSubsystemId(), 5000)); + assertEvent(subsystem, Subsystem.State.INSTALLED, subsystemEvents.poll(subsystem.getSubsystemId(), 5000)); assertChild(parent, subsystem); assertLocation(location, subsystem); assertParent(parent, subsystem); @@ -389,10 +437,10 @@ public abstract class SubsystemTest exte subsystemEvents.clear(); subsystem.start(); assertState(EnumSet.of(State.RESOLVING, State.RESOLVED, State.STARTING, State.ACTIVE), subsystem); -// assertEvent(subsystem, Subsystem.State.RESOLVING, subsystemEvents.poll(subsystem.getSubsystemId(), 5000)); -// assertEvent(subsystem, Subsystem.State.RESOLVED, subsystemEvents.poll(subsystem.getSubsystemId(), 5000)); -// assertEvent(subsystem, Subsystem.State.STARTING, subsystemEvents.poll(subsystem.getSubsystemId(), 5000)); -// assertEvent(subsystem, Subsystem.State.ACTIVE, subsystemEvents.poll(subsystem.getSubsystemId(), 5000)); + assertEvent(subsystem, Subsystem.State.RESOLVING, subsystemEvents.poll(subsystem.getSubsystemId(), 5000)); + assertEvent(subsystem, Subsystem.State.RESOLVED, subsystemEvents.poll(subsystem.getSubsystemId(), 5000)); + assertEvent(subsystem, Subsystem.State.STARTING, subsystemEvents.poll(subsystem.getSubsystemId(), 5000)); + assertEvent(subsystem, Subsystem.State.ACTIVE, subsystemEvents.poll(subsystem.getSubsystemId(), 5000)); assertState(State.ACTIVE, subsystem); } @@ -401,8 +449,8 @@ public abstract class SubsystemTest exte subsystemEvents.clear(); subsystem.stop(); assertState(EnumSet.of(State.STOPPING, State.RESOLVED), subsystem); -// assertEvent(subsystem, Subsystem.State.STOPPING, subsystemEvents.poll(subsystem.getSubsystemId(), 5000)); -// assertEvent(subsystem, Subsystem.State.RESOLVED, subsystemEvents.poll(subsystem.getSubsystemId(), 5000)); + assertEvent(subsystem, Subsystem.State.STOPPING, subsystemEvents.poll(subsystem.getSubsystemId(), 5000)); + assertEvent(subsystem, Subsystem.State.RESOLVED, subsystemEvents.poll(subsystem.getSubsystemId(), 5000)); assertState(State.RESOLVED, subsystem); } @@ -412,8 +460,8 @@ public abstract class SubsystemTest exte Collection parents = subsystem.getParents(); subsystem.uninstall(); assertState(EnumSet.of(State.UNINSTALLED, State.UNINSTALLING), subsystem); -// assertEvent(subsystem, Subsystem.State.UNINSTALLING, subsystemEvents.poll(subsystem.getSubsystemId(), 5000)); -// assertEvent(subsystem, Subsystem.State.UNINSTALLED, subsystemEvents.poll(subsystem.getSubsystemId(), 5000)); + assertEvent(subsystem, Subsystem.State.UNINSTALLING, subsystemEvents.poll(subsystem.getSubsystemId(), 5000)); + assertEvent(subsystem, Subsystem.State.UNINSTALLED, subsystemEvents.poll(subsystem.getSubsystemId(), 5000)); assertState(State.UNINSTALLED, subsystem); assertConstituents(0, subsystem); for (Subsystem parent : parents) Modified: aries/trunk/subsystem/subsystem-itests/src/test/resources/feature3/tb3.jar URL: http://svn.apache.org/viewvc/aries/trunk/subsystem/subsystem-itests/src/test/resources/feature3/tb3.jar?rev=1242146&r1=1242145&r2=1242146&view=diff ============================================================================== Binary files - no diff available.