Search in sources :

Example 11 with SubsystemArchiveBuilder

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

the class Aries1383Test method testComApiComImplAppClient.

@Test
public void testComApiComImplAppClient() throws Exception {
    Subsystem root = getRootSubsystem();
    final 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).importPackage("org.osgi.framework").build(), false);
    uninstallableSubsystems.add(shared);
    shared.start();
    stoppableSubsystems.add(shared);
    @SuppressWarnings("unchecked") Callable<Subsystem>[] installCallables = new Callable[] { new Callable<Subsystem>() {

        @Override
        public Subsystem call() throws Exception {
            Subsystem result = installSubsystem(shared, "client", new SubsystemArchiveBuilder().symbolicName("client").type(SubsystemConstants.SUBSYSTEM_TYPE_APPLICATION).bundle("client", new BundleArchiveBuilder().symbolicName("client").importPackage("org.apache.aries.subsystem.itests.defect").requireCapability("osgi.service;filter:=\"(objectClass=" + TestService.class.getName() + ")\";effective:=active").build()).build(), false);
            uninstallableSubsystems.add(result);
            return result;
        }
    }, new Callable<Subsystem>() {

        @Override
        public Subsystem call() throws Exception {
            Subsystem result = installSubsystem(shared, "impl", new SubsystemArchiveBuilder().symbolicName("impl").type(SubsystemConstants.SUBSYSTEM_TYPE_COMPOSITE).content("impl;version=\"[0,0]\"").provideCapability("osgi.service;objectClass:List<String>=\"" + TestService.class.getName() + "\"").importPackage("org.osgi.framework").requireBundle("api").bundle("impl", new BundleArchiveBuilder().symbolicName("impl").provideCapability("osgi.service;objectClass:List<String>=\"" + TestService.class.getName() + "\"").importPackage("org.osgi.framework").requireBundle("api").clazz(TestServiceImpl.class).activator(TestServiceImplActivator.class).build()).build(), false);
            uninstallableSubsystems.add(result);
            return result;
        }
    }, new Callable<Subsystem>() {

        @Override
        public Subsystem call() throws Exception {
            Subsystem result = installSubsystem(shared, "api", new SubsystemArchiveBuilder().symbolicName("api").type(SubsystemConstants.SUBSYSTEM_TYPE_COMPOSITE).content("api;version=\"[0,0]\"").exportPackage("org.apache.aries.subsystem.itests.defect").provideCapability("osgi.wiring.bundle;osgi.wiring.bundle=api;bundle-version=0").bundle("api", new BundleArchiveBuilder().symbolicName("api").exportPackage("org.apache.aries.subsystem.itests.defect").clazz(TestService.class).build()).build(), false);
            uninstallableSubsystems.add(result);
            return result;
        }
    } };
    ExecutorService executor = Executors.newFixedThreadPool(3);
    List<Future<Subsystem>> installFutures = executor.invokeAll(Arrays.asList(installCallables));
    final Subsystem a1 = installFutures.get(0).get();
    final Subsystem c1 = installFutures.get(1).get();
    final Subsystem c2 = installFutures.get(2).get();
    @SuppressWarnings("unchecked") Callable<Void>[] startCallables = new Callable[] { new Callable<Void>() {

        @Override
        public Void call() throws Exception {
            a1.start();
            stoppableSubsystems.add(a1);
            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));
            assertEvent(a1, State.STARTING, subsystemEvents.poll(a1.getSubsystemId(), 5000));
            assertEvent(a1, State.ACTIVE, subsystemEvents.poll(a1.getSubsystemId(), 5000));
            return null;
        }
    }, new Callable<Void>() {

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

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

Example 12 with SubsystemArchiveBuilder

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

the class Aries1383Test method test18.

/*
	 * (18) Scoped subsystem with a value of apache-aries-provision-dependencies 
	 * that overrides the scoped parent behaves accordingly.
	 */
@Test
public void test18() throws Exception {
    Subsystem root = getRootSubsystem();
    subsystemEvents.clear();
    Subsystem parent = root.install("parent", new SubsystemArchiveBuilder().symbolicName("parent").type(SubsystemConstants.SUBSYSTEM_TYPE_APPLICATION + ';' + AriesProvisionDependenciesDirective.INSTALL.toString() + ';' + SubsystemConstants.PROVISION_POLICY_DIRECTIVE + ":=" + SubsystemConstants.PROVISION_POLICY_ACCEPT_DEPENDENCIES).content("bundle1").bundle("bundle1", new BundleArchiveBuilder().symbolicName("bundle1").importPackage("a").build()).bundle("bundle2", new BundleArchiveBuilder().symbolicName("bundle2").exportPackage("a").build()).build());
    try {
        long id = parent.getSubsystemId();
        assertEvent(id, "parent", Version.emptyVersion, SubsystemConstants.SUBSYSTEM_TYPE_APPLICATION, State.INSTALLING, subsystemEvents.poll(id, 5000), ServiceEvent.REGISTERED);
        assertEvent(id, "parent", Version.emptyVersion, SubsystemConstants.SUBSYSTEM_TYPE_APPLICATION, State.INSTALLED, subsystemEvents.poll(id, 5000), ServiceEvent.MODIFIED);
        assertNull("Unexpected event", subsystemEvents.poll(id, 1));
        assertConstituent(parent, "bundle2");
        assertConstituent(parent, "bundle1");
        parent.start();
        Subsystem child = parent.install("child", new SubsystemArchiveBuilder().symbolicName("child").type(SubsystemConstants.SUBSYSTEM_TYPE_APPLICATION + ';' + AriesProvisionDependenciesDirective.RESOLVE.toString()).content("bundle3").bundle("bundle3", new BundleArchiveBuilder().symbolicName("bundle3").importPackage("b").build()).bundle("bundle4", new BundleArchiveBuilder().symbolicName("bundle4").exportPackage("b").build()).build());
        id = child.getSubsystemId();
        assertEvent(id, "child", Version.emptyVersion, SubsystemConstants.SUBSYSTEM_TYPE_APPLICATION, State.INSTALLING, subsystemEvents.poll(id, 5000), ServiceEvent.REGISTERED);
        assertNull("Unexpected event", subsystemEvents.poll(id, 1));
        assertNotConstituent(parent, "bundle4");
        assertConstituent(child, "bundle3");
        child.start();
        try {
            id = parent.getSubsystemId();
            assertEvent(id, "parent", Version.emptyVersion, SubsystemConstants.SUBSYSTEM_TYPE_APPLICATION, State.RESOLVING, subsystemEvents.poll(id, 5000), ServiceEvent.MODIFIED);
            assertEvent(id, "parent", Version.emptyVersion, SubsystemConstants.SUBSYSTEM_TYPE_APPLICATION, State.RESOLVED, subsystemEvents.poll(id, 5000), ServiceEvent.MODIFIED);
            assertEvent(id, "parent", Version.emptyVersion, SubsystemConstants.SUBSYSTEM_TYPE_APPLICATION, State.STARTING, subsystemEvents.poll(id, 5000), ServiceEvent.MODIFIED);
            assertEvent(id, "parent", Version.emptyVersion, SubsystemConstants.SUBSYSTEM_TYPE_APPLICATION, State.ACTIVE, subsystemEvents.poll(id, 5000), ServiceEvent.MODIFIED);
            assertNull("Unexpected event", subsystemEvents.poll(id, 1));
            id = child.getSubsystemId();
            assertEvent(id, "child", Version.emptyVersion, SubsystemConstants.SUBSYSTEM_TYPE_APPLICATION, State.INSTALLED, subsystemEvents.poll(id, 5000), ServiceEvent.MODIFIED);
            assertEvent(id, "child", Version.emptyVersion, SubsystemConstants.SUBSYSTEM_TYPE_APPLICATION, State.RESOLVING, subsystemEvents.poll(id, 5000), ServiceEvent.MODIFIED);
            assertEvent(id, "child", Version.emptyVersion, SubsystemConstants.SUBSYSTEM_TYPE_APPLICATION, State.RESOLVED, subsystemEvents.poll(id, 5000), ServiceEvent.MODIFIED);
            assertEvent(id, "child", Version.emptyVersion, SubsystemConstants.SUBSYSTEM_TYPE_APPLICATION, State.STARTING, subsystemEvents.poll(id, 5000), ServiceEvent.MODIFIED);
            assertEvent(id, "child", Version.emptyVersion, SubsystemConstants.SUBSYSTEM_TYPE_APPLICATION, State.ACTIVE, subsystemEvents.poll(id, 5000), ServiceEvent.MODIFIED);
            assertNull("Unexpected event", subsystemEvents.poll(id, 1));
            assertConstituent(parent, "bundle4");
        } finally {
            stopSubsystemSilently(parent);
        }
    } finally {
        uninstallSubsystemSilently(parent);
    }
}
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 13 with SubsystemArchiveBuilder

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

the class Aries1383Test method test19.

/*
	 * (19) Scoped subsystem with only features as parents is able to override 
	 * the value of apache-aries-provision-dependencies.
	 */
@Test
public void test19() throws Exception {
    Subsystem root = getRootSubsystem();
    subsystemEvents.clear();
    Subsystem feature1 = installSubsystem(root, "feature1", new SubsystemArchiveBuilder().symbolicName("feature1").type(SubsystemConstants.SUBSYSTEM_TYPE_FEATURE).build());
    try {
        Subsystem feature2 = installSubsystem(root, "feature2", new SubsystemArchiveBuilder().symbolicName("feature2").type(SubsystemConstants.SUBSYSTEM_TYPE_FEATURE + ';' + AriesProvisionDependenciesDirective.INSTALL.toString()).build());
        try {
            SubsystemArchiveBuilder applicationArchive = new SubsystemArchiveBuilder().symbolicName("application").type(SubsystemConstants.SUBSYSTEM_TYPE_APPLICATION + ';' + AriesProvisionDependenciesDirective.RESOLVE.toString() + ';' + SubsystemConstants.PROVISION_POLICY_DIRECTIVE + ":=" + SubsystemConstants.PROVISION_POLICY_ACCEPT_DEPENDENCIES).content("bundle1").bundle("bundle1", new BundleArchiveBuilder().symbolicName("bundle1").importPackage("a").build()).bundle("bundle2", new BundleArchiveBuilder().symbolicName("bundle2").exportPackage("a").build());
            Subsystem application1 = feature1.install("application", applicationArchive.build());
            Subsystem application2 = feature2.install("application", applicationArchive.build());
            assertSame("Wrong subsystem", application1, application2);
            assertEquals("Wrong subsystem", application1, application2);
            assertChild(feature1, "application");
            assertChild(feature2, "application");
            long id = application1.getSubsystemId();
            assertEvent(id, "application", Version.emptyVersion, SubsystemConstants.SUBSYSTEM_TYPE_APPLICATION, State.INSTALLING, subsystemEvents.poll(id, 5000), ServiceEvent.REGISTERED);
            assertNull("Unexpected event", subsystemEvents.poll(id, 1));
            assertConstituent(application1, "bundle1");
            assertNotConstituent(application1, "bundle2");
            application1.start();
            try {
                assertEvent(id, "application", Version.emptyVersion, SubsystemConstants.SUBSYSTEM_TYPE_APPLICATION, State.INSTALLED, subsystemEvents.poll(id, 5000), ServiceEvent.MODIFIED);
                assertEvent(id, "application", Version.emptyVersion, SubsystemConstants.SUBSYSTEM_TYPE_APPLICATION, State.RESOLVING, subsystemEvents.poll(id, 5000), ServiceEvent.MODIFIED);
                assertEvent(id, "application", Version.emptyVersion, SubsystemConstants.SUBSYSTEM_TYPE_APPLICATION, State.RESOLVED, subsystemEvents.poll(id, 5000), ServiceEvent.MODIFIED);
                assertEvent(id, "application", Version.emptyVersion, SubsystemConstants.SUBSYSTEM_TYPE_APPLICATION, State.STARTING, subsystemEvents.poll(id, 5000), ServiceEvent.MODIFIED);
                assertEvent(id, "application", Version.emptyVersion, SubsystemConstants.SUBSYSTEM_TYPE_APPLICATION, State.ACTIVE, subsystemEvents.poll(id, 5000), ServiceEvent.MODIFIED);
                assertNull("Unexpected event", subsystemEvents.poll(id, 1));
                assertConstituent(application1, "bundle2");
            } finally {
                stopSubsystemSilently(application1);
            }
        } finally {
            uninstallSubsystemSilently(feature2);
        }
    } finally {
        uninstallSubsystemSilently(feature1);
    }
}
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 14 with SubsystemArchiveBuilder

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

the class Aries1383Test method testImplicitlyInstalledChildOverridesProvisionDependencies.

@Test
public void testImplicitlyInstalledChildOverridesProvisionDependencies() throws Exception {
    Subsystem root = getRootSubsystem();
    subsystemEvents.clear();
    try {
        Subsystem subsystem = root.install("parent", new SubsystemArchiveBuilder().symbolicName("parent").type(SubsystemConstants.SUBSYSTEM_TYPE_APPLICATION + ';' + AriesProvisionDependenciesDirective.INSTALL.toString()).subsystem("child", new SubsystemArchiveBuilder().symbolicName("child").type(SubsystemConstants.SUBSYSTEM_TYPE_APPLICATION + ';' + AriesProvisionDependenciesDirective.RESOLVE.toString()).build()).build());
        uninstallSubsystemSilently(subsystem);
        fail("Subsystem should not have installed");
    } catch (SubsystemException e) {
        e.printStackTrace();
    }
}
Also used : SubsystemArchiveBuilder(org.apache.aries.subsystem.itests.util.SubsystemArchiveBuilder) 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 15 with SubsystemArchiveBuilder

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

the class Aries1383Test method test6.

/*
	 * (6) Subsystem with apache-aries-provision-dependencies:=resolve has its 
	 * dependencies installed after a successful start.
	 */
@Test
public void test6() throws Exception {
    Subsystem root = getRootSubsystem();
    Subsystem subsystem = root.install("application", new SubsystemArchiveBuilder().symbolicName("application").type(SubsystemConstants.SUBSYSTEM_TYPE_APPLICATION + ';' + AriesProvisionDependenciesDirective.RESOLVE.toString()).content("bundle1").bundle("bundle1", new BundleArchiveBuilder().symbolicName("bundle1").exportPackage("a").importPackage("b").build()).bundle("bundle2", new BundleArchiveBuilder().symbolicName("bundle2").exportPackage("b").build()).build());
    try {
        assertNotConstituent(root, "bundle2");
        startSubsystem(subsystem, false);
        try {
            assertConstituent(root, "bundle2");
        } finally {
            stopSubsystemSilently(subsystem);
        }
    } finally {
        uninstallSubsystemSilently(subsystem);
    }
}
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)

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