Package org.osgi.service.cm

Examples of org.osgi.service.cm.Configuration


    {
        // 1. create config with pid and locationA
        // 2. update config with properties
        final String factoryPid = "test_switch_static_binding_factory";
        final String locationA = "test:location/A/" + factoryPid;
        final Configuration config = createFactoryConfiguration( factoryPid, null, true );
        final String pid = config.getPid();

        TestCase.assertNull( config.getBundleLocation() );

        // 3. register ManagedService ms1 with pid from said locationA
        final Bundle bundleA = installBundle( factoryPid, ManagedServiceFactoryTestActivator.class, locationA );
        bundleA.start();
        delay();

        // ==> configuration supplied to the service ms1
        final ManagedServiceFactoryTestActivator testerA1 = ManagedServiceFactoryTestActivator.INSTANCE;
        TestCase.assertNotNull( testerA1.configs.get( pid ) );
        TestCase.assertEquals( 1, testerA1.numManagedServiceFactoryUpdatedCalls );
        TestCase.assertEquals( locationA, config.getBundleLocation() );

        // 4. register ManagedService ms2 with pid from locationB
        final String locationB = "test:location/B/" + factoryPid;
        final Bundle bundleB = installBundle( factoryPid, ManagedServiceFactoryTestActivator2.class, locationB );
        bundleB.start();
        delay();

        // ==> configuration not supplied to service ms2
        final ManagedServiceFactoryTestActivator2 testerB1 = ManagedServiceFactoryTestActivator2.INSTANCE;
        TestCase.assertNull( testerB1.configs.get( pid ));
        TestCase.assertEquals( 0, testerB1.numManagedServiceFactoryUpdatedCalls );
        TestCase.assertEquals( locationA, config.getBundleLocation() );

        // 5. Uninstall bundle A
        bundleA.uninstall();
        delay();

        // ==> configuration is bound to locationB
        TestCase.assertEquals( locationB, config.getBundleLocation() );

        // ==> configuration supplied to the service ms2
        TestCase.assertNotNull( testerB1.configs.get( pid ) );
        TestCase.assertEquals( 1, testerB1.numManagedServiceFactoryUpdatedCalls );

        // 6. Update configuration now
        config.update();
        delay();

        // ==> configuration supplied to the service ms2
        TestCase.assertNotNull( testerB1.configs.get( pid ) );
        TestCase.assertEquals( 2, testerB1.numManagedServiceFactoryUpdatedCalls );
View Full Code Here


    {
        final String pid = "test.pid";

        configure( pid );

        final Configuration config = getConfiguration( pid );
        TestCase.assertEquals( pid, config.getPid() );
        TestCase.assertNull( config.getBundleLocation() );

        bundle = installBundle( pid, MultiManagedServiceTestActivator.class );
        bundle.start();

        // give cm time for distribution
        delay();

        final MultiManagedServiceTestActivator tester = MultiManagedServiceTestActivator.INSTANCE;
        TestCase.assertNotNull( "Activator not started !!", tester );

        // assert activater has configuration (two calls, one per pid)
        TestCase.assertNotNull( "Expect Properties after Service Registration", tester.props );
        TestCase.assertEquals( "Expect two update calls", 2, tester.numManagedServiceUpdatedCalls );

        TestCase.assertEquals( bundle.getLocation(), config.getBundleLocation() );

        bundle.uninstall();
        bundle = null;

        delay();

        TestCase.assertNull( config.getBundleLocation() );

        // remove the configuration for good
        deleteConfig( pid );
    }
View Full Code Here

        TestCase.assertEquals( "Expect two update calls", 2, tester.numManagedServiceUpdatedCalls );

        configure( pid );
        delay();

        final Configuration config = getConfiguration( pid );
        TestCase.assertEquals( pid, config.getPid() );
        TestCase.assertEquals( bundle.getLocation(), config.getBundleLocation() );

        // assert activater has configuration (two calls, one per pid)
        TestCase.assertNotNull( "Expect Properties after Service Registration", tester.props );
        TestCase.assertEquals( "Expect another two single update call", 4, tester.numManagedServiceUpdatedCalls );

        bundle.uninstall();
        bundle = null;

        delay();

        TestCase.assertNull( config.getBundleLocation() );

        // remove the configuration for good
        deleteConfig( pid );
    }
