Search in sources :

Example 16 with InMemoryFeatureStore

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

the class CacheProxyTest method testCacheProxyManager.

@Test
public void testCacheProxyManager() {
    FF4jCacheProxy proxy = new FF4jCacheProxy();
    FF4JCacheManager cm = new InMemoryCacheManager();
    proxy.setCacheManager(cm);
    proxy.isCached();
    Assert.assertNotNull(proxy.getCacheProvider());
    proxy.setTargetPropertyStore(new InMemoryPropertyStore());
    Assert.assertEquals(0, proxy.readAllProperties().size());
    proxy.createProperty(new PropertyString("p1", "v1"));
    Assert.assertTrue(proxy.existProperty("p1"));
    Assert.assertFalse(proxy.existProperty("p2"));
    proxy.setTargetFeatureStore(new InMemoryFeatureStore());
    Set<Feature> setOfFeatures = new HashSet<Feature>();
    setOfFeatures.add(new Feature("f1"));
    setOfFeatures.add(new Feature("f2"));
    proxy.importFeatures(setOfFeatures);
}
Also used : FF4JCacheManager(org.ff4j.cache.FF4JCacheManager) PropertyString(org.ff4j.property.PropertyString) InMemoryPropertyStore(org.ff4j.property.store.InMemoryPropertyStore) InMemoryCacheManager(org.ff4j.cache.InMemoryCacheManager) InMemoryFeatureStore(org.ff4j.store.InMemoryFeatureStore) FF4jCacheProxy(org.ff4j.cache.FF4jCacheProxy) Feature(org.ff4j.core.Feature) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 17 with InMemoryFeatureStore

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

the class InMemoryCacheTest method testExistBis.

@Test
public void testExistBis() {
    FF4jCacheProxy fscp = new FF4jCacheProxy(new InMemoryFeatureStore("ff4j.xml"), null, new InMemoryCacheManager());
    Assert.assertFalse(fscp.exist("toto"));
    Assert.assertFalse(fscp.exist("toto"));
    Assert.assertTrue(fscp.exist("first"));
    Assert.assertTrue(fscp.exist("first"));
}
Also used : InMemoryCacheManager(org.ff4j.cache.InMemoryCacheManager) InMemoryFeatureStore(org.ff4j.store.InMemoryFeatureStore) FF4jCacheProxy(org.ff4j.cache.FF4jCacheProxy) Test(org.junit.Test)

Example 18 with InMemoryFeatureStore

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

the class FF4jTest method enableDisableGroups.

@Test
public void enableDisableGroups() {
    // Given
    FF4j ff4j = new FF4j();
    ff4j.audit();
    ff4j.setFeatureStore(new InMemoryFeatureStore());
    ff4j.createFeature("f1", true);
    ff4j.createFeature("f2");
    ff4j.getFeatureStore().addToGroup("f1", "g1");
    ff4j.getFeatureStore().addToGroup("f2", "g1");
    // When
    ff4j.disableGroup("g1");
    // Then
    Assert.assertFalse(ff4j.getFeature("f1").isEnable());
    Assert.assertFalse(ff4j.getFeature("f2").isEnable());
    // When
    ff4j.enableGroup("g1");
    // Then
    Assert.assertTrue(ff4j.getFeature("f1").isEnable());
    Assert.assertTrue(ff4j.getFeature("f2").isEnable());
    // When
    ff4j.enable("f1");
    ff4j.setFileName(null);
    // Then
    Assert.assertTrue(ff4j.getFeature("f1").isEnable());
}
Also used : FF4j(org.ff4j.FF4j) InMemoryFeatureStore(org.ff4j.store.InMemoryFeatureStore) Test(org.junit.Test)

Example 19 with InMemoryFeatureStore

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

the class FF4jBeanDefinitionParser method postProcess.

/**
 * {@inheritDoc} *
 */
