Search in sources :

Example 31 with RestCacheClient

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");
}
Also used : RestEntity(org.infinispan.client.rest.RestEntity) RestResponse(org.infinispan.client.rest.RestResponse) RestCacheClient(org.infinispan.client.rest.RestCacheClient) Util.getResourceAsString(org.infinispan.commons.util.Util.getResourceAsString)

Example 32 with RestCacheClient

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

Example 33 with RestCacheClient

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

Example 34 with RestCacheClient

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

Example 35 with RestCacheClient

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));
}
Also used : Marshaller(org.infinispan.commons.marshall.Marshaller) RestResponse(org.infinispan.client.rest.RestResponse) RestCacheClient(org.infinispan.client.rest.RestCacheClient) EmbeddedRestMemcachedHotRodTest(org.infinispan.it.endpoints.EmbeddedRestMemcachedHotRodTest) Test(org.testng.annotations.Test)

Aggregations

RestCacheClient (org.infinispan.client.rest.RestCacheClient)66 RestResponse (org.infinispan.client.rest.RestResponse)41 Test (org.testng.annotations.Test)34 Util.getResourceAsString (org.infinispan.commons.util.Util.getResourceAsString)16 RestEntity (org.infinispan.client.rest.RestEntity)14 Json (org.infinispan.commons.dataconversion.internal.Json)13 RestClient (org.infinispan.client.rest.RestClient)11 Test (org.junit.Test)8 ConfigurationBuilder (org.infinispan.configuration.cache.ConfigurationBuilder)7 AbstractMultipleSitesTest (org.infinispan.xsite.AbstractMultipleSitesTest)7 RestClientConfigurationBuilder (org.infinispan.client.rest.configuration.RestClientConfigurationBuilder)6 GlobalConfigurationBuilder (org.infinispan.configuration.global.GlobalConfigurationBuilder)5 TestClass (org.infinispan.rest.TestClass)5 TestUser (org.infinispan.server.test.api.TestUser)5 DummyInMemoryStoreConfigurationBuilder (org.infinispan.persistence.dummy.DummyInMemoryStoreConfigurationBuilder)3 HashMap (java.util.HashMap)2 RestCacheManagerClient (org.infinispan.client.rest.RestCacheManagerClient)2 RestMetricsClient (org.infinispan.client.rest.RestMetricsClient)2 MediaType (org.infinispan.commons.dataconversion.MediaType)2 EmbeddedCacheManager (org.infinispan.manager.EmbeddedCacheManager)2