View Full Code Here

        {
            final String pid = "test.pid";

            configure( pid );

            final Configuration config = getConfiguration( pid );
            TestCase.assertEquals( pid, config.getPid() );
            TestCase.assertNull( config.getBundleLocation() );

            bundle = installBundle( pid, ManagedServiceTestActivator.class );
            bundle.start();

            bundle2 = installBundle( pid, ManagedServiceTestActivator2.class );
            bundle2.start();

            // give cm time for distribution
            delay();

            final ManagedServiceTestActivator tester = ManagedServiceTestActivator.INSTANCE;
            TestCase.assertNotNull( "Activator not started !!", tester );

            final ManagedServiceTestActivator2 tester2 = ManagedServiceTestActivator2.INSTANCE;
            TestCase.assertNotNull( "Activator 2 not started !!", tester2 );

            // expect first activator to have received properties

            // assert first bundle has configuration (one calls, one per srv)
            TestCase.assertNotNull( "Expect Properties after Service Registration", tester.props );
            TestCase.assertEquals( "Expect a single update call", 1, tester.numManagedServiceUpdatedCalls );

            // assert second bundle has no configuration (but called with null)
            TestCase.assertNull( tester2.props );
            TestCase.assertEquals( 1, tester2.numManagedServiceUpdatedCalls );

            // expect configuration bound to first bundle
            TestCase.assertEquals( bundle.getLocation(), config.getBundleLocation() );

            bundle.uninstall();
            bundle = null;

            delay();

            // after uninstallation, the configuration is redispatched
            // due to the dynamic binding being removed

            // expect configuration reassigned
            TestCase.assertEquals( bundle2.getLocation(), config.getBundleLocation() );

            // assert second bundle now has the configuration
            TestCase.assertNotNull( "Expect Properties after Configuration redispatch", tester2.props );
            TestCase.assertEquals( "Expect a single update call after Configuration redispatch", 2,
                tester2.numManagedServiceUpdatedCalls );
View Full Code Here

            configure( pid );

            delay();

            final Configuration config = getConfiguration( pid );
            TestCase.assertEquals( pid, config.getPid() );

            TestCase.assertEquals(
                "Configuration must be bound to first bundle because the service has higher ranking",
                bundle.getLocation(), config.getBundleLocation() );

            // configuration assigned to the first bundle
            TestCase.assertNotNull( "Expect Properties after Service Registration", tester.props );
            TestCase.assertEquals( "Expect a single update call", 2, tester.numManagedServiceUpdatedCalls );

            TestCase.assertNull( "Expect Properties after Service Registration", tester2.props );
            TestCase.assertEquals( "Expect a single update call", 1, tester2.numManagedServiceUpdatedCalls );

            bundle.uninstall();
            bundle = null;

            delay();

            // after uninstallation, the configuration is redispatched
            // due to the dynamic binding being removed

            // expect configuration reassigned
            TestCase.assertEquals( bundle2.getLocation(), config.getBundleLocation() );

            // assert second bundle now has the configuration
            TestCase.assertNotNull( "Expect Properties after Configuration redispatch", tester2.props );
            TestCase.assertEquals( "Expect a single update call after Configuration redispatch", 2,
                tester2.numManagedServiceUpdatedCalls );
View Full Code Here

                                ManagedService.class.getName(),
                                new TestManagedService(managedServiceUpdated), props);
                            managedServices.add(sr);
                            try
                            {
                                Configuration c = ca.getConfiguration(pid, null);
                                c.update(new Hashtable()
                                {
                                    {
                                        put("foo", "bar");
                                    }
                                });
                                confs.add(c);
                            }
                            catch (IOException e)
                            {
                                log.error("could not create pid %s", e, pid);
                                return;
                            }
                        }
                    });
                }

                if (!managedServiceUpdated.await(MAXWAIT, TimeUnit.MILLISECONDS))
                {
                    TestCase.fail("Detected errors logged during concurrent test");
                    break;
                }
                log.info("all managed services updated");

                // Unregister managed services concurrently
                log.info("unregistering services concurrently");
                for (final ServiceRegistration sr : managedServices)
                {
                    executor.execute(new Runnable()
                    {
                        public void run()
                        {
                            sr.unregister();
                            managedServiceUnregistered.countDown();
                        }
                    });
                }

                // Unregister configuration concurrently
                log.info("unregistering configuration concurrently");
                for (final Configuration c : confs)
                {
                    c.delete();
                }

                // Wait until managed services have been unregistered
                if (!managedServiceUnregistered.await(MAXWAIT, TimeUnit.MILLISECONDS))
                {
View Full Code Here

    @Test
    public void test_two_services_same_pid_in_same_bundle_configure_before_registration() throws BundleException
    {
        final String factoryPid = "test.pid";

        final Configuration config = createFactoryConfiguration( factoryPid );
        final String pid = config.getPid();
        TestCase.assertEquals( factoryPid, config.getFactoryPid() );
        TestCase.assertNull( config.getBundleLocation() );

        bundle = installBundle( factoryPid, MultiManagedServiceFactoryTestActivator.class );
        bundle.start();

        // give cm time for distribution
        delay();

        final MultiManagedServiceFactoryTestActivator tester = MultiManagedServiceFactoryTestActivator.INSTANCE;
        TestCase.assertNotNull( "Activator not started !!", tester );

        // assert activater has configuration (two calls, one per pid)
        TestCase.assertNotNull( "Expect Properties after Service Registration", tester.configs.get( pid ) );
        TestCase.assertEquals( "Expect two update calls", 2, tester.numManagedServiceFactoryUpdatedCalls );

        TestCase.assertEquals( bundle.getLocation(), config.getBundleLocation() );

        bundle.uninstall();
        bundle = null;

        delay();

        TestCase.assertNull( config.getBundleLocation() );

        // remove the configuration for good
        deleteConfig( pid );
    }
View Full Code Here

        // no configuration yet
        TestCase.assertTrue( "Expect Properties after Service Registration", tester.configs.isEmpty() );
        TestCase.assertEquals( "Expect two update calls", 0, tester.numManagedServiceFactoryUpdatedCalls );

        final Configuration config = createFactoryConfiguration( factoryPid );
        final String pid = config.getPid();

        delay();

        TestCase.assertEquals( factoryPid, config.getFactoryPid() );
        TestCase.assertEquals( bundle.getLocation(), config.getBundleLocation() );

        // assert activater has configuration (two calls, one per pid)
        TestCase.assertNotNull( "Expect Properties after Service Registration", tester.configs.get( pid ) );
        TestCase.assertEquals( "Expect another two single update call", 2, tester.numManagedServiceFactoryUpdatedCalls );

        bundle.uninstall();
        bundle = null;

        delay();

        TestCase.assertNull( config.getBundleLocation() );

        // remove the configuration for good
        deleteConfig( pid );
    }
