use of org.apache.aries.subsystem.scope.ScopeUpdate in project aries by apache.
the class ScopeAdminTest method testPackageIsolation.
@Test
@Ignore
public void testPackageIsolation() throws Exception {
// make sure we are using a framework that provides composite admin service
assertNotNull("scope admin should not be null", scope);
System.out.println("able to get scope admin service");
ScopeUpdate su = scope.newScopeUpdate();
ScopeUpdate childScopeUpdate = su.newChild("scope_test1");
su.getChildren().add(childScopeUpdate);
addPackageImportPolicy("org.osgi.framework", childScopeUpdate);
addPackageImportPolicy("org.osgi.util.tracker", childScopeUpdate);
// build up installInfo object for the scope
InstallInfo info1 = new InstallInfo("helloIsolation", new URL("mvn:org.apache.aries.subsystem/org.apache.aries.subsystem.example.helloIsolation/0.1-SNAPSHOT"));
InstallInfo info2 = new InstallInfo("helloIsolationRef", new URL("mvn:org.apache.aries.subsystem/org.apache.aries.subsystem.example.helloIsolationRef/0.1-SNAPSHOT"));
List<InstallInfo> bundlesToInstall = childScopeUpdate.getBundlesToInstall();
bundlesToInstall.add(info1);
bundlesToInstall.add(info2);
// add bundles to be installed, based on subsystem content
su.commit();
// start all bundles in the scope scope_test1
Collection<Bundle> bundlesToStart = childScopeUpdate.getScope().getBundles();
for (Bundle b : bundlesToStart) {
b.start();
}
// install helloIsolationRef1 bundle in the root scope
URL url1 = new URL("mvn:org.apache.aries.subsystem/org.apache.aries.subsystem.example.helloIsolationRef/0.1-SNAPSHOT");
Bundle helloIsolationRef = bundleContext.installBundle("helloIsolationRef1-rootScope", url1.openStream());
try {
helloIsolationRef.start();
fail("should not be able to start helloIsolationRef since missing import packages");
} catch (Exception ex) {
// expect resolving error
}
URL url2 = new URL("mvn:org.apache.aries.subsystem/org.apache.aries.subsystem.example.helloIsolation/0.1-SNAPSHOT");
Bundle helloIsolation = bundleContext.installBundle("helloIsolation1-rootScope", url2.openStream());
helloIsolation.start();
// should be able to start the bundle now.
helloIsolationRef.start();
// remove helloIsolationRef & helloIsolation
helloIsolationRef.uninstall();
helloIsolation.uninstall();
// remove child scope
su = scope.newScopeUpdate();
// Collection<Scope> scopes = su.getToBeRemovedChildren();
Collection<ScopeUpdate> scopes = su.getChildren();
childScopeUpdate = scopes.iterator().next();
// obtain child scope admin from service registry
// String filter = "ScopeName=scope_test1";
// Scope childScopeAdmin = getOsgiService(Scope.class, filter, DEFAULT_TIMEOUT);
Scope childScopeAdmin = childScopeUpdate.getScope();
assertEquals(scope, childScopeAdmin.getParent());
// scopes.add(childScopeAdmin);
scopes.remove(childScopeUpdate);
su.commit();
assertFalse(scope.getChildren().contains(childScopeAdmin));
su = scope.newScopeUpdate();
assertFalse(su.getChildren().contains(childScopeUpdate));
// childScopeAdmin = null;
// try {
// childScopeAdmin = getOsgiService(Scope.class, filter, DEFAULT_TIMEOUT);
// } catch (Exception ex) {
// // ignore
// }
// assertNull("scope admin service for the scope should be unregistered", childScopeAdmin);
}
use of org.apache.aries.subsystem.scope.ScopeUpdate in project aries by apache.
the class ScopeAdminTest method testPackageSharingFromRootScope.
// test sharing the helloIsolation package & service from the root scope.
@Test
public void testPackageSharingFromRootScope() throws Exception {
// install helloIsolationRef1 bundle in the root scope
URL url1 = new URL("mvn:org.apache.aries.subsystem/org.apache.aries.subsystem.example.helloIsolation/0.1-SNAPSHOT");
Bundle helloIsolation = bundleContext.installBundle("helloIsolation1-rootScope", url1.openStream());
try {
helloIsolation.start();
} catch (Exception ex) {
fail("should be able to start helloIsolation");
}
// make sure we are using a framework that provides composite admin service
ScopeUpdate su = scope.newScopeUpdate();
ScopeUpdate childScopeUpdate = su.newChild("scope_test1");
su.getChildren().add(childScopeUpdate);
addPackageImportPolicy("org.osgi.framework", childScopeUpdate);
Map<String, List<SharePolicy>> sharePolicies = childScopeUpdate.getSharePolicies(SharePolicy.TYPE_IMPORT);
final Filter filter1 = FrameworkUtil.createFilter("(&" + "(osgi.wiring.package=org.apache.aries.subsystem.example.helloIsolation)" + ")");
final Filter filter2 = FrameworkUtil.createFilter("(&" + "(scope.share.service=org.apache.aries.subsystem.example.helloIsolation.HelloIsolation)" + ")");
List<SharePolicy> packagePolicies = sharePolicies.get(BundleRevision.PACKAGE_NAMESPACE);
if (packagePolicies == null) {
packagePolicies = new ArrayList<SharePolicy>();
sharePolicies.put(BundleRevision.PACKAGE_NAMESPACE, packagePolicies);
}
packagePolicies.add(new SharePolicy(SharePolicy.TYPE_IMPORT, BundleRevision.PACKAGE_NAMESPACE, filter1));
List<SharePolicy> servicePolicies = sharePolicies.get("scope.share.service");
if (servicePolicies == null) {
servicePolicies = new ArrayList<SharePolicy>();
sharePolicies.put("scope.share.service", servicePolicies);
}
servicePolicies.add(new SharePolicy(SharePolicy.TYPE_IMPORT, "scope.share.service", filter2));
// build up installInfo object for the scope
InstallInfo info2 = new InstallInfo("helloIsolationRef", new URL("mvn:org.apache.aries.subsystem/org.apache.aries.subsystem.example.helloIsolationRef/0.1-SNAPSHOT"));
List<InstallInfo> bundlesToInstall = childScopeUpdate.getBundlesToInstall();
bundlesToInstall.add(info2);
// add bundles to be installed, based on subsystem content
su.commit();
// start all bundles in the scope scope_test1
Collection<Bundle> bundlesToStart = childScopeUpdate.getScope().getBundles();
for (Bundle b : bundlesToStart) {
try {
b.start();
} catch (Exception ex) {
ex.printStackTrace();
fail("should be able to start helloIsolationRef in scope_test1");
}
}
// remove helloIsolation in root scope
helloIsolation.uninstall();
// remove child scope
su = scope.newScopeUpdate();
Collection<ScopeUpdate> scopes = su.getChildren();
childScopeUpdate = scopes.iterator().next();
// obtain child scope admin from service registry
// String filter = "ScopeName=scope_test1";
Scope childScopeAdmin = childScopeUpdate.getScope();
assertEquals(scope, childScopeAdmin.getParent());
scopes.remove(childScopeUpdate);
su.commit();
assertFalse(scope.getChildren().contains(childScopeAdmin));
su = scope.newScopeUpdate();
assertFalse(su.getChildren().contains(childScopeUpdate));
// childScopeAdmin = null;
// try {
// childScopeAdmin = getOsgiService(Scope.class, filter, DEFAULT_TIMEOUT);
// } catch (Exception ex) {
// // ignore
// }
// assertNull("scope admin service for the scope should be unregistered", childScopeAdmin);
}
Aggregations