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());
}
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));
}
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));
}
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));
}
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();
}
Aggregations