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);
}
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"));
}
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());
}
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");
}
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"));
}
Aggregations