Search in sources :

Example 26 with RestCacheClient

use of org.infinispan.client.rest.RestCacheClient in project infinispan by infinispan.

the class CacheResourceV2Test method createCache.

private RestCacheClient createCache(RestClient c, String json, String name) {
    RestEntity jsonEntity = RestEntity.create(APPLICATION_JSON, json);
    RestCacheClient cache = c.cache(name);
    CompletionStage<RestResponse> response = cache.createWithConfiguration(jsonEntity);
    assertThat(response).isOk();
    return cache;
}
Also used : RestEntity(org.infinispan.client.rest.RestEntity) RestResponse(org.infinispan.client.rest.RestResponse) RestCacheClient(org.infinispan.client.rest.RestCacheClient)

Example 27 with RestCacheClient

use of org.infinispan.client.rest.RestCacheClient in project infinispan by infinispan.

the class CacheResourceV2Test method createCache.

private void createCache(String cacheName, MediaType mediaType) {
    RestCacheClient cacheClient = client.cache(cacheName);
    ConfigurationBuilder builder = new ConfigurationBuilder();
    builder.clustering().cacheMode(CacheMode.DIST_SYNC);
    if (mediaType != null)
        builder.encoding().mediaType(mediaType.toString());
    String jsonConfig = cacheConfigToJson(cacheName, builder.build());
    RestEntity cacheConfig = RestEntity.create(APPLICATION_JSON, jsonConfig);
    RestResponse response = join(cacheClient.createWithConfiguration(cacheConfig));
    assertThat(response).isOk();
}
Also used : ConfigurationBuilder(org.infinispan.configuration.cache.ConfigurationBuilder) GlobalConfigurationBuilder(org.infinispan.configuration.global.GlobalConfigurationBuilder) DummyInMemoryStoreConfigurationBuilder(org.infinispan.persistence.dummy.DummyInMemoryStoreConfigurationBuilder) RestEntity(org.infinispan.client.rest.RestEntity) RestResponse(org.infinispan.client.rest.RestResponse) RestCacheClient(org.infinispan.client.rest.RestCacheClient) Util.getResourceAsString(org.infinispan.commons.util.Util.getResourceAsString)

Example 28 with RestCacheClient

use of org.infinispan.client.rest.RestCacheClient in project infinispan by infinispan.

the class CacheResourceV2Test method testCacheV2KeyOps.

@Test
public void testCacheV2KeyOps() {
    RestCacheClient cacheClient = client.cache("default");
    RestResponse response = join(cacheClient.post("key", "value"));
    assertThat(response).isOk();
    response = join(cacheClient.post("key", "value"));
    assertThat(response).isConflicted().hasReturnedText("An entry already exists");
    response = join(cacheClient.put("key", "value-new"));
    assertThat(response).isOk();
    response = join(cacheClient.get("key"));
    assertThat(response).hasReturnedText("value-new");
    response = join(cacheClient.head("key"));
    assertThat(response).isOk();
    assertThat(response).hasNoContent();
    response = join(cacheClient.remove("key"));
    assertThat(response).isOk();
    response = join(cacheClient.get("key"));
    assertThat(response).isNotFound();
}
Also used : RestResponse(org.infinispan.client.rest.RestResponse) RestCacheClient(org.infinispan.client.rest.RestCacheClient) Test(org.testng.annotations.Test)

Example 29 with RestCacheClient

use of org.infinispan.client.rest.RestCacheClient in project infinispan by infinispan.

the class CacheResourceV2Test method testRebalancingActions.

@Test
public void testRebalancingActions() {
    String cacheName = "default";
    assertRebalancingStatus(cacheName, true);
    RestCacheClient cacheClient = adminClient.cache(cacheName);
    RestResponse response = join(cacheClient.disableRebalancing());
    ResponseAssertion.assertThat(response).isOk();
    assertRebalancingStatus(cacheName, false);
    response = join(cacheClient.enableRebalancing());
    ResponseAssertion.assertThat(response).isOk();
    assertRebalancingStatus(cacheName, true);
}
Also used : RestResponse(org.infinispan.client.rest.RestResponse) RestCacheClient(org.infinispan.client.rest.RestCacheClient) Util.getResourceAsString(org.infinispan.commons.util.Util.getResourceAsString) Test(org.testng.annotations.Test)

Example 30 with RestCacheClient

use of org.infinispan.client.rest.RestCacheClient in project infinispan by infinispan.

the class CacheResourceV2Test method testMutableAttributes.

@Test
public void testMutableAttributes() {
    String cacheName = "mutable-attributes";
    String json = "{\"local-cache\":{\"encoding\":{\"media-type\":\"text/plain\"}}}";
    RestCacheClient cacheClient = createCache(adminClient, json, cacheName);
    CompletionStage<RestResponse> response = cacheClient.configurationAttributes(true);
    assertThat(response).isOk();
    Json attributes = Json.read(join(response).getBody());
    assertEquals(10, attributes.asJsonMap().size());
    assertEquals("long", attributes.at("clustering.remote-timeout").at("type").asString());
    assertEquals(15000, attributes.at("clustering.remote-timeout").at("value").asLong());
}
Also used : RestResponse(org.infinispan.client.rest.RestResponse) RestCacheClient(org.infinispan.client.rest.RestCacheClient) Util.getResourceAsString(org.infinispan.commons.util.Util.getResourceAsString) Json(org.infinispan.commons.dataconversion.internal.Json) Test(org.testng.annotations.Test)

Aggregations

RestCacheClient (org.infinispan.client.rest.RestCacheClient)66 RestResponse (org.infinispan.client.rest.RestResponse)41 Test (org.testng.annotations.Test)34 Util.getResourceAsString (org.infinispan.commons.util.Util.getResourceAsString)16 RestEntity (org.infinispan.client.rest.RestEntity)14 Json (org.infinispan.commons.dataconversion.internal.Json)13 RestClient (org.infinispan.client.rest.RestClient)11 Test (org.junit.Test)8 ConfigurationBuilder (org.infinispan.configuration.cache.ConfigurationBuilder)7 AbstractMultipleSitesTest (org.infinispan.xsite.AbstractMultipleSitesTest)7 RestClientConfigurationBuilder (org.infinispan.client.rest.configuration.RestClientConfigurationBuilder)6 GlobalConfigurationBuilder (org.infinispan.configuration.global.GlobalConfigurationBuilder)5 TestClass (org.infinispan.rest.TestClass)5 TestUser (org.infinispan.server.test.api.TestUser)5 DummyInMemoryStoreConfigurationBuilder (org.infinispan.persistence.dummy.DummyInMemoryStoreConfigurationBuilder)3 HashMap (java.util.HashMap)2 RestCacheManagerClient (org.infinispan.client.rest.RestCacheManagerClient)2 RestMetricsClient (org.infinispan.client.rest.RestMetricsClient)2 MediaType (org.infinispan.commons.dataconversion.MediaType)2 EmbeddedCacheManager (org.infinispan.manager.EmbeddedCacheManager)2