Search in sources :

Example 16 with SubsystemArchiveBuilder

use of org.apache.aries.subsystem.itests.util.SubsystemArchiveBuilder in project aries by apache.

the class Aries1383Test method test5.

/*
	 * (5) Subsystem with apache-aries-provision-dependencies:=resolve undergoes 
	 * the following state transitions when starting: INSTALLING -> INSTALLED 
	 * -> RESOLVING -> RESOLVED -> STARTING -> ACTIVE.
	 */
@Test
public void test5() throws Exception {
    Subsystem root = getRootSubsystem();
    subsystemEvents.clear();
    Subsystem subsystem = root.install("application", new SubsystemArchiveBuilder().header(SubsystemConstants.SUBSYSTEM_SYMBOLICNAME, "application").header(SubsystemConstants.SUBSYSTEM_TYPE, SubsystemConstants.SUBSYSTEM_TYPE_APPLICATION + ';' + AriesProvisionDependenciesDirective.RESOLVE.toString()).build());
    try {
        long id = subsystem.getSubsystemId();
        assertEvent(subsystem, State.INSTALLING, subsystemEvents.poll(id, 5000));
        assertNull(subsystemEvents.poll(id, 1));
        subsystem.start();
        try {
            assertEvent(subsystem, State.INSTALLED, subsystemEvents.poll(id, 5000));
            assertEvent(subsystem, State.RESOLVING, subsystemEvents.poll(id, 5000));
            assertEvent(subsystem, State.RESOLVED, subsystemEvents.poll(id, 5000));
            assertEvent(subsystem, State.STARTING, subsystemEvents.poll(id, 5000));
            assertEvent(subsystem, State.ACTIVE, subsystemEvents.poll(id, 5000));
            assertNull(subsystemEvents.poll(id, 1));
        } finally {
            stopSubsystemSilently(subsystem);
        }
    } finally {
        uninstallSubsystemSilently(subsystem);
    }
}
Also used : SubsystemArchiveBuilder(org.apache.aries.subsystem.itests.util.SubsystemArchiveBuilder) AriesSubsystem(org.apache.aries.subsystem.AriesSubsystem) Subsystem(org.osgi.service.subsystem.Subsystem) SubsystemTest(org.apache.aries.subsystem.itests.SubsystemTest) Test(org.junit.Test)

Example 17 with SubsystemArchiveBuilder

use of org.apache.aries.subsystem.itests.util.SubsystemArchiveBuilder in project aries by apache.

the class Aries1383Test method test1.

/*
	 * (1) A set of subsystems with interleaving content dependencies are able 
	 * to be independently, simultaneously, and successfully installed and 
	 * started.
	 */
