aries-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jwr...@apache.org
Subject svn commit: r1399940 - 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/
Date Fri, 19 Oct 2012 01:15:53 GMT
Author: jwross
Date: Fri Oct 19 01:15:52 2012
New Revision: 1399940

URL: http://svn.apache.org/viewvc?rev=1399940&view=rev
Log:
ARIES-941, ARIES-943: Root subsystem region selection and region cleanup.

The root subsystem is now associated with the region in which the subsystems implementation
bundle is installed. Previously, it
was always associated with the kernel region.

Regions are now properly removed when a subsystem is uninstalled.

New tests were added for both issues.

Modified:
    aries/trunk/subsystem/subsystem-core/src/main/java/org/apache/aries/subsystem/core/internal/SubsystemResource.java
    aries/trunk/subsystem/subsystem-core/src/main/java/org/apache/aries/subsystem/core/internal/SubsystemResourceUninstaller.java
    aries/trunk/subsystem/subsystem-core/src/main/java/org/apache/aries/subsystem/core/internal/Subsystems.java
    aries/trunk/subsystem/subsystem-itests/src/test/java/org/apache/aries/subsystem/itests/RootSubsystemTest.java
    aries/trunk/subsystem/subsystem-itests/src/test/java/org/apache/aries/subsystem/itests/SubsystemTest.java

Modified: aries/trunk/subsystem/subsystem-core/src/main/java/org/apache/aries/subsystem/core/internal/SubsystemResource.java
URL: http://svn.apache.org/viewvc/aries/trunk/subsystem/subsystem-core/src/main/java/org/apache/aries/subsystem/core/internal/SubsystemResource.java?rev=1399940&r1=1399939&r2=1399940&view=diff
==============================================================================
--- aries/trunk/subsystem/subsystem-core/src/main/java/org/apache/aries/subsystem/core/internal/SubsystemResource.java
(original)
+++ aries/trunk/subsystem/subsystem-core/src/main/java/org/apache/aries/subsystem/core/internal/SubsystemResource.java
Fri Oct 19 01:15:52 2012
@@ -453,7 +453,9 @@ public class SubsystemResource implement
 		Activator activator = Activator.getInstance();
 		RegionDigraph digraph = activator.getRegionDigraph();
 		if (getParents().isEmpty())
-			return digraph.getRegion(AriesSubsystem.ROOT_REGION);
+			// This is the root subsystem. Associate it with the region in which
+			// the subsystems implementation bundle was installed.
+			return digraph.getRegion(activator.getBundleContext().getBundle());
 		String name = getSubsystemManifest()
 				.getSubsystemSymbolicNameHeader().getSymbolicName()
 				+ ';'

Modified: aries/trunk/subsystem/subsystem-core/src/main/java/org/apache/aries/subsystem/core/internal/SubsystemResourceUninstaller.java
URL: http://svn.apache.org/viewvc/aries/trunk/subsystem/subsystem-core/src/main/java/org/apache/aries/subsystem/core/internal/SubsystemResourceUninstaller.java?rev=1399940&r1=1399939&r2=1399940&view=diff
==============================================================================
--- aries/trunk/subsystem/subsystem-core/src/main/java/org/apache/aries/subsystem/core/internal/SubsystemResourceUninstaller.java
(original)
+++ aries/trunk/subsystem/subsystem-core/src/main/java/org/apache/aries/subsystem/core/internal/SubsystemResourceUninstaller.java
Fri Oct 19 01:15:52 2012
@@ -99,10 +99,12 @@ public class SubsystemResourceUninstalle
 				}
 			}
 			subsystem.setState(State.UNINSTALLED);
-			Activator.getInstance().getSubsystemServiceRegistrar()
-					.unregister(subsystem);
-			if (subsystem.isScoped())
+			Activator activator = Activator.getInstance();
+			activator.getSubsystemServiceRegistrar().unregister(subsystem);
+			if (subsystem.isScoped()) {
 				RegionContextBundleHelper.uninstallRegionContextBundle(subsystem);
+				activator.getRegionDigraph().removeRegion(subsystem.getRegion());
+			}
 			if (firstError != null)
 				throw new SubsystemException(firstError);
 		}

