Search in sources :

Example 86 with RestResponse

use of org.infinispan.client.rest.RestResponse 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 87 with RestResponse

use of org.infinispan.client.rest.RestResponse 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)

Example 88 with RestResponse

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

the class CacheResourceV2Test method testCreateAndUseCache.

private void testCreateAndUseCache(String name) {
    String cacheConfig = "{\"distributed-cache\":{\"mode\":\"SYNC\"}}";
    RestCacheClient cacheClient = client.cache(name);
    RestEntity config = RestEntity.create(APPLICATION_JSON, cacheConfig);
    CompletionStage<RestResponse> response = cacheClient.createWithConfiguration(config);
    assertThat(response).isOk();
    CompletionStage<RestResponse> sizeResponse = cacheClient.size();
    assertThat(sizeResponse).isOk();
    assertThat(sizeResponse).containsReturnedText("0");
    RestResponse namesResponse = join(client.caches());
    assertThat(namesResponse).isOk();
    List<String> names = Json.read(namesResponse.getBody()).asJsonList().stream().map(Json::asString).collect(Collectors.toList());
    assertTrue(names.contains(name));
    CompletionStage<RestResponse> putResponse = cacheClient.post("key", "value");
    assertThat(putResponse).isOk();
    CompletionStage<RestResponse> getResponse = cacheClient.get("key");
    assertThat(getResponse).isOk();
    assertThat(getResponse).containsReturnedText("value");
}
Also used : 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 89 with RestResponse

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

the class Http2Test method shouldReportErrorCorrectly.

@Test
public void shouldReportErrorCorrectly() {
    restServer = RestServerHelper.defaultRestServer().withKeyStore(KEY_STORE_PATH, STORE_PASSWORD, STORE_TYPE).withTrustStore(KEY_STORE_PATH, STORE_PASSWORD, STORE_TYPE).start(TestResourceTracker.getCurrentTestShortName());
    RestClientConfigurationBuilder config = new RestClientConfigurationBuilder();
    config.addServer().host(restServer.getHost()).port(restServer.getPort()).protocol(HTTP_20).priorKnowledge(true).security().ssl().enable().trustStoreFileName(KEY_STORE_PATH).trustStorePassword(STORE_PASSWORD).trustStoreType(STORE_TYPE).keyStoreFileName(KEY_STORE_PATH).keyStorePassword(STORE_PASSWORD).keyStoreType(STORE_TYPE).hostnameVerifier((hostname, session) -> true);
    client = RestClient.forConfiguration(config.build());
    CompletionStage<RestResponse> response = client.raw().get("/invalid");
    ResponseAssertion.assertThat(response).isNotFound();
}
Also used : RestClientConfigurationBuilder(org.infinispan.client.rest.configuration.RestClientConfigurationBuilder) RestResponse(org.infinispan.client.rest.RestResponse) Test(org.testng.annotations.Test) AbstractInfinispanTest(org.infinispan.test.AbstractInfinispanTest)

Example 90 with RestResponse

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

the class Http2Test method clearTextUpgrade.

private void clearTextUpgrade(boolean previousKnowledge) {
    restServer = RestServerHelper.defaultRestServer().start(TestResourceTracker.getCurrentTestShortName());
    RestClientConfigurationBuilder builder = new RestClientConfigurationBuilder();
    builder.addServer().host(restServer.getHost()).port(restServer.getPort()).priorKnowledge(previousKnowledge).protocol(Protocol.HTTP_20);
    client = RestClient.forConfiguration(builder.build());
    CompletionStage<RestResponse> response = client.cacheManager("default").info();
    ResponseAssertion.assertThat(response).isOk();
    RestEntity value = RestEntity.create(MediaType.APPLICATION_OCTET_STREAM, "test".getBytes(CharsetUtil.UTF_8));
    response = client.cache("defaultcache").post("test", value);
    Assertions.assertThat(join(response).getStatus()).isEqualTo(204);
    Assertions.assertThat(restServer.getCacheManager().getCache().size()).isEqualTo(1);
}
Also used : RestClientConfigurationBuilder(org.infinispan.client.rest.configuration.RestClientConfigurationBuilder) RestEntity(org.infinispan.client.rest.RestEntity) RestResponse(org.infinispan.client.rest.RestResponse)

Aggregations

RestResponse (org.infinispan.client.rest.RestResponse)233 Test (org.testng.annotations.Test)108 Json (org.infinispan.commons.dataconversion.internal.Json)52 RestCacheClient (org.infinispan.client.rest.RestCacheClient)42 Test (org.junit.Test)41 Util.getResourceAsString (org.infinispan.commons.util.Util.getResourceAsString)39 RestClient (org.infinispan.client.rest.RestClient)37 RestEntity (org.infinispan.client.rest.RestEntity)36 RestClientConfigurationBuilder (org.infinispan.client.rest.configuration.RestClientConfigurationBuilder)23 HashMap (java.util.HashMap)8 RestCounterClient (org.infinispan.client.rest.RestCounterClient)8 TestClass (org.infinispan.rest.TestClass)8 RestSchemaClient (org.infinispan.client.rest.RestSchemaClient)7 ConfigurationBuilder (org.infinispan.configuration.cache.ConfigurationBuilder)7 RestCacheManagerClient (org.infinispan.client.rest.RestCacheManagerClient)6 RestMetricsClient (org.infinispan.client.rest.RestMetricsClient)6 GlobalConfigurationBuilder (org.infinispan.configuration.global.GlobalConfigurationBuilder)6 Cache (org.infinispan.Cache)5 RestRawClient (org.infinispan.client.rest.RestRawClient)5 MultipleCacheManagersTest (org.infinispan.test.MultipleCacheManagersTest)5