@Test
public void test1() throws Exception {
    Subsystem root = getRootSubsystem();
    final Subsystem c1 = installSubsystem(root, "c1", new SubsystemArchiveBuilder().symbolicName("c1").type(SubsystemConstants.SUBSYSTEM_TYPE_COMPOSITE + ';' + AriesProvisionDependenciesDirective.RESOLVE.toString()).build(), false);
    uninstallableSubsystems.add(c1);
    c1.start();
    stoppableSubsystems.add(c1);
    @SuppressWarnings("unchecked") Callable<Subsystem>[] installCallables = new Callable[] { new Callable<Subsystem>() {

        @Override
        public Subsystem call() throws Exception {
            Subsystem result = installSubsystem(c1, "a1", new SubsystemArchiveBuilder().symbolicName("a1").type(SubsystemConstants.SUBSYSTEM_TYPE_APPLICATION + ';' + AriesProvisionDependenciesDirective.RESOLVE.toString()).content("b1").bundle("b1", new BundleArchiveBuilder().symbolicName("b1").importPackage("b2").build()).build(), false);
            uninstallableSubsystems.add(result);
            return result;
        }
    }, new Callable<Subsystem>() {

        @Override
        public Subsystem call() throws Exception {
            Subsystem result = installSubsystem(c1, "f1", new SubsystemArchiveBuilder().symbolicName("f1").type(SubsystemConstants.SUBSYSTEM_TYPE_FEATURE + ';' + AriesProvisionDependenciesDirective.RESOLVE.toString()).content("b2").bundle("b2", new BundleArchiveBuilder().symbolicName("b2").exportPackage("b2").importPackage("b3").build()).build(), false);
            uninstallableSubsystems.add(result);
            return result;
        }
    }, new Callable<Subsystem>() {

        @Override
        public Subsystem call() throws Exception {
            Subsystem result = installSubsystem(c1, "f2", new SubsystemArchiveBuilder().symbolicName("f2").type(SubsystemConstants.SUBSYSTEM_TYPE_FEATURE + ';' + AriesProvisionDependenciesDirective.RESOLVE.toString()).content("b4").bundle("b4", new BundleArchiveBuilder().symbolicName("b4").exportPackage("b4").importPackage("b2").importPackage("b3").build()).build(), false);
            uninstallableSubsystems.add(result);
            return result;
        }
    }, new Callable<Subsystem>() {

        @Override
        public Subsystem call() throws Exception {
            Subsystem result = installSubsystem(c1, "c2", new SubsystemArchiveBuilder().symbolicName("c2").type(SubsystemConstants.SUBSYSTEM_TYPE_COMPOSITE + ';' + AriesProvisionDependenciesDirective.RESOLVE.toString()).content("b3;version=\"[0,0]\"").exportPackage("b3").importPackage("b4").bundle("b3", new BundleArchiveBuilder().symbolicName("b3").exportPackage("b3").importPackage("b4").build()).build(), false);
            uninstallableSubsystems.add(result);
            return result;
        }
    } };
    ExecutorService executor = Executors.newFixedThreadPool(4);
    List<Future<Subsystem>> installFutures = executor.invokeAll(Arrays.asList(installCallables));
    final Subsystem a1 = installFutures.get(0).get();
    assertConstituent(a1, "b1");
    final Subsystem f1 = installFutures.get(1).get();
    assertConstituent(f1, "b2");
    final Subsystem f2 = installFutures.get(2).get();
    assertConstituent(f2, "b4");
    final Subsystem c2 = installFutures.get(3).get();
    assertConstituent(c2, "b3");
    @SuppressWarnings("unchecked") Callable<Null>[] startCallables = new Callable[] { new Callable<Null>() {

        @Override
        public Null call() throws Exception {
            a1.start();
            assertEvent(a1, State.INSTALLED, subsystemEvents.poll(a1.getSubsystemId(), 5000));
            assertEvent(a1, State.RESOLVING, subsystemEvents.poll(a1.getSubsystemId(), 5000));
            assertEvent(a1, State.RESOLVED, subsystemEvents.poll(a1.getSubsystemId(), 5000));
            stoppableSubsystems.add(a1);
            return null;
        }
    }, new Callable<Null>() {

        @Override
        public Null call() throws Exception {
            f1.start();
            assertEvent(f1, State.INSTALLED, subsystemEvents.poll(f1.getSubsystemId(), 5000));
            assertEvent(f1, State.RESOLVING, subsystemEvents.poll(f1.getSubsystemId(), 5000));
            assertEvent(f1, State.RESOLVED, subsystemEvents.poll(f1.getSubsystemId(), 5000));
            stoppableSubsystems.add(f1);
            return null;
        }
    }, new Callable<Null>() {

        @Override
        public Null call() throws Exception {
            f2.start();
            assertEvent(f2, State.INSTALLED, subsystemEvents.poll(f2.getSubsystemId(), 5000));
            assertEvent(f2, State.RESOLVING, subsystemEvents.poll(f2.getSubsystemId(), 5000));
            assertEvent(f2, State.RESOLVED, subsystemEvents.poll(f2.getSubsystemId(), 5000));
            stoppableSubsystems.add(f2);
            return null;
        }
    }, new Callable<Null>() {

        @Override
        public Null call() throws Exception {
            c2.start();
            assertEvent(c2, State.INSTALLED, subsystemEvents.poll(c2.getSubsystemId(), 5000));
            assertEvent(c2, State.RESOLVING, subsystemEvents.poll(c2.getSubsystemId(), 5000));
            assertEvent(c2, State.RESOLVED, subsystemEvents.poll(c2.getSubsystemId(), 5000));
            stoppableSubsystems.add(c2);
            return null;
        }
    } };
    List<Future<Null>> startFutures = executor.invokeAll(Arrays.asList(startCallables));
    startFutures.get(0).get();
    startFutures.get(1).get();
    startFutures.get(2).get();
    startFutures.get(3).get();
}
Also used : SubsystemArchiveBuilder(org.apache.aries.subsystem.itests.util.SubsystemArchiveBuilder) BundleArchiveBuilder(org.apache.aries.subsystem.itests.util.BundleArchiveBuilder) AriesSubsystem(org.apache.aries.subsystem.AriesSubsystem) Subsystem(org.osgi.service.subsystem.Subsystem) ExecutorService(java.util.concurrent.ExecutorService) Future(java.util.concurrent.Future) Callable(java.util.concurrent.Callable) SubsystemTest(org.apache.aries.subsystem.itests.SubsystemTest) Test(org.junit.Test)

