Search in sources :

Example 1 with AbstractCounterConfiguration

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();
}
Also used : StrongCounterConfiguration(org.infinispan.counter.configuration.StrongCounterConfiguration) AbstractCounterConfiguration(org.infinispan.counter.configuration.AbstractCounterConfiguration)

Example 2 with AbstractCounterConfiguration

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());
}
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 AbstractCounterConfiguration

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();
    }
}
Also used : RestResponse(org.infinispan.client.rest.RestResponse) AbstractCounterConfiguration(org.infinispan.counter.configuration.AbstractCounterConfiguration) AbstractCounterConfiguration(org.infinispan.counter.configuration.AbstractCounterConfiguration) CounterConfiguration(org.infinispan.counter.api.CounterConfiguration)

Example 4 with AbstractCounterConfiguration

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"));
}
Also used : AbstractCounterConfiguration(org.infinispan.counter.configuration.AbstractCounterConfiguration) CounterManagerConfiguration(org.infinispan.counter.configuration.CounterManagerConfiguration)

Example 5 with AbstractCounterConfiguration

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"));
}
Also used : ConfigurationBuilderHolder(org.infinispan.configuration.parsing.ConfigurationBuilderHolder) GlobalConfiguration(org.infinispan.configuration.global.GlobalConfiguration) ParserRegistry(org.infinispan.configuration.parsing.ParserRegistry) AbstractCounterConfiguration(org.infinispan.counter.configuration.AbstractCounterConfiguration) CounterManagerConfiguration(org.infinispan.counter.configuration.CounterManagerConfiguration)

Aggregations

AbstractCounterConfiguration (org.infinispan.counter.configuration.AbstractCounterConfiguration)9 RestResponse (org.infinispan.client.rest.RestResponse)3 CounterConfiguration (org.infinispan.counter.api.CounterConfiguration)2 CounterManagerConfiguration (org.infinispan.counter.configuration.CounterManagerConfiguration)2 StrongCounterConfiguration (org.infinispan.counter.configuration.StrongCounterConfiguration)2 RestClient (org.infinispan.client.rest.RestClient)1 RestCounterClient (org.infinispan.client.rest.RestCounterClient)1 RestEntity (org.infinispan.client.rest.RestEntity)1 RestClientConfigurationBuilder (org.infinispan.client.rest.configuration.RestClientConfigurationBuilder)1 ConfigurationWriter (org.infinispan.commons.configuration.io.ConfigurationWriter)1 StringBuilderWriter (org.infinispan.commons.io.StringBuilderWriter)1 GlobalConfiguration (org.infinispan.configuration.global.GlobalConfiguration)1 ConfigurationBuilderHolder (org.infinispan.configuration.parsing.ConfigurationBuilderHolder)1 ParserRegistry (org.infinispan.configuration.parsing.ParserRegistry)1 CounterConfigurationSerializer (org.infinispan.counter.configuration.CounterConfigurationSerializer)1 CounterManagerConfigurationBuilder (org.infinispan.counter.configuration.CounterManagerConfigurationBuilder)1 WeakCounterConfiguration (org.infinispan.counter.configuration.WeakCounterConfiguration)1 NettyRestResponse (org.infinispan.rest.NettyRestResponse)1 AbstractRestResourceTest (org.infinispan.rest.resources.AbstractRestResourceTest)1 Test (org.junit.Test)1