You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@aries.apache.org by jw...@apache.org on 2014/01/07 21:55:18 UTC

svn commit: r1556354 - 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/

Author: jwross
Date: Tue Jan  7 20:55:18 2014
New Revision: 1556354

URL: http://svn.apache.org/r1556354
Log:
[ARIES-1144] Shared dependencies are uninstalled while still referenced.

New test.

Fix minor issue in existing tests regarding asserting bundle states.

When computing a subsystem's dependencies, the provider of each wire returned by the resolver will be inspected in addition
to the resources that were resolved in order to avoid omitting resources that were already resolved.

Added:
    aries/trunk/subsystem/subsystem-itests/src/test/java/org/apache/aries/subsystem/itests/SharedResourceTest.java   (with props)
Modified:
    aries/trunk/subsystem/subsystem-core/src/main/java/org/apache/aries/subsystem/core/internal/SubsystemResource.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=1556354&r1=1556353&r2=1556354&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 Tue Jan  7 20:55:18 2014
@@ -408,9 +408,18 @@ public class SubsystemResource implement
 		SubsystemContentHeader contentHeader = manifest.getSubsystemContentHeader();
 		try {
 			Map<Resource, List<Wire>> resolution = Activator.getInstance().getResolver().resolve(createResolveContext());
-			for (Resource resource : resolution.keySet())
-				if (!contentHeader.contains(resource))
-					addDependency(resource);
+			for (Map.Entry<Resource, List<Wire>> entry : resolution.entrySet()) {
+				Resource key = entry.getKey();
+				if (!contentHeader.contains(key)) {
+					addDependency(key);
+				}
+				for (Wire wire : entry.getValue()) {
+					Resource provider = wire.getProvider();
+					if (!contentHeader.contains(provider)) {
+						addDependency(provider);
+					}
+				}
+			}
 		}
 		catch (ResolutionException e) {
 			throw new SubsystemException(e);

Added: aries/trunk/subsystem/subsystem-itests/src/test/java/org/apache/aries/subsystem/itests/SharedResourceTest.java
URL: http://svn.apache.org/viewvc/aries/trunk/subsystem/subsystem-itests/src/test/java/org/apache/aries/subsystem/itests/SharedResourceTest.java?rev=1556354&view=auto
==============================================================================
--- aries/trunk/subsystem/subsystem-itests/src/test/java/org/apache/aries/subsystem/itests/SharedResourceTest.java (added)
+++ aries/trunk/subsystem/subsystem-itests/src/test/java/org/apache/aries/subsystem/itests/SharedResourceTest.java Tue Jan  7 20:55:18 2014
@@ -0,0 +1,139 @@
+/*
+ * Licensed 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.aries.subsystem.itests;
+
+import java.io.IOException;
+import java.util.HashMap;
+import java.util.Map;
+
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.ops4j.pax.exam.junit.MavenConfiguredJUnit4TestRunner;
+import org.osgi.framework.Bundle;
+import org.osgi.service.subsystem.Subsystem;
+import org.osgi.service.subsystem.SubsystemConstants;
+
+import aQute.lib.osgi.Constants;
+
+@RunWith(MavenConfiguredJUnit4TestRunner.class)
+public class SharedResourceTest extends SubsystemTest {
+	/*
+	 * Subsystem-SymbolicName: application.a.esa
+	 * Subsystem-Content: bundle.a.jar
+	 */
+	private static final String APPLICATION_A = "application.a.esa";
+	/*
+	 * Subsystem-SymbolicName: application.b.esa
+	 * Subsystem-Content: bundle.b.jar
+	 */
+	private static final String APPLICATION_B = "application.b.esa";
+	/*
+	 * Bundle-SymbolicName: bundle.a.jar
+	 * Import-Package: x
+	 */
+	private static final String BUNDLE_A = "bundle.a.jar";
+	/*
+	 * Bundle-SymbolicName: bundle.b.jar
+	 * Import-Package: x
+	 */
+	private static final String BUNDLE_B = "bundle.b.jar";
+	/*
+	 * Bundle-SymbolicName: bundle.c.jar
+	 * Export-Package: x
+	 */
+	private static final String BUNDLE_C = "bundle.c.jar";
+
+	
+	private static void createApplicationA() throws IOException {
+		createApplicationAManifest();
+		createSubsystem(APPLICATION_A, BUNDLE_A);
+	}
+	
+	private static void createApplicationAManifest() throws IOException {
+		Map<String, String> attributes = new HashMap<String, String>();
+		attributes.put(SubsystemConstants.SUBSYSTEM_SYMBOLICNAME, APPLICATION_A);
+		attributes.put(SubsystemConstants.SUBSYSTEM_CONTENT, BUNDLE_A);
+		createManifest(APPLICATION_A + ".mf", attributes);
+	}
+	
+	private static void createApplicationB() throws IOException {
+		createApplicationBManifest();
+		createSubsystem(APPLICATION_B, BUNDLE_B);
+	}
+	
+	private static void createApplicationBManifest() throws IOException {
+		Map<String, String> attributes = new HashMap<String, String>();
+		attributes.put(SubsystemConstants.SUBSYSTEM_SYMBOLICNAME, APPLICATION_B);
+		attributes.put(SubsystemConstants.SUBSYSTEM_CONTENT, BUNDLE_B);
+		createManifest(APPLICATION_B + ".mf", attributes);
+	}
+	
+	private static void createBundleA() throws IOException {
+		Map<String, String> headers = new HashMap<String, String>();
+		headers.put(Constants.IMPORT_PACKAGE, "x");
+		createBundle(BUNDLE_A, headers);
+	}
+	
+	private static void createBundleB() throws IOException {
+		Map<String, String> headers = new HashMap<String, String>();
+		headers.put(Constants.IMPORT_PACKAGE, "x");
+		createBundle(BUNDLE_B, headers);
+	}
+	
+	private static void createBundleC() throws IOException {
+		Map<String, String> headers = new HashMap<String, String>();
+		headers.put(Constants.EXPORT_PACKAGE, "x");
+		createBundle(BUNDLE_C, headers);
+	}
+	
+	private static boolean createdTestFiles;
+	@Before
+	public static void createTestFiles() throws Exception {
+		if (createdTestFiles)
+			return;
+		createBundleA();
+		createBundleB();
+		createBundleC();
+		createApplicationA();
+		createApplicationB();
+		createdTestFiles = true;
+	}
+	
+	public void setUp() throws Exception {
+		super.setUp();
+		registerRepositoryService(BUNDLE_C);
+	}
+	
+	@Test
+	public void testSharedBundleNotUninstalledWhileStillReferenced() throws Exception {
+		Subsystem applicationA = installSubsystemFromFile(APPLICATION_A);
+		try {
+			startSubsystem(applicationA);
+			Subsystem applicationB = installSubsystemFromFile(APPLICATION_B);
+			try {
+				startSubsystem(applicationB);
+				stopSubsystem(applicationA);
+				uninstallSubsystem(applicationA);
+				assertBundleState(Bundle.ACTIVE, BUNDLE_C, getRootSubsystem());
+			}
+			finally {
+				stopAndUninstallSubsystemSilently(applicationB);
+			}
+		}
+		finally {
+			stopAndUninstallSubsystemSilently(applicationA);
+		}
+	}
+}

Propchange: aries/trunk/subsystem/subsystem-itests/src/test/java/org/apache/aries/subsystem/itests/SharedResourceTest.java
------------------------------------------------------------------------------
    svn:executable = *

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=1556354&r1=1556353&r2=1556354&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 Tue Jan  7 20:55:18 2014
@@ -253,11 +253,11 @@ public abstract class SubsystemTest exte
 	
 	protected void assertBundleState(int state, String symbolicName, Subsystem subsystem) {
     	Bundle bundle = getBundle(subsystem, symbolicName);
+    	assertNotNull("Bundle not found: " + symbolicName, bundle);
     	assertBundleState(bundle, state);
     }
 	
 	protected void assertBundleState(Bundle bundle, int state) {
-		assertNotNull("Bundle not found: " + bundle, bundle);
 		assertTrue("Wrong state: " + bundle + " [expected " + state + " but was " + bundle.getState() + "]", (bundle.getState() & state) != 0);
 	}