Example 18 with SubsystemArchiveBuilder

use of org.apache.aries.subsystem.itests.util.SubsystemArchiveBuilder in project aries by apache.

the class Aries1383Test method testRestart2.

@Test
public void testRestart2() throws Exception {
    Subsystem root = getRootSubsystem();
    Subsystem c1 = installSubsystem(root, "c1", new SubsystemArchiveBuilder().symbolicName("c1").type(SubsystemConstants.SUBSYSTEM_TYPE_COMPOSITE + ';' + AriesProvisionDependenciesDirective.RESOLVE.toString()).content("c1b1;version=\"[0,0]\"").exportPackage("c1b1").importPackage("c2b1").bundle("c1b1", new BundleArchiveBuilder().symbolicName("c1b1").exportPackage("c1b1").importPackage("c2b1").build()).build(), false);
    uninstallableSubsystems.add(c1);
    Subsystem c2 = installSubsystem(root, "c2", new SubsystemArchiveBuilder().symbolicName("c2").type(SubsystemConstants.SUBSYSTEM_TYPE_COMPOSITE + ';' + AriesProvisionDependenciesDirective.RESOLVE.toString()).content("c2b1;version=\"[0,0]\"").exportPackage("c2b1").importPackage("c1b1").bundle("c2b1", new BundleArchiveBuilder().symbolicName("c2b1").exportPackage("c2b1").importPackage("c1b1").build()).build(), false);
    uninstallableSubsystems.add(c2);
    assertChild(root, "c1", null, SubsystemConstants.SUBSYSTEM_TYPE_COMPOSITE);
    assertChild(root, "c2", null, SubsystemConstants.SUBSYSTEM_TYPE_COMPOSITE);
    restartSubsystemsImplBundle();
    root = getRootSubsystem();
    c1 = getChild(root, "c1", null, SubsystemConstants.SUBSYSTEM_TYPE_COMPOSITE);
    assertNotNull("Missing child", c1);
    uninstallableSubsystems.add(c1);
    c2 = getChild(root, "c2", null, SubsystemConstants.SUBSYSTEM_TYPE_COMPOSITE);
    assertNotNull("Missing child", c2);
    uninstallableSubsystems.add(c2);
    startSubsystem(c1, false);
    stoppableSubsystems.add(c1);
    try {
        assertState(EnumSet.of(State.RESOLVED, State.ACTIVE), c2);
    } catch (AssertionError e) {
        System.out.println(c2.getState());
    }
}
Also used : SubsystemArchiveBuilder(org.apache.aries.subsystem.itests.util.SubsystemArchiveBuilder) BundleArchiveBuilder(org.apache.aries.subsystem.itests.util.BundleArchiveBuilder) AriesSubsystem(org.apache.aries.subsystem.AriesSubsystem) Subsystem(org.osgi.service.subsystem.Subsystem) SubsystemTest(org.apache.aries.subsystem.itests.SubsystemTest) Test(org.junit.Test)

Example 19 with SubsystemArchiveBuilder

use of org.apache.aries.subsystem.itests.util.SubsystemArchiveBuilder in project aries by apache.

the class Aries1383Test method testAutoInstallDependenciesFeature.

@Test
public void testAutoInstallDependenciesFeature() throws Exception {
    Subsystem root = getRootSubsystem();
    Subsystem shared = installSubsystem(root, "shared", new SubsystemArchiveBuilder().symbolicName("shared").type(SubsystemConstants.SUBSYSTEM_TYPE_COMPOSITE + ';' + AriesProvisionDependenciesDirective.RESOLVE.toString() + ';' + SubsystemConstants.PROVISION_POLICY_DIRECTIVE + ":=" + SubsystemConstants.PROVISION_POLICY_ACCEPT_DEPENDENCIES).build(), false);
    uninstallableSubsystems.add(shared);
    startSubsystem(shared, false);
    Subsystem b = installSubsystem(shared, "b", new SubsystemArchiveBuilder().symbolicName("b").type(SubsystemConstants.SUBSYSTEM_TYPE_FEATURE).content("a").bundle("a", new BundleArchiveBuilder().symbolicName("a").importPackage("b").exportPackage("a").build()).bundle("b", new BundleArchiveBuilder().symbolicName("b").exportPackage("b").build()).build(), false);
    try {
        installSubsystem(shared, "a", new SubsystemArchiveBuilder().symbolicName("a").type(SubsystemConstants.SUBSYSTEM_TYPE_APPLICATION + ';' + AriesProvisionDependenciesDirective.INSTALL.toString()).bundle("a", new BundleArchiveBuilder().symbolicName("a").importPackage("a").build()).build(), true);
        assertState(EnumSet.of(State.INSTALLED, State.RESOLVED), b);
    } catch (Exception e) {
        e.printStackTrace();
        fail("Subsystem should have installed");
    }
}
Also used : SubsystemArchiveBuilder(org.apache.aries.subsystem.itests.util.SubsystemArchiveBuilder) BundleArchiveBuilder(org.apache.aries.subsystem.itests.util.BundleArchiveBuilder) AriesSubsystem(org.apache.aries.subsystem.AriesSubsystem) Subsystem(org.osgi.service.subsystem.Subsystem) SubsystemException(org.osgi.service.subsystem.SubsystemException) SubsystemTest(org.apache.aries.subsystem.itests.SubsystemTest) Test(org.junit.Test)