Modified: aries/trunk/subsystem/subsystem-core/src/main/java/org/apache/aries/subsystem/core/internal/Subsystems.java
URL: http://svn.apache.org/viewvc/aries/trunk/subsystem/subsystem-core/src/main/java/org/apache/aries/subsystem/core/internal/Subsystems.java?rev=1399940&r1=1399939&r2=1399940&view=diff
==============================================================================
--- aries/trunk/subsystem/subsystem-core/src/main/java/org/apache/aries/subsystem/core/internal/Subsystems.java
(original)
+++ aries/trunk/subsystem/subsystem-core/src/main/java/org/apache/aries/subsystem/core/internal/Subsystems.java
Fri Oct 19 01:15:52 2012
@@ -208,7 +208,11 @@ public class Subsystems {
 	public void removeConstituent(AriesSubsystem subsystem, Resource constituent) {
 		synchronized (subsystemToConstituents) {
 			Set<Resource> constituents = subsystemToConstituents.get(subsystem);
-			constituents.remove(constituent);
+			if (constituents != null) {
+				constituents.remove(constituent);
+				if (constituents.isEmpty())
+					subsystemToConstituents.remove(subsystem);
+			}
 		}
 		subsystem.removedContent(constituent);
 	}

Modified: 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=1399940&r1=1399939&r2=1399940&view=diff
==============================================================================
--- aries/trunk/subsystem/subsystem-itests/src/test/java/org/apache/aries/subsystem/itests/RootSubsystemTest.java
(original)
+++ aries/trunk/subsystem/subsystem-itests/src/test/java/org/apache/aries/subsystem/itests/RootSubsystemTest.java
Fri Oct 19 01:15:52 2012
@@ -19,6 +19,9 @@ import static org.junit.Assert.fail;
 import java.io.File;
 import java.io.IOException;
 
+import org.eclipse.equinox.region.Region;
+import org.eclipse.equinox.region.RegionDigraph;
+import org.eclipse.equinox.region.RegionFilter;
 import org.junit.Before;
 import org.junit.Test;
 import org.junit.runner.RunWith;
@@ -140,4 +143,45 @@ public class RootSubsystemTest extends S
 	public void testVersion() {
 		assertEquals("Wrong root version", getRootSubsystem().getVersion(), Version.parseVersion("1.0.0"));
 	}
+	
+	/*
+	 * The root subsystem should be associated with the region in which the
+	 * subsystems implementation bundle is installed.
+	 */
+	@Test
+	public void testRegion() throws Exception {
+		RegionDigraph digraph = getOsgiService(RegionDigraph.class);
+		Bundle core = getSubsystemCoreBundle();
+		Region kernel = digraph.getRegion(core);
+		Subsystem root = getRootSubsystem();
+		Bundle rootRegionContext = root.getBundleContext().getBundle();
+		// Get the region containing the subsystem's region context bundle, 
+		// which is the same thing as getting the region with which the 
+		// subsystem is associated.
+		Region region = digraph.getRegion(root.getBundleContext().getBundle());
+		assertEquals("Wrong region", kernel, region);
+		// Uninstall the core bundle to remove the persisted root subsystem.
+		core.uninstall();
+		// Clean up the lingering region context bundle.
+		rootRegionContext.uninstall();
+		// Create a new region and install the core bundle into it.
+		Region user = digraph.createRegion("user");
+		// Allow everything from the kernel region into the user region so the 
+		// core bundle will resolve.
+		user.connectRegion(
+				kernel, 
+				digraph.createRegionFilterBuilder().allowAll(RegionFilter.VISIBLE_ALL_NAMESPACE).build());
+		// Allow everything from the user region into the kernel region so the
+		// root subsystem service can be found.
+		kernel.connectRegion(
+				user, 
+				digraph.createRegionFilterBuilder().allowAll(RegionFilter.VISIBLE_ALL_NAMESPACE).build());
+		core = user.installBundle(normalizeBundleLocation(core.getLocation()));
+		user = digraph.getRegion(core);
+		core.start();
+		root = getRootSubsystem();
+		region = digraph.getRegion(root.getBundleContext().getBundle());
+		// The root subsystem should now be in the new region.
+		assertEquals("Wrong region", user, region);
+	}
 }

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=1399940&r1=1399939&r2=1399940&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
Fri Oct 19 01:15:52 2012
@@ -50,6 +50,8 @@ import org.apache.aries.unittest.fixture
 import org.apache.aries.unittest.fixture.ArchiveFixture.JarFixture;
 import org.apache.aries.unittest.fixture.ArchiveFixture.ManifestFixture;
 import org.apache.aries.unittest.fixture.ArchiveFixture.ZipFixture;
