Search in sources :

Example 11 with RestResponse

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

the class EmbeddedRestHotRodTest method testHotRodEmbeddedPutRestGetCacheControlHeader.

public void testHotRodEmbeddedPutRestGetCacheControlHeader() {
    final String key1 = "18";
    final String key2 = "19";
    // 1. Put with HotRod
    assertNull(cacheFactory.getHotRodCache().put(key1, "v1", 7, TimeUnit.SECONDS));
    // 2. Put with Embedded
    assertNull(cacheFactory.getEmbeddedCache().put(key2, "v2", 7, TimeUnit.SECONDS));
    // 3. GET with REST key1, long min-fresh
    Map<String, String> headers = singletonMap("Cache-Control", "min-fresh=20");
    RestResponse response = join(cacheFactory.getRestCacheClient().get(key1, headers));
    assertEquals(404, response.getStatus());
    // 4. GET with REST key2, long min-fresh
    response = join(cacheFactory.getRestCacheClient().get(key2, headers));
    assertEquals(404, response.getStatus());
    // 5. GET with REST key1, short min-fresh
    headers = new HashMap<>();
    headers.put("Accept", TEXT_PLAIN_TYPE);
    headers.put("Cache-Control", "min-fresh=3");
    response = join(cacheFactory.getRestCacheClient().get(key1, headers));
    assertEquals(200, response.getStatus());
    assertNotNull(response.getHeader("Cache-Control"));
    assertTrue(response.getHeader("Cache-Control").contains("max-age"));
    assertEquals("v1", response.getBody());
    // 6. GET with REST key2, short min-fresh
    response = join(cacheFactory.getRestCacheClient().get(key2, headers));
    assertEquals(200, response.getStatus());
    assertTrue(response.getHeader("Cache-Control").contains("max-age"));
    assertEquals("v2", response.getBody());
}
Also used : RestResponse(org.infinispan.client.rest.RestResponse)

Example 12 with RestResponse

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

the class EmbeddedRestMemcachedHotRodTest method testEmbeddedPutMemcachedRestHotRodGetTest.

public void testEmbeddedPutMemcachedRestHotRodGetTest() {
    final String key = "2";
    // 1. Put with Embedded
    assertNull(cacheFactory.getEmbeddedCache().put(key, "v1"));
    // 2. Get with Memcached
    assertEquals("v1", cacheFactory.getMemcachedClient().get(key));
    // 3. Get with REST
    RestResponse response = join(cacheFactory.getRestCacheClient().get(key, MediaType.TEXT_PLAIN_TYPE));
    assertEquals(200, response.getStatus());
    assertEquals("v1", response.getBody());
    // 4. Get with Hot Rod
    assertEquals("v1", cacheFactory.getHotRodCache().get(key));
}
Also used : RestResponse(org.infinispan.client.rest.RestResponse)

Example 13 with RestResponse

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

the class EmbeddedRestMemcachedHotRodTest method testMemcachedPutEmbeddedRestHotRodGetTest.

public void testMemcachedPutEmbeddedRestHotRodGetTest() throws Exception {
    final String key = "1";
    // 1. Put with Memcached
    Future<Boolean> f = cacheFactory.getMemcachedClient().set(key, 0, "v1");
    assertTrue(f.get(60, TimeUnit.SECONDS));
    // 2. Get with Embedded
    assertEquals("v1", cacheFactory.getEmbeddedCache().get(key));
    // 3. Get with REST
    RestResponse response = join(cacheFactory.getRestCacheClient().get(key, MediaType.TEXT_PLAIN_TYPE));
    assertEquals(200, response.getStatus());
    assertEquals("v1", response.getBody());
    // 4. Get with Hot Rod
    assertEquals("v1", cacheFactory.getHotRodCache().get(key));
}
Also used : RestResponse(org.infinispan.client.rest.RestResponse)

Example 14 with RestResponse

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

