use of org.infinispan.counter.api.CounterConfiguration in project infinispan by infinispan.
the class ExpirationStrongCounterTest method testUnboundedCounter.
public void testUnboundedCounter() {
CounterConfiguration config = CounterConfiguration.builder(CounterType.UNBOUNDED_STRONG).lifespan(EXPIRATION_MILLISECONDS).build();
String counterName = "unbounded-counter";
CounterManager counterManager = counterManager();
counterManager.defineCounter(counterName, config);
doTest(counterName, -1);
}
use of org.infinispan.counter.api.CounterConfiguration in project infinispan by infinispan.
the class RestOperations method testCounter.
@Test
public void testCounter() {
RestClientConfigurationBuilder builder = new RestClientConfigurationBuilder();
builder.protocol(protocol);
RestClient client = SERVER_TEST.rest().withClientConfiguration(builder).create();
CounterConfiguration configuration = CounterConfiguration.builder(CounterType.WEAK).initialValue(5).concurrencyLevel(1).build();
AbstractCounterConfiguration config = ConvertUtil.configToParsedConfig("test-counter", configuration);
String configJson = AbstractRestResourceTest.counterConfigToJson(config);
RestCounterClient counter = client.counter("test");
RestResponse rsp = sync(counter.create(RestEntity.create(MediaType.APPLICATION_JSON, configJson)));
assertEquals(HttpResponseStatus.OK.code(), rsp.getStatus());
rsp = sync(counter.get());
assertEquals("5", rsp.getBody());
}
use of org.infinispan.counter.api.CounterConfiguration in project infinispan by infinispan.
the class CounterManagerImplTestStrategy method testLowerBoundedStrongCounter.
@Override
public void testLowerBoundedStrongCounter(Method method) {
final Random random = generateRandom();
final String counterName = method.getName();
CounterConfiguration config = builder(CounterType.BOUNDED_STRONG).initialValue(15).lowerBound(5).storage(random.nextBoolean() ? Storage.VOLATILE : Storage.PERSISTENT).build();
doCreationTest(counterName, config);
}
use of org.infinispan.counter.api.CounterConfiguration in project infinispan by infinispan.
the class CounterManagerImplTestStrategy method testUnboundedStrongCounter.
@Override
public void testUnboundedStrongCounter(Method method) {
final Random random = generateRandom();
final String counterName = method.getName();
CounterConfiguration config = builder(CounterType.UNBOUNDED_STRONG).initialValue(random.nextInt()).storage(random.nextBoolean() ? Storage.VOLATILE : Storage.PERSISTENT).build();
doCreationTest(counterName, config);
}
use of org.infinispan.counter.api.CounterConfiguration in project infinispan by infinispan.
the class CounterManagerImplTestStrategy method testRemove.
@Override
public void testRemove(Method method) {
// we need to cleanup other tests counters from the caches because of cache.size()
clearCaches();
final Random random = generateRandom();
final String counterName = method.getName();
final CounterManager counterManager = getTestedCounterManager();
CounterConfiguration config = builder(CounterType.UNBOUNDED_STRONG).initialValue(random.nextLong()).build();
assertTrue(counterManager.defineCounter(counterName, config));
awaitCounterOperation(counterManager.getStrongCounter(counterName).addAndGet(10));
EmbeddedCacheManager cacheManager = cacheManagerSupplier.get();
Cache<?, ?> cache = cacheManager.getCache(CounterModuleLifecycle.COUNTER_CACHE_NAME);
assertEquals(1, cache.size());
counterManager.remove(counterName);
assertEquals(0, cache.size());
}
Aggregations