use of org.infinispan.client.rest.RestEntity 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");
}
use of org.infinispan.client.rest.RestEntity in project infinispan by infinispan.
the class ContainerResourceTest method createCache.
private void createCache(String json, String name) {
RestEntity jsonEntity = RestEntity.create(APPLICATION_JSON, json);
CompletionStage<RestResponse> response = client.cache(name).createWithConfiguration(jsonEntity);
assertThat(response).isOk();
}
use of org.infinispan.client.rest.RestEntity 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.RestEntity in project infinispan by infinispan.
the class EmbeddedRestHotRodWithStringTest method testRestPutStringHotRodGet.
public void testRestPutStringHotRodGet() {
final String key = "1";
// 1. Put text content with REST
RestEntity value = RestEntity.create(MediaType.TEXT_PLAIN, "<hey>ho</hey>");
RestResponse response = join(cacheFactory.getRestCacheClient().put(key, value));
assertEquals(204, response.getStatus());
// 3. Get with Hot Rod
assertEquals("<hey>ho</hey>", cacheFactory.getHotRodCache().get(key));
final String newKey = "2";
final String newValue = "<let's>go</let's>";
// 4. Put text content with Hot Rod
RemoteCache<String, Object> hotRodCache = cacheFactory.getHotRodCache();
hotRodCache.put(newKey, newValue);
// 5. Read with rest
response = join(cacheFactory.getRestCacheClient().get(newKey));
assertEquals(200, response.getStatus());
assertEquals(newValue, response.getBody());
}
use of org.infinispan.client.rest.RestEntity in project infinispan by infinispan.
the class ReplEmbeddedRestHotRodTest method testRestPutEmbeddedHotRodGet.
public void testRestPutEmbeddedHotRodGet() {
final String key = "1";
// 1. Put with REST
RestEntity value = RestEntity.create(MediaType.TEXT_PLAIN, "<hey>ho</hey>".getBytes());
RestResponse response = join(cacheFactory1.getRestCacheClient().put(key, value));
assertEquals(204, response.getStatus());
// 2. Get with Embedded
Cache embeddedCache = cacheFactory2.getEmbeddedCache().getAdvancedCache();
assertEquals("<hey>ho</hey>", embeddedCache.get(key));
// 3. Get with Hot Rod
assertEquals("<hey>ho</hey>", cacheFactory2.getHotRodCache().get(key));
}
Aggregations