use of org.ff4j.property.Property in project ff4j by ff4j.
the class Store2CachePollingWorker method run.
/**
* {@inheritDoc}
*/
@Override
public void run() {
try {
FF4JCacheManager cacheManager;
if (ff4JCacheProxy != null) {
cacheManager = new InMemoryCacheManager();
} else {
cacheManager = this.cacheManager;
}
if (sourceFeatureStore != null) {
// Access the store, if failed an error is raised and cache is not cleared.
Map<String, Feature> mapOfFeatures = sourceFeatureStore.readAll();
// Clear cache
cacheManager.clearFeatures();
// Fill Cache
for (Feature f : mapOfFeatures.values()) {
cacheManager.putFeature(f);
}
}
if (sourcePropertyStore != null) {
// Access the store, if failed an error is raised and cache is not cleared.
Map<String, Property<?>> mapOfProperties = sourcePropertyStore.readAllProperties();
// Clear cache
cacheManager.clearProperties();
// Fill Cache
for (Property<?> p : mapOfProperties.values()) {
cacheManager.putProperty(p);
}
}
if (ff4JCacheProxy != null) {
ff4JCacheProxy.setCacheManager(cacheManager);
}
} catch (Exception ex) {
// Work in background (worker) failed 'silently'
ex.printStackTrace();
}
}
use of org.ff4j.property.Property in project ff4j by ff4j.
the class FeatureJsonParserTest method assertMarshalling.
/**
* Check serialized string against json serializer.
*
* @param json
* json value
* @param feat
* feature
*/
private void assertMarshalling(Feature feat) throws Exception {
Map<String, Property<?>> props = feat.getCustomProperties();
if (props != null && !props.isEmpty()) {
// Custom properties are unforce to PropertyJsonBean
for (String pName : props.keySet()) {
PropertyJsonBean pjb = new PropertyJsonBean(props.get(pName));
Assert.assertEquals(marshallWithJackson(pjb), pjb.asJson());
}
feat.setCustomProperties(new HashMap<String, Property<?>>());
}
Assert.assertEquals(marshallWithJackson(feat), feat.toJson());
feat.setCustomProperties(props);
}
use of org.ff4j.property.Property 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);
}
}
}
use of org.ff4j.property.Property in project ff4j by ff4j.
the class FeatureXmlParserTest method testParsingProperties.
@Test
public void testParsingProperties() throws IOException {
// Given
XmlParser parser = new XmlParser();
InputStream in = getClass().getClassLoader().getResourceAsStream("ff4j-parser-properties.xml");
// When
XmlConfig conf = parser.parseConfigurationFile(in);
// Then
Map<String, Feature> features = conf.getFeatures();
Assert.assertNotNull(features);
// Then
Map<String, Property<?>> properties = conf.getProperties();
Assert.assertNotNull(properties);
}
use of org.ff4j.property.Property in project ff4j by ff4j.
the class InMemoryPropertiesStoreTest method testInvalidXML.
@Test(expected = IllegalArgumentException.class)
public void testInvalidXML() {
new InMemoryPropertyStore(new HashMap<String, Property<?>>());
InputStream in = getClass().getClassLoader().getResourceAsStream("invalid.xml");
new InMemoryPropertyStore(in);
}
Aggregations