public void clean() { try { for (; ; ) { Configuration[] configs = configurationAdmin.listConfigurations( "(|(service.factoryPid=org.fusesource.fabric.zookeeper.server)(service.pid=org.fusesource.fabric.zookeeper))"); if (configs != null && configs.length > 0) { for (Configuration config : configs) { config.delete(); } Thread.sleep(100); } else { break; } } File zkDir = new File("data/zookeeper"); if (zkDir.isDirectory()) { File newZkDir = new File("data/zookeeper." + System.currentTimeMillis()); if (!zkDir.renameTo(newZkDir)) { newZkDir = zkDir; } delete(newZkDir); } } catch (Exception e) { throw new FabricException("Unable to delete zookeeper configuration", e); } }
public static void removeModeShapeRepositoryConfigurations(BundleContext bundleContext) throws IOException, InvalidSyntaxException { Configuration[] modeShapeRepositoryConfigurations = getModeShapeConfigurations(bundleContext); for (Configuration modeShapeConfiguration : modeShapeRepositoryConfigurations) { modeShapeConfiguration.delete(); } }
private void loggingDeactivate(final ConfigurationAdmin configAdmin) throws Exception { final org.osgi.service.cm.Configuration config = configAdmin.getConfiguration(PAX_PID, null); config.delete(); Thread.sleep(500); }
protected void deleteConfig(final String pid) { final ConfigurationAdmin ca = getConfigurationAdmin(); try { final Configuration config = ca.getConfiguration(pid); config.delete(); } catch (IOException ioe) { TestCase.fail("Failed deleting configuration " + pid + ": " + ioe.toString()); } }
@Test public void testConfigurationEventDeleted() throws Exception { String testPid = SecuredCommandConfigTransformer.PROXY_COMMAND_ACL_PID_PREFIX + "test123"; ConfigurationAdmin cm = EasyMock.createMock(ConfigurationAdmin.class); EasyMock.expect(cm.listConfigurations(EasyMock.isA(String.class))).andReturn(null).anyTimes(); EasyMock.replay(cm); SecuredCommandConfigTransformer scct = new SecuredCommandConfigTransformer(); scct.setConfigAdmin(cm); scct.init(); @SuppressWarnings("unchecked") ServiceReference<ConfigurationAdmin> cmRef = EasyMock.createMock(ServiceReference.class); EasyMock.replay(cmRef); ConfigurationEvent event = new ConfigurationEvent(cmRef, ConfigurationEvent.CM_DELETED, null, testPid); Configuration c1 = EasyMock.createMock(Configuration.class); c1.delete(); EasyMock.expectLastCall().once(); EasyMock.replay(c1); Configuration c2 = EasyMock.createMock(Configuration.class); c2.delete(); EasyMock.expectLastCall().once(); EasyMock.replay(c2); EasyMock.reset(cm); EasyMock.expect( cm.listConfigurations("(service.pid=org.apache.karaf.service.acl.command.test123.*)")) .andReturn(new Configuration[] {c1, c2}) .once(); EasyMock.replay(cm); scct.configurationEvent(event); EasyMock.verify(cm); EasyMock.verify(c1); EasyMock.verify(c2); }
protected void deleteFactoryConfigurations(String factoryPid) { ConfigurationAdmin ca = getConfigurationAdmin(); try { final String filter = "(service.factoryPid=" + factoryPid + ")"; Configuration[] configs = ca.listConfigurations(filter); if (configs != null) { for (Configuration configuration : configs) { configuration.delete(); } } } catch (InvalidSyntaxException ise) { // unexpected } catch (IOException ioe) { TestCase.fail("Failed deleting configurations " + factoryPid + ": " + ioe.toString()); } }
@Before public void setUp() throws InvalidSyntaxException, IOException { _serviceReference = _bundleContext.getServiceReference(ConfigurationAdmin.class); _configurationAdmin = _bundleContext.getService(_serviceReference); Configuration[] configurations = _configurationAdmin.listConfigurations(null); if (configurations != null) { for (Configuration configuration : configurations) { configuration.delete(); } } configurations = _configurationAdmin.listConfigurations(null); Assert.assertNull(configurations); }
@Override public void deleteProviderFactoryInstance(String factoryUID, String instanceUID) { synchronized (factories) { // delete factory reference settingDao.deleteSetting(getFactorySettingKey(factoryUID), instanceUID); // delete instance values settingDao.deleteSetting(getFactoryInstanceSettingKey(factoryUID, instanceUID)); // delete Configuration try { Configuration conf = getConfiguration(factoryUID, instanceUID); conf.delete(); } catch (IOException e) { throw new RuntimeException(e); } catch (InvalidSyntaxException e) { throw new RuntimeException(e); } } }
protected void cleanupConfigurationAdmin() throws IOException, InvalidSyntaxException { Configuration[] configurations = admin.listConfigurations(null); if (configurations != null) { for (Configuration conf : configurations) { if (!conf.getPid().contains("instantiated.at.boot")) { conf.delete(); } } } await() .atMost(1, TimeUnit.MINUTES) .until( new Callable<Boolean>() { @Override public Boolean call() throws Exception { return osgi.getServiceObject(MyComponent.class) == null; } }); }
@Test public void testDynamicInstantiationAndDeletionUsingConfigurationFactory() throws IOException, InterruptedException { assertThat(osgi.getServiceObject(MyComponent.class)).isNull(); final Configuration configuration = admin.createFactoryConfiguration("org.wisdom.conf"); Properties properties = new Properties(); properties.put("user", "wisdom"); configuration.update(properties); await() .atMost(1, TimeUnit.MINUTES) .until( new Callable<Boolean>() { @Override public Boolean call() throws Exception { return osgi.getServiceObject(MyComponent.class) != null; } }); MyComponent service = osgi.getServiceObject(MyComponent.class); assertThat(service).isNotNull(); assertThat(service.hello()).contains("wisdom"); // Deleting the configuration configuration.delete(); await() .atMost(1, TimeUnit.MINUTES) .until( new Callable<Boolean>() { @Override public Boolean call() throws Exception { return osgi.getServiceObject(MyComponent.class) == null; } }); assertThat(osgi.getServiceObject(MyComponent.class)).isNull(); }
@Invalidate void stop() throws IOException { destination.delete(); }
@Test public void test_two_bundles_one_pid() throws BundleException, IOException { // 1. Bundle registers service with pid1 final String pid = "test_two_bundles_one_pid"; final Bundle bundleA = installBundle(pid, ManagedServiceTestActivator.class); final String locationA = bundleA.getLocation(); bundleA.start(); delay(); // call back with null final ManagedServiceTestActivator tester = ManagedServiceTestActivator.INSTANCE; TestCase.assertNull(tester.props); TestCase.assertEquals(1, tester.numManagedServiceUpdatedCalls); // 2. create new Conf with pid1 and locationA. final Configuration config = configure(pid, locationA, false); delay(); // ==> No call back. TestCase.assertNull(tester.props); TestCase.assertEquals(1, tester.numManagedServiceUpdatedCalls); // 3. Configuration#update(prop) is called. config.update(theConfig); delay(); // ==> call back with the prop. TestCase.assertNotNull(tester.props); TestCase.assertEquals(2, tester.numManagedServiceUpdatedCalls); // 4. Stop BundleA bundleA.stop(); delay(); // 5. Start BundleA bundleA.start(); delay(); // ==> call back with the prop. final ManagedServiceTestActivator tester2 = ManagedServiceTestActivator.INSTANCE; TestCase.assertNotNull(tester2.props); TestCase.assertEquals(1, tester2.numManagedServiceUpdatedCalls); // 6. Configuration#deleted() is called. config.delete(); delay(); // ==> call back with null. TestCase.assertNull(tester2.props); TestCase.assertEquals(2, tester2.numManagedServiceUpdatedCalls); // 7. uninstall Bundle A for cleanup. bundleA.uninstall(); delay(); // Test 2 // 8. BundleA registers ManagedService with pid1. final Bundle bundleA2 = installBundle(pid, ManagedServiceTestActivator.class); final String locationA2 = bundleA.getLocation(); bundleA2.start(); delay(); // call back with null final ManagedServiceTestActivator tester21 = ManagedServiceTestActivator.INSTANCE; TestCase.assertNull(tester21.props); TestCase.assertEquals(1, tester21.numManagedServiceUpdatedCalls); // 9. create new Conf with pid1 and locationB. final String locationB = "test:locationB/" + pid; final Configuration configB = configure(pid, locationB, false); delay(); // ==> No call back. TestCase.assertNull(tester21.props); TestCase.assertEquals(1, tester21.numManagedServiceUpdatedCalls); // 10. Configuration#update(prop) is called. configB.update(theConfig); delay(); // ==> No call back because the Conf is not bound to locationA. TestCase.assertNull(tester21.props); TestCase.assertEquals(1, tester21.numManagedServiceUpdatedCalls); }