Search in sources :

Example 91 with RestResponse

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

the class Http2Test method secureUpgradeTest.

private void secureUpgradeTest(Protocol choice) {
    // given
    restServer = RestServerHelper.defaultRestServer().withKeyStore(KEY_STORE_PATH, STORE_PASSWORD, STORE_TYPE).start(TestResourceTracker.getCurrentTestShortName());
    RestClientConfigurationBuilder builder = new RestClientConfigurationBuilder();
    builder.addServer().host(restServer.getHost()).port(restServer.getPort()).protocol(choice).security().ssl().trustStoreFileName(KEY_STORE_PATH).trustStorePassword(STORE_PASSWORD).hostnameVerifier((hostname, session) -> true);
    client = RestClient.forConfiguration(builder.build());
    RestEntity value = RestEntity.create(MediaType.APPLICATION_OCTET_STREAM, "test".getBytes(CharsetUtil.UTF_8));
    CompletionStage<RestResponse> response = client.cache("defaultcache").post("test", value);
    // then
    ResponseAssertion.assertThat(response).isOk();
    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)

Example 92 with RestResponse

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

the class Http2Test method shouldUseHTTP1.

@Test
public void shouldUseHTTP1() {
    restServer = RestServerHelper.defaultRestServer().start(TestResourceTracker.getCurrentTestShortName());
    RestClientConfigurationBuilder builder = new RestClientConfigurationBuilder();
    builder.addServer().host(restServer.getHost()).port(restServer.getPort()).protocol(HTTP_11);
    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").put("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) Test(org.testng.annotations.Test) AbstractInfinispanTest(org.infinispan.test.AbstractInfinispanTest)

Example 93 with RestResponse

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

the class CacheResourceV2Test method testCacheV2LifeCycle.

@Test
public void testCacheV2LifeCycle() throws Exception {
    String xml = getResourceAsString("cache.xml", getClass().getClassLoader());
    String json = getResourceAsString("cache.json", getClass().getClassLoader());
    RestEntity xmlEntity = RestEntity.create(APPLICATION_XML, xml);
    RestEntity jsonEntity = RestEntity.create(APPLICATION_JSON, json);
    CompletionStage<RestResponse> response = client.cache("cache1").createWithConfiguration(xmlEntity, VOLATILE);
    assertThat(response).isOk();
    assertPersistence("cache1", false);
    response = client.cache("cache2").createWithConfiguration(jsonEntity);
    assertThat(response).isOk();
    assertPersistence("cache2", true);
    String mediaList = "application/json,text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8";
    response = client.cache("cache1").configuration(mediaList);
    assertThat(response).isOk();
    String cache1Cfg = join(response).getBody();
    response = client.cache("cache2").configuration();
    assertThat(response).isOk();
    String cache2Cfg = join(response).getBody();
    assertEquals(cache1Cfg, cache2Cfg.replace("cache2", "cache1"));
    response = client.cache("cache1").configuration("application/xml");
    assertThat(response).isOk();
    String cache1Xml = join(response).getBody();
    ParserRegistry registry = new ParserRegistry();
    Configuration xmlConfig = registry.parse(cache1Xml).getCurrentConfigurationBuilder().build();
    assertEquals(1200000, xmlConfig.clustering().l1().lifespan());
    assertEquals(60500, xmlConfig.clustering().stateTransfer().timeout());
}
Also used : Configuration(org.infinispan.configuration.cache.Configuration) RestEntity(org.infinispan.client.rest.RestEntity) RestResponse(org.infinispan.client.rest.RestResponse) ParserRegistry(org.infinispan.configuration.parsing.ParserRegistry) Util.getResourceAsString(org.infinispan.commons.util.Util.getResourceAsString) Test(org.testng.annotations.Test)

Example 94 with RestResponse

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

the class CacheResourceV2Test method insertEntity.

private void insertEntity(int cacheKey, String type, int intValue, String stringValue) {
    Json json = Json.object().set("_type", type).set("value", intValue).set("description", stringValue);
    RestEntity restEntity = RestEntity.create(APPLICATION_JSON, json.toString());
    RestCacheClient cacheClient = client.cache("indexedCache");
    CompletionStage<RestResponse> response = cacheClient.put(String.valueOf(cacheKey), restEntity);
    assertThat(response).isOk();
}
Also used : RestEntity(org.infinispan.client.rest.RestEntity) RestResponse(org.infinispan.client.rest.RestResponse) RestCacheClient(org.infinispan.client.rest.RestCacheClient) Json(org.infinispan.commons.dataconversion.internal.Json)

Example 95 with RestResponse

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

the class CacheResourceV2Test method testStreamEntriesWithMetadataAndExpirationTimesConvertedToSeconds.

@Test
public void testStreamEntriesWithMetadataAndExpirationTimesConvertedToSeconds() {
    RestEntity textValue = RestEntity.create(TEXT_PLAIN, "value1");
    join(client.cache("default").put("key1", TEXT_PLAIN_TYPE, textValue, 1000, 5000));
    RestResponse response = join(client.cache("default").entries(1, true));
    List<Json> jsons = Json.read(response.getBody()).asJsonList();
    assertEquals(1, jsons.size());
    Json first = jsons.get(0);
    String entry = first.toPrettyString();
    assertThat(entry).contains("\"key\" : \"key1");
    assertThat(entry).contains("\"value\" : \"value1");
    assertThat(entry).contains("\"timeToLiveSeconds\" : 1000");
    assertThat(entry).contains("\"maxIdleTimeSeconds\" : 5000");
}
Also used : RestEntity(org.infinispan.client.rest.RestEntity) RestResponse(org.infinispan.client.rest.RestResponse) Json(org.infinispan.commons.dataconversion.internal.Json) Util.getResourceAsString(org.infinispan.commons.util.Util.getResourceAsString) Test(org.testng.annotations.Test)

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