Search in sources :

Example 21 with InMemoryFeatureStore

use of org.ff4j.store.InMemoryFeatureStore in project ff4j by ff4j.

the class MappingUtilsTest method testJsonMapping.

@Test
public void testJsonMapping() {
    JsonUtils.permissionsAsJson(null);
    JsonUtils.customPropertiesAsJson(null);
    JsonUtils.customPropertiesAsJson(new HashMap<String, Property<?>>());
    FeatureStore store1 = new InMemoryFeatureStore();
    FF4jCacheProxy proxy = new FF4jCacheProxy(store1, null, null);
    JsonUtils.cacheJson(proxy);
}
Also used : InMemoryFeatureStore(org.ff4j.store.InMemoryFeatureStore) PropertyString(org.ff4j.property.PropertyString) FF4jCacheProxy(org.ff4j.cache.FF4jCacheProxy) Property(org.ff4j.property.Property) InMemoryFeatureStore(org.ff4j.store.InMemoryFeatureStore) FeatureStore(org.ff4j.core.FeatureStore) Test(org.junit.Test)

Example 22 with InMemoryFeatureStore

use of org.ff4j.store.InMemoryFeatureStore in project ff4j by ff4j.

the class FF4j method loadConfiguration.

protected void loadConfiguration(FF4jConfiguration config) {
    this.fstore = new InMemoryFeatureStore(config);
    this.pStore = new InMemoryPropertyStore(config);
}
Also used : InMemoryPropertyStore(org.ff4j.property.store.InMemoryPropertyStore) InMemoryFeatureStore(org.ff4j.store.InMemoryFeatureStore)

Example 23 with InMemoryFeatureStore

use of org.ff4j.store.InMemoryFeatureStore in project ff4j by ff4j.

the class CacheProxyWithPollingTest method testCacheProxyManagerPropertyDuringRefresh.

@Test
public void testCacheProxyManagerPropertyDuringRefresh() throws InterruptedException {
    FeatureStore fs = new InMemoryFeatureStore("ff4j.xml");
    PropertyStore ps = new InMemoryPropertyStore("ff4j.xml");
    FF4JCacheManager cm = new InMemoryCacheManager();
    final FF4jCacheProxy proxy = new FF4jCacheProxy(fs, ps, cm);
    // scheduler refreshing cache through worker thread
    Store2CachePollingScheduler store2CachePollingScheduler = new Store2CachePollingScheduler(proxy);
    // setting polling delay 10ms
    store2CachePollingScheduler.start(10);
    // 20 threads trying to fetch property from cacheManager
    ExecutorService fetchPropertyService = Executors.newFixedThreadPool(20);
    Callable<Property<?>> callable = new Callable<Property<?>>() {

        @Override
        public Property<?> call() throws Exception {
            try {
                return proxy.getCacheManager().getProperty("a");
            } catch (Exception e) {
                throw e;
            }
        }
    };
    List<Callable<Property<?>>> multiplePropertyFetchCalls = new ArrayList<Callable<Property<?>>>(1000);
    // generating 100000 requests
    for (int i = 0; i < 100; i++) {
        for (int j = 0; j < 10; j++) {
            // clear to avoid accumulation of callables over multiple iterations
            multiplePropertyFetchCalls.clear();
        }
        for (int k = 0; k < 100; k++) {
            multiplePropertyFetchCalls.add(callable);
        }
        // execute 100 property fetch calls on 20 threads
        List<Future<Property<?>>> fetchPropertyCalls = fetchPropertyService.invokeAll(multiplePropertyFetchCalls);
        // property should never be null
        for (Future<Property<?>> property : fetchPropertyCalls) {
            Assert.assertNotNull(property);
        }
    }
}
Also used : FF4JCacheManager(org.ff4j.cache.FF4JCacheManager) InMemoryPropertyStore(org.ff4j.property.store.InMemoryPropertyStore) ArrayList(java.util.ArrayList) Callable(java.util.concurrent.Callable) InMemoryCacheManager(org.ff4j.cache.InMemoryCacheManager) InMemoryFeatureStore(org.ff4j.store.InMemoryFeatureStore) ExecutorService(java.util.concurrent.ExecutorService) Future(java.util.concurrent.Future) FF4jCacheProxy(org.ff4j.cache.FF4jCacheProxy) Property(org.ff4j.property.Property) InMemoryFeatureStore(org.ff4j.store.InMemoryFeatureStore) FeatureStore(org.ff4j.core.FeatureStore) Store2CachePollingScheduler(org.ff4j.cache.Store2CachePollingScheduler) InMemoryPropertyStore(org.ff4j.property.store.InMemoryPropertyStore) PropertyStore(org.ff4j.property.store.PropertyStore) Test(org.junit.Test)

Example 24 with InMemoryFeatureStore

use of org.ff4j.store.InMemoryFeatureStore in project ff4j by ff4j.

the class InMemoryFeatureStoreTest method testUnitFeatureInitialization.

@Test
public void testUnitFeatureInitialization() {
    InMemoryFeatureStore imfs = new InMemoryFeatureStore();
    imfs.create(new Feature("default", true, "grp1", "desc", null, new PonderationStrategy()));
    Assert.assertEquals(1, imfs.readAll().size());
}
Also used : PonderationStrategy(org.ff4j.strategy.PonderationStrategy) InMemoryFeatureStore(org.ff4j.store.InMemoryFeatureStore) Feature(org.ff4j.core.Feature) Test(org.junit.Test)

Example 25 with InMemoryFeatureStore

use of org.ff4j.store.InMemoryFeatureStore in project ff4j by ff4j.

the class InMemoryFeatureStoreTest method testDonotImportEmpty.

@Test(expected = IllegalArgumentException.class)
public void testDonotImportEmpty() {
    InMemoryFeatureStore f = new InMemoryFeatureStore();
    f.importFeaturesFromXmlFile("");
}
Also used : InMemoryFeatureStore(org.ff4j.store.InMemoryFeatureStore) Test(org.junit.Test)

Aggregations

InMemoryFeatureStore (org.ff4j.store.InMemoryFeatureStore)35 Test (org.junit.Test)20 InMemoryPropertyStore (org.ff4j.property.store.InMemoryPropertyStore)16 FF4jCacheProxy (org.ff4j.cache.FF4jCacheProxy)6 Feature (org.ff4j.core.Feature)6 InMemoryCacheManager (org.ff4j.cache.InMemoryCacheManager)5 FF4j (org.ff4j.FF4j)4 FeatureStore (org.ff4j.core.FeatureStore)4 FF4JCacheManager (org.ff4j.cache.FF4JCacheManager)3 FlippingExecutionContext (org.ff4j.core.FlippingExecutionContext)3 Property (org.ff4j.property.Property)3 PropertyString (org.ff4j.property.PropertyString)3 AbstractFf4jTest (org.ff4j.test.AbstractFf4jTest)3 Before (org.junit.Before)3 HashSet (java.util.HashSet)2 Store2CachePollingScheduler (org.ff4j.cache.Store2CachePollingScheduler)2 FlippingStrategy (org.ff4j.core.FlippingStrategy)2 PropertyStore (org.ff4j.property.store.PropertyStore)2 ClientResponse (com.sun.jersey.api.client.ClientResponse)1 ArrayList (java.util.ArrayList)1