Search in sources :

Example 6 with AbstractCounterConfiguration

use of org.infinispan.counter.configuration.AbstractCounterConfiguration in project infinispan by infinispan.

the class ConfigurationTest method assertUnboundedStrongCounter.

private void assertUnboundedStrongCounter(CounterManagerConfiguration config) {
    for (AbstractCounterConfiguration counterConfig : config.counters().values()) {
        if (counterConfig.name().equals("unbounded-strong-1")) {
            assertTrue(counterConfig instanceof StrongCounterConfiguration);
            assertEquals(1, counterConfig.initialValue());
            assertEquals(-1, ((StrongCounterConfiguration) counterConfig).lifespan());
            assertEquals(Storage.VOLATILE, counterConfig.storage());
            return;
        }
    }
    fail();
}
Also used : StrongCounterConfiguration(org.infinispan.counter.configuration.StrongCounterConfiguration) AbstractCounterConfiguration(org.infinispan.counter.configuration.AbstractCounterConfiguration)

Example 7 with AbstractCounterConfiguration

use of org.infinispan.counter.configuration.AbstractCounterConfiguration in project infinispan by infinispan.

the class ConfigurationTest method assertWeakCounter.

private void assertWeakCounter(CounterManagerConfiguration config) {
    for (AbstractCounterConfiguration counterConfig : config.counters().values()) {
        if (counterConfig.name().equals("weak-5")) {
            assertTrue(counterConfig instanceof WeakCounterConfiguration);
            assertEquals(5, counterConfig.initialValue());
            assertEquals(Storage.VOLATILE, counterConfig.storage());
            assertEquals(10, ((WeakCounterConfiguration) counterConfig).concurrencyLevel());
            return;
        }
    }
    fail();
}
Also used : AbstractCounterConfiguration(org.infinispan.counter.configuration.AbstractCounterConfiguration) WeakCounterConfiguration(org.infinispan.counter.configuration.WeakCounterConfiguration)

Example 8 with AbstractCounterConfiguration

use of org.infinispan.counter.configuration.AbstractCounterConfiguration in project infinispan by infinispan.

the class CounterResourceTest method createCounter.

private void createCounter(String name, CounterConfiguration configuration) {
    AbstractCounterConfiguration config = ConvertUtil.configToParsedConfig(name, configuration);
    RestEntity restEntity = RestEntity.create(APPLICATION_JSON, counterConfigToJson(config));
    CompletionStage<RestResponse> response = client.counter(name).create(restEntity);
    assertThat(response).isOk();
}
Also used : RestEntity(org.infinispan.client.rest.RestEntity) RestResponse(org.infinispan.client.rest.RestResponse) AbstractCounterConfiguration(org.infinispan.counter.configuration.AbstractCounterConfiguration)

Example 9 with AbstractCounterConfiguration

use of org.infinispan.counter.configuration.AbstractCounterConfiguration in project infinispan by infinispan.

the class CounterResource method getConfig.

private CompletionStage<RestResponse> getConfig(RestRequest request) {
    NettyRestResponse.Builder responseBuilder = new NettyRestResponse.Builder();
    String counterName = request.variables().get("counterName");
    return invocationHelper.getCounterManager().getConfigurationAsync(counterName).thenApply(cfg -> {
        if (cfg == null)
            return responseBuilder.status(NOT_FOUND).build();
        AbstractCounterConfiguration parsedConfig = ConvertUtil.configToParsedConfig(counterName, cfg);
        CounterConfigurationSerializer ccs = new CounterConfigurationSerializer();
        StringBuilderWriter sw = new StringBuilderWriter();
        try (ConfigurationWriter w = ConfigurationWriter.to(sw).withType(APPLICATION_JSON).build()) {
            ccs.serializeConfiguration(w, parsedConfig);
        }
        return responseBuilder.entity(sw.toString()).contentType(APPLICATION_JSON).build();
    });
}
Also used : CounterConfigurationSerializer(org.infinispan.counter.configuration.CounterConfigurationSerializer) StringBuilderWriter(org.infinispan.commons.io.StringBuilderWriter) ConfigurationWriter(org.infinispan.commons.configuration.io.ConfigurationWriter) CounterManagerConfigurationBuilder(org.infinispan.counter.configuration.CounterManagerConfigurationBuilder) AbstractCounterConfiguration(org.infinispan.counter.configuration.AbstractCounterConfiguration) NettyRestResponse(org.infinispan.rest.NettyRestResponse)

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