use of org.infinispan.counter.api.CounterConfiguration in project infinispan by infinispan.
the class CounterManagerImplTestStrategy method testBoundedStrongCounter.
@Override
public void testBoundedStrongCounter(Method method) {
final Random random = generateRandom();
final String counterName = method.getName();
CounterConfiguration config = builder(CounterType.BOUNDED_STRONG).initialValue(15).lowerBound(5).upperBound(20).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 TestCounterManager method getStrongCounter.
@Override
public StrongCounter getStrongCounter(String name) {
StrongCounter c = (StrongCounter) counters.get(name);
if (c == null) {
CounterConfiguration config = getConfiguration(name);
if (config == null || config.type() == CounterType.WEAK) {
throw new IllegalStateException();
}
c = new TestStrongCounter(name, config, client, notificationManager);
counters.put(name, c);
}
return c;
}
use of org.infinispan.counter.api.CounterConfiguration in project infinispan by infinispan.
the class TestCounterManager method getWeakCounter.
@Override
public WeakCounter getWeakCounter(String name) {
WeakCounter c = (WeakCounter) counters.get(name);
if (c == null) {
CounterConfiguration config = getConfiguration(name);
if (config == null || config.type() != CounterType.WEAK) {
throw new IllegalStateException();
}
c = new TestWeakCounter(name, config, client, notificationManager);
counters.put(name, c);
}
return c;
}
use of org.infinispan.counter.api.CounterConfiguration in project infinispan by infinispan.
the class CounterManagerImplTestStrategy method testWeakCounter.
@Override
public void testWeakCounter(Method method) {
final Random random = generateRandom();
final String counterName = method.getName();
CounterConfiguration config = builder(CounterType.WEAK).initialValue(random.nextInt()).storage(random.nextBoolean() ? Storage.VOLATILE : Storage.PERSISTENT).concurrencyLevel(abs(random.nextInt())).build();
doCreationTest(counterName, config);
}
use of org.infinispan.counter.api.CounterConfiguration in project infinispan by infinispan.
the class CounterResource method executeCommonCounterOp.
private CompletionStage<RestResponse> executeCommonCounterOp(RestRequest request, Function<WeakCounter, CompletionStage<Void>> weakOp, Function<StrongCounter, CompletableFuture<Long>> strongOp) {
String counterName = request.variables().get("counterName");
CompletableFuture<CounterConfiguration> counterConfigAsync = invocationHelper.getCounterManager().getConfigurationAsync(counterName);
return counterConfigAsync.thenCompose(configuration -> {
if (configuration == null)
return notFoundResponseFuture();
CounterType type = configuration.type();
if (type == CounterType.WEAK)
return executeWeakCounterOp(counterName, weakOp);
return executeStrongCounterOp(counterName, strongOp);
});
}
Aggregations