use of org.infinispan.counter.configuration.AbstractCounterConfiguration in project infinispan by infinispan.
the class ConfigurationTest method assertBoundedStrongCounter.
private void assertBoundedStrongCounter(CounterManagerConfiguration config, String name, long initialValue, long min, long max, long lifespan, Storage storage) {
for (AbstractCounterConfiguration counterConfig : config.counters().values()) {
if (counterConfig.name().equals(name)) {
assertTrue(counterConfig instanceof StrongCounterConfiguration);
assertEquals(initialValue, counterConfig.initialValue());
assertEquals(storage, counterConfig.storage());
assertTrue(((StrongCounterConfiguration) counterConfig).isBound());
assertEquals(min, ((StrongCounterConfiguration) counterConfig).lowerBound());
assertEquals(max, ((StrongCounterConfiguration) counterConfig).upperBound());
assertEquals(lifespan, ((StrongCounterConfiguration) counterConfig).lifespan());
return;
}
}
fail();
}
use of org.infinispan.counter.configuration.AbstractCounterConfiguration 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.configuration.AbstractCounterConfiguration in project infinispan by infinispan.
the class MultiResourceTest method createCounters.
private void createCounters(String... names) {
CounterConfiguration configuration = CounterConfiguration.builder(CounterType.BOUNDED_STRONG).lowerBound(0).upperBound(100).initialValue(0).build();
for (String counterName : names) {
AbstractCounterConfiguration config = ConvertUtil.configToParsedConfig(counterName, configuration);
RestResponse response = join(client.counter(counterName).create(RestEntity.create(APPLICATION_JSON, counterConfigToJson(config))));
ResponseAssertion.assertThat(response).isOk();
}
}
use of org.infinispan.counter.configuration.AbstractCounterConfiguration in project infinispan by infinispan.
the class ConfigurationSerializerTest method compareExtraGlobalConfiguration.
@Override
protected void compareExtraGlobalConfiguration(GlobalConfiguration configurationBefore, GlobalConfiguration configurationAfter) {
CounterManagerConfiguration configBefore = configurationBefore.module(CounterManagerConfiguration.class);
CounterManagerConfiguration configAfter = configurationAfter.module(CounterManagerConfiguration.class);
assertEquals(configBefore.numOwners(), configAfter.numOwners());
assertEquals(configBefore.reliability(), configAfter.reliability());
Map<String, AbstractCounterConfiguration> counterConfigBefore = configBefore.counters();
Map<String, AbstractCounterConfiguration> counterConfigAfter = configAfter.counters();
assertSameStrongCounterConfiguration(counterConfigBefore.get("c1"), counterConfigAfter.get("c1"));
assertSameStrongCounterConfiguration(counterConfigBefore.get("c2"), counterConfigAfter.get("c2"));
assertSameStrongCounterConfiguration(counterConfigBefore.get("c3"), counterConfigAfter.get("c3"));
assertSameStrongCounterConfiguration(counterConfigBefore.get("c4"), counterConfigAfter.get("c4"));
assertSameWeakCounterConfiguration(counterConfigBefore.get("c5"), counterConfigAfter.get("c5"));
}
use of org.infinispan.counter.configuration.AbstractCounterConfiguration in project infinispan by infinispan.
the class ConfigurationSerializerTest method testParser.
public void testParser() throws IOException {
ConfigurationBuilderHolder holder = new ParserRegistry().parseFile("configs/all/counters.xml");
GlobalConfiguration globalConfiguration = holder.getGlobalConfigurationBuilder().build();
CounterManagerConfiguration counterManagerConfiguration = globalConfiguration.module(CounterManagerConfiguration.class);
assertNotNull(counterManagerConfiguration);
assertEquals(3, counterManagerConfiguration.numOwners());
assertEquals(Reliability.CONSISTENT, counterManagerConfiguration.reliability());
Map<String, AbstractCounterConfiguration> counters = counterManagerConfiguration.counters();
assertStrongCounter("c1", counters.get("c1"), 1, Storage.PERSISTENT, false, Long.MIN_VALUE, Long.MAX_VALUE, -1);
assertStrongCounter("c2", counters.get("c2"), 2, Storage.VOLATILE, true, 0, Long.MAX_VALUE, -1);
assertStrongCounter("c3", counters.get("c3"), 3, Storage.PERSISTENT, true, Long.MIN_VALUE, 5, 2000);
assertStrongCounter("c4", counters.get("c4"), 4, Storage.VOLATILE, true, 0, 10, 0);
assertWeakCounter(counters.get("c5"));
}
Aggregations