Search in sources :

Example 1 with CounterConfiguration

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);
}
Also used : CounterManager(org.infinispan.counter.api.CounterManager) CounterConfiguration(org.infinispan.counter.api.CounterConfiguration)

Example 2 with CounterConfiguration

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());
}
Also used : RestCounterClient(org.infinispan.client.rest.RestCounterClient) RestClientConfigurationBuilder(org.infinispan.client.rest.configuration.RestClientConfigurationBuilder) RestResponse(org.infinispan.client.rest.RestResponse) RestClient(org.infinispan.client.rest.RestClient) AbstractCounterConfiguration(org.infinispan.counter.configuration.AbstractCounterConfiguration) AbstractCounterConfiguration(org.infinispan.counter.configuration.AbstractCounterConfiguration) CounterConfiguration(org.infinispan.counter.api.CounterConfiguration) AbstractRestResourceTest(org.infinispan.rest.resources.AbstractRestResourceTest) Test(org.junit.Test)

Example 3 with CounterConfiguration

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);
}
Also used : Random(java.util.Random) CounterConfiguration(org.infinispan.counter.api.CounterConfiguration)

Example 4 with CounterConfiguration

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);
}
Also used : Random(java.util.Random) CounterConfiguration(org.infinispan.counter.api.CounterConfiguration)

Example 5 with CounterConfiguration

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());
}
Also used : Random(java.util.Random) EmbeddedCacheManager(org.infinispan.manager.EmbeddedCacheManager) CounterManager(org.infinispan.counter.api.CounterManager) CounterConfiguration(org.infinispan.counter.api.CounterConfiguration)

Aggregations

CounterConfiguration (org.infinispan.counter.api.CounterConfiguration)30 CounterManager (org.infinispan.counter.api.CounterManager)8 Random (java.util.Random)7 AbstractCounterConfiguration (org.infinispan.counter.configuration.AbstractCounterConfiguration)7 StrongCounter (org.infinispan.counter.api.StrongCounter)4 RestResponse (org.infinispan.client.rest.RestResponse)3 CounterType (org.infinispan.counter.api.CounterType)3 WeakCounter (org.infinispan.counter.api.WeakCounter)3 DataInputStream (java.io.DataInputStream)2 IOException (java.io.IOException)2 ZipEntry (java.util.zip.ZipEntry)2 RestCounterClient (org.infinispan.client.rest.RestCounterClient)2 CacheException (org.infinispan.commons.CacheException)2 BlockingManager (org.infinispan.util.concurrent.BlockingManager)2 Flowable (io.reactivex.rxjava3.core.Flowable)1 DataOutputStream (java.io.DataOutputStream)1 OutputStream (java.io.OutputStream)1 Files (java.nio.file.Files)1 Path (java.nio.file.Path)1 ArrayList (java.util.ArrayList)1