Example 20 with SubsystemArchiveBuilder

use of org.apache.aries.subsystem.itests.util.SubsystemArchiveBuilder in project aries by apache.

the class Aries1383Test method testMatchingCapabilityInDisconnectedRegion.

@Test
public void testMatchingCapabilityInDisconnectedRegion() throws Exception {
    Subsystem root = getRootSubsystem();
    BundleArchiveBuilder b1Builder = new BundleArchiveBuilder().symbolicName("b1").exportPackage("b1");
    Bundle b1 = root.getBundleContext().installBundle("b1", b1Builder.build());
    try {
        Subsystem a1 = installSubsystem(root, "a1", new SubsystemArchiveBuilder().symbolicName("a1").type(SubsystemConstants.SUBSYSTEM_TYPE_APPLICATION + ';' + AriesProvisionDependenciesDirective.RESOLVE.toString() + ';' + SubsystemConstants.PROVISION_POLICY_DIRECTIVE + ":=" + SubsystemConstants.PROVISION_POLICY_ACCEPT_DEPENDENCIES).build(), false);
        uninstallableSubsystems.add(a1);
        startSubsystem(a1, false);
        stoppableSubsystems.add(a1);
        removeConnectionWithParent(a1);
        Subsystem a2 = installSubsystem(a1, "a2", new SubsystemArchiveBuilder().symbolicName("a2").type(SubsystemConstants.SUBSYSTEM_TYPE_APPLICATION).content("b2").bundle("b2", new BundleArchiveBuilder().symbolicName("b2").importPackage("b1").build()).bundle("b1", b1Builder.build()).build(), false);
        uninstallableSubsystems.add(a2);
        assertState(State.INSTALLING, a2);
        assertNotConstituent(a1, "b1");
        try {
            startSubsystem(a2, false);
            stoppableSubsystems.add(a2);
            assertConstituent(a1, "b1");
        } catch (SubsystemException e) {
            e.printStackTrace();
            fail("Subsystem should have started");
        }
    } finally {
        uninstallSilently(b1);
    }
}
Also used : SubsystemArchiveBuilder(org.apache.aries.subsystem.itests.util.SubsystemArchiveBuilder) BundleArchiveBuilder(org.apache.aries.subsystem.itests.util.BundleArchiveBuilder) Bundle(org.osgi.framework.Bundle) AriesSubsystem(org.apache.aries.subsystem.AriesSubsystem) Subsystem(org.osgi.service.subsystem.Subsystem) SubsystemException(org.osgi.service.subsystem.SubsystemException) SubsystemTest(org.apache.aries.subsystem.itests.SubsystemTest) Test(org.junit.Test)

Aggregations

SubsystemArchiveBuilder (org.apache.aries.subsystem.itests.util.SubsystemArchiveBuilder)31 Subsystem (org.osgi.service.subsystem.Subsystem)30 BundleArchiveBuilder (org.apache.aries.subsystem.itests.util.BundleArchiveBuilder)22 AriesSubsystem (org.apache.aries.subsystem.AriesSubsystem)21 SubsystemTest (org.apache.aries.subsystem.itests.SubsystemTest)21 Test (org.junit.Test)21 SubsystemException (org.osgi.service.subsystem.SubsystemException)16 Bundle (org.osgi.framework.Bundle)5 Callable (java.util.concurrent.Callable)3 ExecutorService (java.util.concurrent.ExecutorService)3 Future (java.util.concurrent.Future)3 TestCapability (org.apache.aries.subsystem.itests.util.TestCapability)3 TestRepository (org.apache.aries.subsystem.itests.util.TestRepository)3 Repository (org.osgi.service.repository.Repository)3 TestRepositoryContent (org.apache.aries.subsystem.itests.util.TestRepositoryContent)2 TestRequirement (org.apache.aries.subsystem.itests.util.TestRequirement)1