View Full Code Here

    {
        Bundle bundle2 = null;
        try
        {
            final String factoryPid = "test.pid";
            final Configuration config = createFactoryConfiguration( factoryPid );
            final String pid = config.getPid();

            TestCase.assertEquals( factoryPid, config.getFactoryPid() );
            TestCase.assertNull( config.getBundleLocation() );

            bundle = installBundle( factoryPid, ManagedServiceFactoryTestActivator.class );
            bundle.start();

            bundle2 = installBundle( factoryPid, ManagedServiceFactoryTestActivator2.class );
            bundle2.start();

            // give cm time for distribution
            delay();

            final ManagedServiceFactoryTestActivator tester = ManagedServiceFactoryTestActivator.INSTANCE;
            TestCase.assertNotNull( "Activator not started !!", tester );

            final ManagedServiceFactoryTestActivator2 tester2 = ManagedServiceFactoryTestActivator2.INSTANCE;
            TestCase.assertNotNull( "Activator 2 not started !!", tester2 );

            // expect first activator to have received properties

            // assert first bundle has configuration (two calls, one per srv)
            TestCase.assertNotNull( "Expect Properties after Service Registration", tester.configs.get( pid ) );
            TestCase.assertEquals( "Expect a single update call", 1, tester.numManagedServiceFactoryUpdatedCalls );

            // assert second bundle has no configuration
            TestCase.assertTrue( tester2.configs.isEmpty() );
            TestCase.assertEquals( 0, tester2.numManagedServiceFactoryUpdatedCalls );

            // expect configuration bound to first bundle
            TestCase.assertEquals( bundle.getLocation(), config.getBundleLocation() );

            bundle.uninstall();
            bundle = null;

            delay();

            // expect configuration reassigned
            TestCase.assertEquals( bundle2.getLocation(), config.getBundleLocation() );
            TestCase.assertNotNull( "Expect Properties after Configuration Redispatch", tester2.configs.get( pid ) );
            TestCase.assertEquals( "Expect update call after Configuration Redispatch", 1, tester2.numManagedServiceFactoryUpdatedCalls );

            // remove the configuration for good
            deleteConfig( pid );
View Full Code Here

            TestCase.assertTrue( "Expect Properties after Service Registration", tester.configs.isEmpty() );
            TestCase.assertEquals( "Expect a single update call", 0, tester.numManagedServiceFactoryUpdatedCalls );
            TestCase.assertTrue( "Expect Properties after Service Registration", tester2.configs.isEmpty() );
            TestCase.assertEquals( "Expect a single update call", 0, tester2.numManagedServiceFactoryUpdatedCalls );

            final Configuration config = createFactoryConfiguration( factoryPid );
            final String pid = config.getPid();

            delay();

            TestCase.assertEquals( factoryPid, config.getFactoryPid() );

            TestCase.assertEquals(
                "Configuration must be bound to second bundle because the service has higher ranking",
                bundle.getLocation(), config.getBundleLocation() );

            // configuration assigned to the first bundle
            TestCase.assertNotNull( "Expect Properties after Service Registration", tester.configs.get( pid ) );
            TestCase.assertEquals( "Expect a single update call", 1, tester.numManagedServiceFactoryUpdatedCalls );

            TestCase.assertTrue( "Expect Properties after Service Registration", tester2.configs.isEmpty() );
            TestCase.assertEquals( "Expect a single update call", 0, tester2.numManagedServiceFactoryUpdatedCalls );

            bundle.uninstall();
            bundle = null;

            delay();

            // expect configuration reassigned
            TestCase.assertEquals( bundle2.getLocation(), config.getBundleLocation() );
            TestCase.assertNotNull( "Expect Properties after Configuration Redispatch", tester2.configs.get( pid ) );
            TestCase.assertEquals( "Expect a single update call after Configuration Redispatch", 1, tester2.numManagedServiceFactoryUpdatedCalls );

            // remove the configuration for good
            deleteConfig( pid );
View Full Code Here

TOP

Related Classes of org.osgi.service.cm.Configuration

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.