protected void postProcess(final BeanDefinitionBuilder definitionBuilder, final Element ff4jTag) {
    super.postProcess(definitionBuilder, ff4jTag);
    logger.debug("Initialization from <ff4j:ff4j> TAG");
    // If filename is present ff4j will be initialized with both features and properties inmemory.
    if (StringUtils.hasLength(ff4jTag.getAttribute(ATT_FF4J_FILENAME))) {
        String fileName = ff4jTag.getAttribute(ATT_FF4J_FILENAME);
        InMemoryFeatureStore imfs = new InMemoryFeatureStore(fileName);
        InMemoryPropertyStore imps = new InMemoryPropertyStore(fileName);
        definitionBuilder.getBeanDefinition().getPropertyValues().addPropertyValue("featureStore", imfs);
        definitionBuilder.getBeanDefinition().getPropertyValues().addPropertyValue("propertiesStore", imps);
        logger.debug("... Setting in-memory stores : " + imfs.readAll().size() + " feature(s), " + imps.readAllProperties().size() + " propertie(s)");
    }
    if (StringUtils.hasLength(ff4jTag.getAttribute(ATT_FF4J_AUTOCREATE))) {
        String autocreate = ff4jTag.getAttribute(ATT_FF4J_AUTOCREATE);
        logger.debug("... Setting autocreate property to '" + autocreate + "'");
    }
    if (StringUtils.hasLength(ff4jTag.getAttribute(ATT_FF4J_AUTH_MANAGER))) {
        String authManagerBeanId = ff4jTag.getAttribute(ATT_FF4J_AUTH_MANAGER);
        RuntimeBeanReference refSolution = new RuntimeBeanReference(authManagerBeanId);
        definitionBuilder.getBeanDefinition().getPropertyValues().addPropertyValue("authorizationsManager", refSolution);
        logger.debug("... Setting authorizationManager with " + authManagerBeanId);
    }
    logger.debug("... Initialization done");
}
Also used : InMemoryPropertyStore(org.ff4j.property.store.InMemoryPropertyStore) InMemoryFeatureStore(org.ff4j.store.InMemoryFeatureStore) RuntimeBeanReference(org.springframework.beans.factory.config.RuntimeBeanReference)

Example 20 with InMemoryFeatureStore

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

the class CacheProxyTest method testCacheProxyManagerProperty.

@Test
public void testCacheProxyManagerProperty() {
    FF4jCacheProxy proxy = new FF4jCacheProxy();
    proxy.setTargetPropertyStore(new InMemoryPropertyStore());
    proxy.setTargetFeatureStore(new InMemoryFeatureStore());
    proxy.setCacheManager(new InMemoryCacheManager());
    Assert.assertTrue(proxy.isEmpty());
    proxy.create(new Feature("a"));
    Assert.assertFalse(proxy.isEmpty());
    proxy.createProperty(new PropertyString("p1", "v1"));
    Property<?> p1 = proxy.readProperty("p1");
    proxy.readProperty("p1");
    proxy.getTargetPropertyStore().createProperty(new PropertyString("p2"));
    proxy.readProperty("p2");
    proxy.updateProperty("p1", "v2");
    proxy.updateProperty(p1);
    Assert.assertFalse(proxy.isEmpty());
    Assert.assertFalse(proxy.listPropertyNames().isEmpty());
    proxy.deleteProperty("p1");
    proxy.clear();
    Set<Property<?>> setOfProperty = new HashSet<Property<?>>();
    setOfProperty.add(new PropertyLogLevel("a", LogLevel.INFO));
    setOfProperty.add(new PropertyLogLevel("titi1", LogLevel.INFO));
    proxy.importProperties(setOfProperty);
    // Already in cache, but not same value
    proxy.createProperty(new PropertyString("cacheNStore", "cacheNStore"));
    proxy.readProperty("cacheNStore", p1);
    // Not in cache, but in store, but not same default value
    proxy.getTargetPropertyStore().createProperty(new PropertyString("p4", "v4"));
    proxy.readProperty("p1", p1);
    proxy.readProperty("p1", p1);
    // Nowhere, return default
    proxy.readProperty("p2", new PropertyString("p2"));
    proxy.readProperty("p1", new PropertyString("p3"));
}
Also used : PropertyLogLevel(org.ff4j.property.PropertyLogLevel) PropertyString(org.ff4j.property.PropertyString) InMemoryPropertyStore(org.ff4j.property.store.InMemoryPropertyStore) InMemoryCacheManager(org.ff4j.cache.InMemoryCacheManager) InMemoryFeatureStore(org.ff4j.store.InMemoryFeatureStore) FF4jCacheProxy(org.ff4j.cache.FF4jCacheProxy) Feature(org.ff4j.core.Feature) Property(org.ff4j.property.Property) HashSet(java.util.HashSet) 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