the class EmbeddedRestMemcachedHotRodTest method testRestPutEmbeddedMemcachedHotRodGetTest.

public void testRestPutEmbeddedMemcachedHotRodGetTest() throws Exception {
    final String key = "3";
    // 1. Put with REST
    RestEntity value = RestEntity.create(MediaType.TEXT_PLAIN, "<hey>ho</hey>");
    RestResponse response = join(cacheFactory.getRestCacheClient().put(key, value));
    assertEquals(204, response.getStatus());
    // 2. Get with Embedded (given a marshaller, it can unmarshall the result)
    assertEquals("<hey>ho</hey>", cacheFactory.getEmbeddedCache().get(key));
    // 3. Get with Memcached (given a marshaller, it can unmarshall the result)
    assertEquals("<hey>ho</hey>", cacheFactory.getMemcachedClient().get(key));
    // 4. Get with Hot Rod (given a marshaller, it can unmarshall the result)
    assertEquals("<hey>ho</hey>", cacheFactory.getHotRodCache().get(key));
}
Also used : RestEntity(org.infinispan.client.rest.RestEntity) RestResponse(org.infinispan.client.rest.RestResponse)

Example 15 with RestResponse

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

the class SinglePortTest method shouldUpgradeThroughALPN.

@Test
public void shouldUpgradeThroughALPN() throws Exception {
    checkForOpenSSL();
    // given
    restServer = RestTestingUtil.createDefaultRestServer("rest", "default");
    RestServerRouteDestination restDestination = new RestServerRouteDestination("rest", restServer);
    SinglePortRouteSource singlePortSource = new SinglePortRouteSource();
    Route<SinglePortRouteSource, RestServerRouteDestination> routeToRest = new Route<>(singlePortSource, restDestination);
    SslContextFactory sslContextFactory = new SslContextFactory();
    RouterConfigurationBuilder routerConfigurationBuilder = new RouterConfigurationBuilder();
    routerConfigurationBuilder.singlePort().sslContext(sslContextFactory.keyStoreFileName(KEY_STORE_PATH).keyStorePassword(KEY_STORE_PASSWORD.toCharArray()).getContext()).port(0).ip(InetAddress.getLoopbackAddress()).routing().add(routeToRest);
    router = new Router(routerConfigurationBuilder.build());
    router.start();
    EndpointRouter singlePortRouter = router.getRouter(EndpointRouter.Protocol.SINGLE_PORT).get();
    // when
    RestClientConfigurationBuilder builder = new RestClientConfigurationBuilder();
    builder.addServer().host(singlePortRouter.getHost()).port(singlePortRouter.getPort()).protocol(Protocol.HTTP_20).security().ssl().trustStoreFileName(TRUST_STORE_PATH).trustStorePassword("secret".toCharArray()).hostnameVerifier((hostname, session) -> true);
    httpClient = RestClient.forConfiguration(builder.build());
    CompletionStage<RestResponse> response = httpClient.cache("default").post("test", VALUE);
    // then
    ResponseAssertion.assertThat(response).hasNoContent();
}
Also used : SslContextFactory(org.infinispan.commons.util.SslContextFactory) RestClientConfigurationBuilder(org.infinispan.client.rest.configuration.RestClientConfigurationBuilder) SinglePortRouteSource(org.infinispan.server.router.routes.singleport.SinglePortRouteSource) RestResponse(org.infinispan.client.rest.RestResponse) Router(org.infinispan.server.router.Router) EndpointRouter(org.infinispan.server.router.router.EndpointRouter) RestServerRouteDestination(org.infinispan.server.router.routes.rest.RestServerRouteDestination) EndpointRouter(org.infinispan.server.router.router.EndpointRouter) RouterConfigurationBuilder(org.infinispan.server.router.configuration.builder.RouterConfigurationBuilder) Route(org.infinispan.server.router.routes.Route) Test(org.junit.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