Search in sources :

Example 11 with ScopeUpdate

use of org.apache.aries.subsystem.scope.ScopeUpdate in project aries by apache.

the class MoveBundleTest method test2.

/**
	 * Create one scope off of the root scope with the following structure. 
	 * R
	 * |
	 * S
	 * Install a bundle using the test bundle's bundle context. This should add 
	 * the bundle to R since the test bundle is in R. Next, move the bundle into
	 * S without removing it from R. This should result in an 
	 * IllegalStateException. Finally, correct the error using the same 
	 * ScopeUpdate objects and commit again. This should succeed, and the bundle
	 * should now be in S.
	 * @throws Exception
	 */
@Test
public void test2() throws Exception {
    Bundle tb2 = installBundle("tb-2.jar");
    Scope root = getScope();
    ScopeUpdate rootUpdate = root.newScopeUpdate();
    ScopeUpdate sUpdate = rootUpdate.newChild("S");
    rootUpdate.getChildren().add(sUpdate);
    rootUpdate.commit();
    Scope s = sUpdate.getScope();
    assertTrue(root.getBundles().contains(tb2));
    assertFalse(s.getBundles().contains(tb2));
    rootUpdate = root.newScopeUpdate();
    sUpdate = findChildUpdate("S", rootUpdate);
    sUpdate.getBundles().add(tb2);
    try {
        rootUpdate.commit();
        fail();
    } catch (IllegalStateException e) {
    // Okay.
    }
    assertTrue(root.getBundles().contains(tb2));
    assertFalse(s.getBundles().contains(tb2));
    rootUpdate.getBundles().remove(tb2);
    rootUpdate.commit();
    assertFalse(root.getBundles().contains(tb2));
    assertTrue(s.getBundles().contains(tb2));
    tb2.uninstall();
}
Also used : Scope(org.apache.aries.subsystem.scope.Scope) Bundle(org.osgi.framework.Bundle) ScopeUpdate(org.apache.aries.subsystem.scope.ScopeUpdate) Test(org.junit.Test)

Example 12 with ScopeUpdate

use of org.apache.aries.subsystem.scope.ScopeUpdate in project aries by apache.

the class MoveBundleTest method test1.

/**
	 * Create two scopes off of the root scope with the following structure.
	 *    R
	 *   / \
	 * S1   S2
	 * Install a bundle using the test bundle's bundle context. This should add
	 * the bundle to R since the test bundle is in R. Next, move the bundle 
	 * into S1. Finally, move the bundle into S2.
	 * @throws Exception
	 */
@Test
@Ignore
public void test1() throws Exception {
    Bundle tb2 = installBundle("tb-2.jar");
    Scope root = getScope();
    ScopeUpdate rootUpdate = root.newScopeUpdate();
    ScopeUpdate s1Update = rootUpdate.newChild("S1");
    ScopeUpdate s2Update = rootUpdate.newChild("S2");
    rootUpdate.getChildren().add(s1Update);
    rootUpdate.getChildren().add(s2Update);
    rootUpdate.commit();
    Scope s1 = s1Update.getScope();
    Scope s2 = s2Update.getScope();
    assertTrue(root.getBundles().contains(tb2));
    assertFalse(s1.getBundles().contains(tb2));
    assertFalse(s2.getBundles().contains(tb2));
    rootUpdate = root.newScopeUpdate();
    rootUpdate.getBundles().remove(tb2);
    s1Update = findChildUpdate("S1", rootUpdate);
    s1Update.getBundles().add(tb2);
    rootUpdate.commit();
    assertFalse(root.getBundles().contains(tb2));
    assertTrue(s1.getBundles().contains(tb2));
    assertFalse(s2.getBundles().contains(tb2));
    rootUpdate = root.newScopeUpdate();
    s1Update = findChildUpdate("S1", rootUpdate);
    s1Update.getBundles().remove(tb2);
    s2Update = findChildUpdate("S2", rootUpdate);
    s2Update.getBundles().add(tb2);
    rootUpdate.commit();
    assertFalse(root.getBundles().contains(tb2));
    assertFalse(s1.getBundles().contains(tb2));
    assertTrue(s2.getBundles().contains(tb2));
    tb2.uninstall();
}
Also used : Scope(org.apache.aries.subsystem.scope.Scope) Bundle(org.osgi.framework.Bundle) ScopeUpdate(org.apache.aries.subsystem.scope.ScopeUpdate) Ignore(org.junit.Ignore) Test(org.junit.Test)

