Search in sources :

Example 16 with RestEntity

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

Example 17 with RestEntity

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

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

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

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

Aggregations

RestEntity (org.infinispan.client.rest.RestEntity)38 RestResponse (org.infinispan.client.rest.RestResponse)35 RestCacheClient (org.infinispan.client.rest.RestCacheClient)14 Test (org.testng.annotations.Test)14 Util.getResourceAsString (org.infinispan.commons.util.Util.getResourceAsString)11 Json (org.infinispan.commons.dataconversion.internal.Json)5 ConfigurationBuilder (org.infinispan.configuration.cache.ConfigurationBuilder)5 RestClientConfigurationBuilder (org.infinispan.client.rest.configuration.RestClientConfigurationBuilder)4 GlobalConfigurationBuilder (org.infinispan.configuration.global.GlobalConfigurationBuilder)4 DummyInMemoryStoreConfigurationBuilder (org.infinispan.persistence.dummy.DummyInMemoryStoreConfigurationBuilder)3 MediaType (org.infinispan.commons.dataconversion.MediaType)2 ByteArrayInputStream (java.io.ByteArrayInputStream)1 ByteArrayOutputStream (java.io.ByteArrayOutputStream)1 File (java.io.File)1 ObjectOutputStream (java.io.ObjectOutputStream)1 HashMap (java.util.HashMap)1 Cache (org.infinispan.Cache)1 RemoteCache (org.infinispan.client.hotrod.RemoteCache)1 RemoteCacheManager (org.infinispan.client.hotrod.RemoteCacheManager)1 RestClient (org.infinispan.client.rest.RestClient)1