use of org.infinispan.client.rest.RestCacheClient 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");
}
use of org.infinispan.client.rest.RestCacheClient in project infinispan by infinispan.
the class CacheResourceV2Test method testConnectStoreValidation.
@Test
public void testConnectStoreValidation() {
RestCacheClient cacheClient = client.cache("default");
assertBadResponse(cacheClient, "true");
assertBadResponse(cacheClient, "2");
assertBadResponse(cacheClient, "[1,2,3]");
assertBadResponse(cacheClient, "\"random text\"");
assertBadResponse(cacheClient, "{\"jdbc-store\":{\"shared\":true}}");
assertBadResponse(cacheClient, "{\"jdbc-store\":{\"shared\":true},\"remote-store\":{\"shared\":true}}");
}
use of org.infinispan.client.rest.RestCacheClient 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();
}
use of org.infinispan.client.rest.RestCacheClient in project infinispan by infinispan.
the class EmbeddedRestCacheListenerTest method testLoadingAndStoringEventsRest.
public void testLoadingAndStoringEventsRest() {
Cache<String, String> embedded = cacheFactory.getEmbeddedCache();
RestCacheClient remote = cacheFactory.getRestCacheClient();
TestCacheListener l = new TestCacheListener();
embedded.addListener(l);
assertTrue(l.created.isEmpty());
assertTrue(l.removed.isEmpty());
assertTrue(l.modified.isEmpty());
assertTrue(l.visited.isEmpty());
RestEntity v = RestEntity.create(MediaType.APPLICATION_OCTET_STREAM, "v".getBytes());
join(remote.put("k", v));
assertEquals(1, l.createdCounter);
assertEquals("v".getBytes(), (byte[]) l.created.get("k"));
assertTrue(l.removed.isEmpty());
assertEquals(0, l.modifiedCounter);
assertTrue(l.visited.isEmpty());
RestEntity value = RestEntity.create(MediaType.APPLICATION_OCTET_STREAM, "value".getBytes());
join(remote.put("key", value));
assertEquals(2, l.createdCounter);
assertTrue(l.removed.isEmpty());
assertEquals(0, l.modifiedCounter);
assertTrue(l.visited.isEmpty());
RestEntity modifiedValue = RestEntity.create(MediaType.APPLICATION_OCTET_STREAM, "modifiedValue".getBytes());
join(remote.put("key", modifiedValue));
assertEquals(2, l.createdCounter);
assertTrue(l.removed.isEmpty());
assertEquals(1, l.modifiedCounter);
assertEquals("modifiedValue".getBytes(), (byte[]) l.modified.get("key"));
assertTrue(l.visited.isEmpty());
RestEntity replacedValue = RestEntity.create(MediaType.APPLICATION_OCTET_STREAM, "replacedValue".getBytes());
join(remote.put("k", replacedValue));
assertEquals(2, l.createdCounter);
assertTrue(l.removed.isEmpty());
assertEquals(2, l.modifiedCounter);
assertEquals("replacedValue".getBytes(), (byte[]) l.modified.get("k"));
assertTrue(l.visited.isEmpty());
// resetting so don't have to type "== 2" etc. all over again
l.reset();
join(remote.remove("key"));
assertTrue(l.created.isEmpty());
assertEquals(1, l.removedCounter);
assertEquals("modifiedValue".getBytes(), (byte[]) l.removed.get("key"));
assertTrue(l.modified.isEmpty());
l.reset();
join(remote.get("k"));
assertTrue(l.created.isEmpty());
assertTrue(l.removed.isEmpty());
assertTrue(l.modified.isEmpty());
assertEquals(1, l.visitedCounter);
assertEquals("replacedValue".getBytes(), (byte[]) l.visited.get("k"));
l.reset();
}
use of org.infinispan.client.rest.RestCacheClient in project infinispan by infinispan.
the class AbstractInteropTest method testRestPutEmbeddedMemcachedHotRodGetTest.
@Test
public void testRestPutEmbeddedMemcachedHotRodGetTest() throws Exception {
final String key = "3";
final Object value = "<hey>ho</hey>";
final Marshaller marshaller = cacheFactory.getMarshaller();
// 1. Put with REST
byte[] bytes = marshaller.objectToByteBuffer(value);
RestCacheClient restClient = cacheFactory.getRestCacheClient();
RestResponse response = join(restClient.put(key, RestEntity.create(marshaller.mediaType(), bytes)));
assertEquals(204, response.getStatus());
// 2. Get with Embedded (given a marshaller, it can unmarshall the result)
assertEquals(value, cacheFactory.getEmbeddedCache().get(key));
// 3. Get with Memcached (given a marshaller, it can unmarshall the result)
assertEquals(value, cacheFactory.getMemcachedClient().get(key));
// 4. Get with Hot Rod
assertEquals(value, cacheFactory.getHotRodCache().get(key));
}
Aggregations