Example 13 with ScopeUpdate

use of org.apache.aries.subsystem.scope.ScopeUpdate in project aries by apache.

the class PersistenceTest method test4.

/**
	 * Create two scopes off of the root scope with the following structure.
	 * 
	 *    R
	 *   / \
	 * S1   S2
	 * 
	 * S1 contains bundle tb1, one import policy, and one export policy.
	 * S2 contains bundle tb2 and two import policies.
	 * 
	 * This configuration should persist between restarts of the Scope Admin
	 * bundle.
	 * 
	 * @throws Exception
	 */
@Test
public void test4() throws Exception {
    Scope root = getScope();
    ScopeUpdate rootUpdate = root.newScopeUpdate();
    ScopeUpdate s1Update = rootUpdate.newChild("S1");
    rootUpdate.getChildren().add(s1Update);
    ScopeUpdate s2Update = rootUpdate.newChild("S2");
    rootUpdate.getChildren().add(s2Update);
    s1Update.getBundlesToInstall().add(new InstallInfo(null, new URL(getBundleLocation("tb-1.jar"))));
    s2Update.getBundlesToInstall().add(new InstallInfo(null, new URL(getBundleLocation("tb-2.jar"))));
    addPackageImportPolicy("org.osgi.framework", s1Update);
    addPackageExportPolicy("org.apache.aries.subsystem.scope.itests.tb1", s1Update);
    addPackageImportPolicy("org.osgi.framework", s2Update);
    addPackageImportPolicy("org.apache.aries.subsystem.scope.itests.tb1", s2Update);
    assertTrue(rootUpdate.commit());
    root = getScope();
    assertEquals(2, root.getChildren().size());
    Scope s1 = findChildScope("S1", root);
    Bundle tb1 = findBundle("org.apache.aries.subsystem.scope.itests.tb1", s1);
    assertNotNull(tb1);
    assertTrue(s1.getBundles().contains(tb1));
    assertEquals(1, s1.getSharePolicies(SharePolicy.TYPE_IMPORT).get("osgi.wiring.package").size());
    assertEquals(1, s1.getSharePolicies(SharePolicy.TYPE_EXPORT).get("osgi.wiring.package").size());
    Scope s2 = findChildScope("S2", root);
    Bundle tb2 = findBundle("org.apache.aries.subsystem.scope.itests.tb2", s2);
    assertNotNull(tb2);
    assertTrue(s2.getBundles().contains(tb2));
    assertEquals(2, s2.getSharePolicies(SharePolicy.TYPE_IMPORT).get("osgi.wiring.package").size());
    Bundle scopeAdmin = findBundle("org.apache.aries.subsystem.scope.impl");
    assertNotNull(scopeAdmin);
    scopeAdmin.stop();
    scopeAdmin.start();
    root = getScope();
    assertEquals(2, root.getChildren().size());
    s1 = findChildScope("S1", root);
    assertTrue(s1.getBundles().contains(tb1));
    assertEquals(1, s1.getSharePolicies(SharePolicy.TYPE_IMPORT).get("osgi.wiring.package").size());
    assertEquals(1, s1.getSharePolicies(SharePolicy.TYPE_EXPORT).get("osgi.wiring.package").size());
    s2 = findChildScope("S2", root);
    assertTrue(s2.getBundles().contains(tb2));
    assertEquals(2, s2.getSharePolicies(SharePolicy.TYPE_IMPORT).get("osgi.wiring.package").size());
}
Also used : InstallInfo(org.apache.aries.subsystem.scope.InstallInfo) Scope(org.apache.aries.subsystem.scope.Scope) Bundle(org.osgi.framework.Bundle) ScopeUpdate(org.apache.aries.subsystem.scope.ScopeUpdate) URL(java.net.URL) Test(org.junit.Test)