+import org.eclipse.equinox.region.Region;
+import org.eclipse.equinox.region.RegionDigraph;
 import org.ops4j.pax.exam.Option;
 import org.ops4j.pax.exam.container.def.PaxRunnerOptions;
 import org.osgi.framework.Bundle;
@@ -196,7 +198,7 @@ public abstract class SubsystemTest exte
 				mavenBundle("org.eclipse.equinox",          "org.eclipse.equinox.event").version("1.2.200.v20120522-2049"),
 				mavenBundle("org.eclipse.equinox",          "org.eclipse.equinox.region").version("1.1.0.v20120522-1841"),
 				mavenBundle("org.osgi",                     "org.osgi.enterprise").version("5.0.0"),
-        //org.ops4j.pax.exam.container.def.PaxRunnerOptions.vmOption("-Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=7777"),
+//				org.ops4j.pax.exam.container.def.PaxRunnerOptions.vmOption("-Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=7777"),
 				PaxRunnerOptions.rawPaxRunnerOption("config", "classpath:ss-runner.properties"),
 				equinox().version("3.8.0.V20120529-1548"));
 		options = updateOptions(options);
@@ -763,9 +765,13 @@ public abstract class SubsystemTest exte
 		subsystemEvents.clear();
 		Collection<Subsystem> parents = subsystem.getParents();
 		Bundle b = null;
+		Region region = null;
+		RegionDigraph digraph = getOsgiService(RegionDigraph.class);
 		if (subsystem.getType().equals(SubsystemConstants.SUBSYSTEM_TYPE_APPLICATION)
-				|| subsystem.getType().equals(SubsystemConstants.SUBSYSTEM_TYPE_COMPOSITE))
+				|| subsystem.getType().equals(SubsystemConstants.SUBSYSTEM_TYPE_COMPOSITE)) {
 			b = getRegionContextBundle(subsystem);
+			region = digraph.getRegion(b);
+		}
 		State state = subsystem.getState();
 		subsystem.uninstall();
 		if (!EnumSet.of(State.INSTALL_FAILED, State.INSTALLED, State.INSTALLING).contains(state))
@@ -776,8 +782,11 @@ public abstract class SubsystemTest exte
 		for (Subsystem parent : parents)
 			assertNotChild(parent, subsystem);
 //		assertNotDirectory(subsystem);
-		if (b != null)
+		if (subsystem.getType().equals(SubsystemConstants.SUBSYSTEM_TYPE_APPLICATION)
+				|| subsystem.getType().equals(SubsystemConstants.SUBSYSTEM_TYPE_COMPOSITE)) {
 			assertEquals("Region context bundle not uninstalled", Bundle.UNINSTALLED, b.getState());
+			assertNull("Region not removed", digraph.getRegion(region.getName()));
+		}
 	}
 	
 	protected void uninstallSubsystemSilently(Subsystem subsystem) {
@@ -834,4 +843,10 @@ public abstract class SubsystemTest exte
 			Utils.closeQuietly(fos);
 		}
 	}
+	
+	protected static String normalizeBundleLocation(String location) {
+		if (location.startsWith("initial@"))
+			return location.substring(8);
+		return location;
+	}
 }



Mime
View raw message