use of org.apache.felix.cm.MockNotCachablePersistenceManager in project felix by apache.
the class ConfigurationManagerTest method test_listConfigurations_notcached.
@Test
public void test_listConfigurations_notcached() throws Exception {
String pid = "testDefaultPersistenceManager";
PersistenceManager pm = new MockNotCachablePersistenceManager();
Dictionary<String, Object> dictionary = new Hashtable<>();
dictionary.put("property1", "value1");
dictionary.put(Constants.SERVICE_PID, pid);
pm.store(pid, dictionary);
ConfigurationManager configMgr = new ConfigurationManager(new PersistenceManagerProxy(pm), null);
ConfigurationImpl[] conf = configMgr.listConfigurations(new ConfigurationAdminImpl(configMgr, null), null);
assertEquals(1, conf.length);
assertEquals(2, conf[0].getProperties(true).size());
dictionary = new Hashtable<>();
dictionary.put("property1", "valueNotCached");
pid = "testDefaultPersistenceManager";
dictionary.put(Constants.SERVICE_PID, pid);
pm.store(pid, dictionary);
conf = configMgr.listConfigurations(new ConfigurationAdminImpl(configMgr, null), null);
assertEquals(1, conf.length);
assertEquals(2, conf[0].getProperties(true).size());
// verify that the value returned was not the one from the cache
assertEquals("valueNotCached", conf[0].getProperties(true).get("property1"));
}
use of org.apache.felix.cm.MockNotCachablePersistenceManager in project felix by apache.
the class CachingPersistenceManagerProxyTest method test_caching_is_avoided.
@SuppressWarnings({ "rawtypes", "unchecked" })
public void test_caching_is_avoided() throws Exception {
String pid = "testDefaultPersistenceManager";
SimpleFilter filter = SimpleFilter.parse("(&(service.pid=" + pid + ")(property1=value1))");
PersistenceManager pm = new MockNotCachablePersistenceManager();
CachingPersistenceManagerProxy cpm = new CachingPersistenceManagerProxy(pm);
Dictionary dictionary = new Hashtable();
dictionary.put("property1", "value1");
dictionary.put(Constants.SERVICE_PID, pid);
pm.store(pid, dictionary);
Enumeration dictionaries = cpm.getDictionaries(filter);
List list = Collections.list(dictionaries);
assertEquals(1, list.size());
dictionary = new Hashtable();
dictionary.put("property1", "value2");
pid = "testDefaultPersistenceManager";
dictionary.put(Constants.SERVICE_PID, pid);
pm.store(pid, dictionary);
dictionaries = cpm.getDictionaries(filter);
list = Collections.list(dictionaries);
assertEquals(1, list.size());
}
use of org.apache.felix.cm.MockNotCachablePersistenceManager in project felix by apache.
the class ConfigurationManagerTest method test_factoryConfigurationCleanup.
public void test_factoryConfigurationCleanup() throws Exception {
MockNotCachablePersistenceManager pm = new MockNotCachablePersistenceManager();
ConfigurationManager configMgr = new ConfigurationManager(new CachingPersistenceManagerProxy(pm), null);
final Field bcField = configMgr.getClass().getDeclaredField("bundleContext");
bcField.setAccessible(true);
bcField.set(configMgr, new MockBundleContext());
setServiceTrackerField(configMgr, "persistenceManagerTracker");
setServiceTrackerField(configMgr, "logTracker");
setServiceTrackerField(configMgr, "configurationListenerTracker");
setServiceTrackerField(configMgr, "syncConfigurationListenerTracker");
final Field mstField = configMgr.getClass().getDeclaredField("managedServiceFactoryTracker");
mstField.setAccessible(true);
mstField.set(configMgr, new ManagedServiceFactoryTracker(configMgr) {
@Override
public void open() {
}
});
final Field utField = configMgr.getClass().getDeclaredField("updateThread");
utField.setAccessible(true);
utField.set(configMgr, new UpdateThread(null, "Test updater") {
@Override
void schedule(Runnable update) {
update.run();
}
});
final String factoryPid = "my.factory";
final Dictionary<String, Object> props = new Hashtable<>();
props.put("hello", "world");
final ConfigurationImpl c1 = configMgr.createFactoryConfiguration(factoryPid, null);
c1.update(props);
final ConfigurationImpl c2 = configMgr.createFactoryConfiguration(factoryPid, null);
c2.update(props);
final ConfigurationImpl c3 = configMgr.createFactoryConfiguration(factoryPid, null);
c3.update(props);
assertEquals(4, pm.getStored().size());
c1.delete();
assertEquals(3, pm.getStored().size());
c2.delete();
assertEquals(2, pm.getStored().size());
c3.delete();
assertEquals(0, pm.getStored().size());
}
use of org.apache.felix.cm.MockNotCachablePersistenceManager in project felix by apache.
the class PersistenceManagerProxyTest method test_caching_is_avoided.
@SuppressWarnings({ "rawtypes", "unchecked" })
public void test_caching_is_avoided() throws Exception {
String pid = "testDefaultPersistenceManager";
SimpleFilter filter = SimpleFilter.parse("(&(service.pid=" + pid + ")(property1=value1))");
PersistenceManager pm = new MockNotCachablePersistenceManager();
PersistenceManagerProxy cpm = new PersistenceManagerProxy(pm);
Dictionary dictionary = new Hashtable();
dictionary.put("property1", "value1");
dictionary.put(Constants.SERVICE_PID, pid);
pm.store(pid, dictionary);
Collection<Dictionary> list = cpm.getDictionaries(filter);
assertEquals(1, list.size());
dictionary = new Hashtable();
dictionary.put("property1", "value2");
pid = "testDefaultPersistenceManager";
dictionary.put(Constants.SERVICE_PID, pid);
pm.store(pid, dictionary);
list = cpm.getDictionaries(filter);
assertEquals(0, list.size());
}
Aggregations