Example 14 with ScopeUpdate

use of org.apache.aries.subsystem.scope.ScopeUpdate in project aries by apache.

the class ScopeUpdateImpl method commit0.

private synchronized boolean commit0() throws BundleException {
    synchronized (scope) {
        if (scope.getLastUpdate() > id)
            return false;
        scope.setUpdating(true);
        synchronized (bundles) {
            removeBundles();
        }
        synchronized (children) {
            for (ScopeUpdate child : children) {
                if (!((ScopeUpdateImpl) child).commit0())
                    return false;
            }
            uninstallChildren();
        }
        synchronized (bundles) {
            addBundles();
        }
        synchronized (bundlesToInstall) {
            installBundles();
        }
        updateSharePolicies();
        scope.setLastUpdate(id);
        scope.getScopes().addScope(scope);
        scope.setUpdating(false);
        return true;
    }
}
Also used : ScopeUpdate(org.apache.aries.subsystem.scope.ScopeUpdate)

Example 15 with ScopeUpdate

use of org.apache.aries.subsystem.scope.ScopeUpdate in project aries by apache.

the class BundleVisibilityTest method test1.

/**
	 * Install a bundle into the same scope as this one. Both bundles should be
	 * able to see each other.
	 * @throws Exception
	 */
@Test
public void test1() throws Exception {
    Scope scope = getScope();
    assertTrue(scope.getBundles().contains(bundleContext.getBundle()));
    ScopeUpdate scopeUpdate = scope.newScopeUpdate();
    String location = getBundleLocation("tb-4.jar");
    assertNull(bundleContext.getBundle(location));
    URL url = new URL(location);
    InstallInfo installInfo = new InstallInfo(location, url.openStream());
    scopeUpdate.getBundlesToInstall().add(installInfo);
    scopeUpdate.commit();
    Bundle bundle = bundleContext.getBundle(location);
    assertTrue(scope.getBundles().contains(bundle));
    bundle.start();
    ServiceReference<BundleProvider> bundleProviderRef = bundleContext.getServiceReference(BundleProvider.class);
    BundleProvider bundleProvider = bundleContext.getService(bundleProviderRef);
    assertTrue(bundleProvider.getBundles().contains(bundleContext.getBundle()));
    assertTrue(Arrays.asList(bundleContext.getBundles()).contains(bundle));
    assertNotNull(bundleContext.getBundle(bundle.getBundleId()));
    assertNotNull(bundleProvider.getBundle(bundle.getBundleId()));
    bundleContext.ungetService(bundleProviderRef);
    bundle.uninstall();
}
Also used : InstallInfo(org.apache.aries.subsystem.scope.InstallInfo) Scope(org.apache.aries.subsystem.scope.Scope) Bundle(org.osgi.framework.Bundle) ScopeUpdate(org.apache.aries.subsystem.scope.ScopeUpdate) URL(java.net.URL) Test(org.junit.Test)

Aggregations

ScopeUpdate (org.apache.aries.subsystem.scope.ScopeUpdate)27 Bundle (org.osgi.framework.Bundle)22 Test (org.junit.Test)21 URL (java.net.URL)20 InstallInfo (org.apache.aries.subsystem.scope.InstallInfo)20 Scope (org.apache.aries.subsystem.scope.Scope)16 IOException (java.io.IOException)5 MalformedURLException (java.net.MalformedURLException)5 ArrayList (java.util.ArrayList)5 List (java.util.List)5 SharePolicy (org.apache.aries.subsystem.scope.SharePolicy)5 BundleException (org.osgi.framework.BundleException)5 Filter (org.osgi.framework.Filter)5 InvalidSyntaxException (org.osgi.framework.InvalidSyntaxException)5 Ignore (org.junit.Ignore)4 FrameworkWiring (org.osgi.framework.wiring.FrameworkWiring)4 ServiceReference (org.osgi.framework.ServiceReference)3 HelloIsolation (org.apache.aries.subsystem.example.helloIsolation.HelloIsolation)2 CoreOptions.mavenBundle (org.ops4j.pax.exam.CoreOptions.mavenBundle)2 BundleContext (org.osgi.framework.BundleContext)2