Search in sources :

Example 1 with MockNotCachablePersistenceManager

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"));
}
Also used : PersistenceManager(org.apache.felix.cm.PersistenceManager) MockNotCachablePersistenceManager(org.apache.felix.cm.MockNotCachablePersistenceManager) MockPersistenceManager(org.apache.felix.cm.MockPersistenceManager) Hashtable(java.util.Hashtable) PersistenceManagerProxy(org.apache.felix.cm.impl.persistence.PersistenceManagerProxy) CachingPersistenceManagerProxy(org.apache.felix.cm.impl.persistence.CachingPersistenceManagerProxy) MockNotCachablePersistenceManager(org.apache.felix.cm.MockNotCachablePersistenceManager) Test(org.junit.Test)

Example 2 with MockNotCachablePersistenceManager

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());
}
Also used : Dictionary(java.util.Dictionary) Enumeration(java.util.Enumeration) MockNotCachablePersistenceManager(org.apache.felix.cm.MockNotCachablePersistenceManager) MockPersistenceManager(org.apache.felix.cm.MockPersistenceManager) PersistenceManager(org.apache.felix.cm.PersistenceManager) Hashtable(java.util.Hashtable) List(java.util.List) MockNotCachablePersistenceManager(org.apache.felix.cm.MockNotCachablePersistenceManager)

Example 3 with MockNotCachablePersistenceManager

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());
}
Also used : ManagedServiceFactoryTracker(org.apache.felix.cm.impl.helper.ManagedServiceFactoryTracker) CachingPersistenceManagerProxy(org.apache.felix.cm.impl.persistence.CachingPersistenceManagerProxy) Hashtable(java.util.Hashtable) Field(java.lang.reflect.Field) MockBundleContext(org.apache.felix.cm.MockBundleContext) MockNotCachablePersistenceManager(org.apache.felix.cm.MockNotCachablePersistenceManager)

Example 4 with MockNotCachablePersistenceManager

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());
}
Also used : Dictionary(java.util.Dictionary) MockNotCachablePersistenceManager(org.apache.felix.cm.MockNotCachablePersistenceManager) PersistenceManager(org.apache.felix.cm.PersistenceManager) Hashtable(java.util.Hashtable) SimpleFilter(org.apache.felix.cm.impl.SimpleFilter) MockNotCachablePersistenceManager(org.apache.felix.cm.MockNotCachablePersistenceManager)

Aggregations

Hashtable (java.util.Hashtable)4 MockNotCachablePersistenceManager (org.apache.felix.cm.MockNotCachablePersistenceManager)4 PersistenceManager (org.apache.felix.cm.PersistenceManager)3 Dictionary (java.util.Dictionary)2 MockPersistenceManager (org.apache.felix.cm.MockPersistenceManager)2 CachingPersistenceManagerProxy (org.apache.felix.cm.impl.persistence.CachingPersistenceManagerProxy)2 Field (java.lang.reflect.Field)1 Enumeration (java.util.Enumeration)1 List (java.util.List)1 MockBundleContext (org.apache.felix.cm.MockBundleContext)1 SimpleFilter (org.apache.felix.cm.impl.SimpleFilter)1 ManagedServiceFactoryTracker (org.apache.felix.cm.impl.helper.ManagedServiceFactoryTracker)1 PersistenceManagerProxy (org.apache.felix.cm.impl.persistence.PersistenceManagerProxy)1 Test (org.junit.Test)1