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 2012/11/20 16:39:07 UTC
svn commit: r1411703 - 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 Nov 20 15:39:06 2012
New Revision: 1411703
URL: http://svn.apache.org/viewvc?rev=1411703&view=rev
Log:
[ARIES-966] The region context bundle should have the start level set explicitly to 1.
The start level of the region context bundle is now explicit set to 1 after installing it.
Created a more robust bundle start level test and moved it from InstallTest to BundleStartLevelTest.
Added:
aries/trunk/subsystem/subsystem-itests/src/test/java/org/apache/aries/subsystem/itests/BundleStartLevelTest.java
Modified:
aries/trunk/subsystem/subsystem-core/src/main/java/org/apache/aries/subsystem/core/internal/RegionContextBundleHelper.java
aries/trunk/subsystem/subsystem-itests/src/test/java/org/apache/aries/subsystem/itests/InstallTest.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/RegionContextBundleHelper.java
URL: http://svn.apache.org/viewvc/aries/trunk/subsystem/subsystem-core/src/main/java/org/apache/aries/subsystem/core/internal/RegionContextBundleHelper.java?rev=1411703&r1=1411702&r2=1411703&view=diff
==============================================================================
--- aries/trunk/subsystem/subsystem-core/src/main/java/org/apache/aries/subsystem/core/internal/RegionContextBundleHelper.java (original)
+++ aries/trunk/subsystem/subsystem-core/src/main/java/org/apache/aries/subsystem/core/internal/RegionContextBundleHelper.java Tue Nov 20 15:39:06 2012
@@ -24,6 +24,7 @@ import java.util.jar.Manifest;
import org.osgi.framework.Bundle;
import org.osgi.framework.BundleException;
import org.osgi.framework.Version;
+import org.osgi.framework.startlevel.BundleStartLevel;
import org.osgi.framework.wiring.BundleRevision;
public class RegionContextBundleHelper {
@@ -37,6 +38,9 @@ public class RegionContextBundleHelper {
if (b == null) {
ThreadLocalSubsystem.set(subsystem);
b = subsystem.getRegion().installBundleAtLocation(location, createRegionContextBundle(symbolicName));
+ // The start level of all managed bundles, including the region
+ // context bundle, should be 1.
+ b.adapt(BundleStartLevel.class).setStartLevel(1);
}
Utils.installResource(b.adapt(BundleRevision.class), subsystem);
// The region context bundle must be started persistently.
Added: aries/trunk/subsystem/subsystem-itests/src/test/java/org/apache/aries/subsystem/itests/BundleStartLevelTest.java
URL: http://svn.apache.org/viewvc/aries/trunk/subsystem/subsystem-itests/src/test/java/org/apache/aries/subsystem/itests/BundleStartLevelTest.java?rev=1411703&view=auto
==============================================================================
--- aries/trunk/subsystem/subsystem-itests/src/test/java/org/apache/aries/subsystem/itests/BundleStartLevelTest.java (added)
+++ aries/trunk/subsystem/subsystem-itests/src/test/java/org/apache/aries/subsystem/itests/BundleStartLevelTest.java Tue Nov 20 15:39:06 2012
@@ -0,0 +1,149 @@
+/*
+ * 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.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 BundleStartLevelTest extends SubsystemTest {
+ /*
+ * Subsystem-SymbolicName: application.a.esa
+ * Subsystem-Content: bundle.b.jar
+ */
+ private static final String APPLICATION_A = "application.a.esa";
+ /*
+ * Bundle-SymbolicName: bundle.a.jar
+ * Export-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
+ */
+ private static final String BUNDLE_C = "bundle.c.jar";
+
+ @Before
+ public static void createApplications() throws Exception {
+ if (createdApplications) {
+ return;
+ }
+ createBundleA();
+ createBundleB();
+ createBundleC();
+ createApplicationA();
+ createdApplications = true;
+ }
+
+ private static void createApplicationA() throws IOException {
+ createApplicationAManifest();
+ createSubsystem(APPLICATION_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_B);
+ createManifest(APPLICATION_A + ".mf", attributes);
+ }
+
+ private static void createBundleA() throws IOException {
+ Map<String, String> headers = new HashMap<String, String>();
+ headers.put(Constants.EXPORT_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 {
+ createBundle(BUNDLE_C);
+ }
+
+ public void setUp() throws Exception {
+ super.setUp();
+ registerRepositoryService(BUNDLE_A, BUNDLE_B);
+ }
+
+ /*
+ * Tests the start level of bundle constituents.
+ *
+ * A managed bundle is a bundle that was installed via the Subsystems API
+ * either as content or a dependency. This includes the region context
+ * bundle. The life cycle of managed bundles should follow the life cycle of
+ * the subsystem of which they are constituents. They therefore receive a
+ * start level of 1 to ensure they will be started and stopped at the same
+ * time as the subsystem.
+ *
+ * An unmanaged bundle is a bundle that was installed outside of the
+ * Subsystem API. For example, the root subsystem may contain bundles that
+ * were installed prior to the subsystems bundle. It's also possible to
+ * install bundles via subsystem.getBundleContext().install(...). Unmanaged
+ * bundles retain the start level setting assigned by the framework or
+ * third party.
+ */
+ @Test
+ public void testBundleStartLevel() throws Exception {
+ // Set the default bundle start level to something other than 1.
+ getSystemBundleAsFrameworkStartLevel().setInitialBundleStartLevel(5);
+ Subsystem a = installSubsystemFromFile(APPLICATION_A);
+ try {
+ startSubsystem(a);
+ try {
+ // Test managed bundles.
+ assertStartLevel(getBundle(a, BUNDLE_B), 1);
+ assertStartLevel(getRegionContextBundle(a), 1);
+ assertStartLevel(getBundle(getRootSubsystem(), BUNDLE_A), 1);
+ // Test unmanaged bundle.
+ Bundle c = installBundleFromFile(BUNDLE_C, a);
+ try {
+ assertConstituent(a, BUNDLE_C);
+ assertStartLevel(c, 5);
+ }
+ finally {
+ uninstallSilently(c);
+ }
+ }
+ finally {
+ stopSubsystemSilently(a);
+ }
+ }
+ finally {
+ uninstallSubsystemSilently(a);
+ }
+ }
+}
Modified: aries/trunk/subsystem/subsystem-itests/src/test/java/org/apache/aries/subsystem/itests/InstallTest.java
URL: http://svn.apache.org/viewvc/aries/trunk/subsystem/subsystem-itests/src/test/java/org/apache/aries/subsystem/itests/InstallTest.java?rev=1411703&r1=1411702&r2=1411703&view=diff
==============================================================================
--- aries/trunk/subsystem/subsystem-itests/src/test/java/org/apache/aries/subsystem/itests/InstallTest.java (original)
+++ aries/trunk/subsystem/subsystem-itests/src/test/java/org/apache/aries/subsystem/itests/InstallTest.java Tue Nov 20 15:39:06 2012
@@ -18,7 +18,6 @@
*/
package org.apache.aries.subsystem.itests;
-import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertSame;
import static org.junit.Assert.fail;
@@ -37,8 +36,6 @@ import org.junit.runner.RunWith;
import org.ops4j.pax.exam.junit.MavenConfiguredJUnit4TestRunner;
import org.osgi.framework.Bundle;
import org.osgi.framework.Version;
-import org.osgi.framework.startlevel.BundleStartLevel;
-import org.osgi.framework.startlevel.FrameworkStartLevel;
import org.osgi.service.subsystem.Subsystem;
@RunWith(MavenConfiguredJUnit4TestRunner.class)
@@ -178,30 +175,4 @@ public class InstallTest extends Subsyst
fail("Subsystem installation using directory URL as location failed");
}
}
-
- @Test
- public void testManagedBundleStartLevel() throws Exception {
- bundleContext.getBundle(0).adapt(FrameworkStartLevel.class).setInitialBundleStartLevel(5);
- Bundle tb1 = bundleContext.installBundle("tb1.jar", SubsystemTest.class.getClassLoader().getResourceAsStream("feature1/tb1.jar"));
- try {
- Subsystem feature2 = installSubsystemFromFile("feature2.esa");
- try {
- startSubsystem(feature2);
- try {
- assertEquals("Wrong start level for unmanaged bundle", 5, tb1.adapt(BundleStartLevel.class).getStartLevel());
- assertEquals("Wrong start level for managed bundle", 1, getBundle(feature2, "org.apache.aries.subsystem.itests.tb2").adapt(BundleStartLevel.class).getStartLevel());
- assertEquals("Wrong start level for managed bundle", 1, getBundle(feature2, "org.apache.aries.subsystem.itests.tb3").adapt(BundleStartLevel.class).getStartLevel());
- }
- finally {
- stopSubsystemSilently(feature2);
- }
- }
- finally {
- uninstallSubsystemSilently(feature2);
- }
- }
- finally {
- uninstallSilently(tb1);
- }
- }
}
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=1411703&r1=1411702&r2=1411703&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 Nov 20 15:39:06 2012
@@ -66,6 +66,8 @@ import org.osgi.framework.ServiceListene
import org.osgi.framework.ServiceRegistration;
import org.osgi.framework.Version;
import org.osgi.framework.namespace.IdentityNamespace;
+import org.osgi.framework.startlevel.BundleStartLevel;
+import org.osgi.framework.startlevel.FrameworkStartLevel;
import org.osgi.framework.wiring.BundleRevision;
import org.osgi.resource.Resource;
import org.osgi.service.repository.Repository;
@@ -430,6 +432,10 @@ public abstract class SubsystemTest exte
assertEvent(subsystem, Subsystem.State.RESOLVED, subsystemEvents.poll(subsystem.getSubsystemId(), 5000), type);
}
+ protected void assertStartLevel(Bundle bundle, int expected) {
+ assertEquals("Wrong start level", expected, bundle.adapt(BundleStartLevel.class).getStartLevel());
+ }
+
protected void assertState(State expected, State actual) {
assertState(EnumSet.of(expected), actual);
}
@@ -611,6 +617,14 @@ public abstract class SubsystemTest exte
return getOsgiService(Subsystem.class);
}
+ protected Bundle getSystemBundle() {
+ return bundleContext.getBundle(Constants.SYSTEM_BUNDLE_LOCATION);
+ }
+
+ protected FrameworkStartLevel getSystemBundleAsFrameworkStartLevel() {
+ return getSystemBundle().adapt(FrameworkStartLevel.class);
+ }
+
protected Bundle getSubsystemCoreBundle() {
return findBundleBySymbolicName("org.apache.aries.subsystem.core");
}