Search in sources :

Example 21 with RestEntity

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");
}
Also used : RestEntity(org.infinispan.client.rest.RestEntity) RestResponse(org.infinispan.client.rest.RestResponse) Json(org.infinispan.commons.dataconversion.internal.Json) Util.getResourceAsString(org.infinispan.commons.util.Util.getResourceAsString) Test(org.testng.annotations.Test)

Example 22 with RestEntity

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();
}
Also used : RestEntity(org.infinispan.client.rest.RestEntity) RestResponse(org.infinispan.client.rest.RestResponse)

Example 23 with RestEntity

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();
}
Also used : RestEntity(org.infinispan.client.rest.RestEntity) RestCacheClient(org.infinispan.client.rest.RestCacheClient)

Example 24 with RestEntity

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());
}
Also used : RestEntity(org.infinispan.client.rest.RestEntity) RestResponse(org.infinispan.client.rest.RestResponse)

Example 25 with RestEntity

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));
}
Also used : RestEntity(org.infinispan.client.rest.RestEntity) RestResponse(org.infinispan.client.rest.RestResponse) Cache(org.infinispan.Cache) RemoteCache(org.infinispan.client.hotrod.RemoteCache)

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