Search in sources :

Example 11 with RestEntity

use of org.infinispan.client.rest.RestEntity in project infinispan by infinispan.

the class CacheResourceV2Test method testIndexDataSyncInvalidSchema.

@Test
public void testIndexDataSyncInvalidSchema() {
    String notQuiteIndexed = "package schemas;\n" + " /* @Indexed */\n" + " message Entity {\n" + "    optional string name=1;\n" + " }";
    // Register schema
    RestResponse restResponse = join(client.schemas().put("schemas.proto", notQuiteIndexed));
    assertThat(restResponse).isOk();
    // Create the indexed cache
    ConfigurationBuilder builder = new ConfigurationBuilder();
    builder.indexing().enable().storage(LOCAL_HEAP).addIndexedEntities("schemas.Entity");
    String cacheConfig = cacheConfigToJson("sync-data-index", builder.build());
    RestCacheClient cacheClient = client.cache("sync-data-index");
    RestEntity config = RestEntity.create(APPLICATION_JSON, cacheConfig);
    CompletionStage<RestResponse> response = cacheClient.createWithConfiguration(config);
    assertThat(response).isOk();
    // Write an entry, it should error
    String value = Json.object().set("_type", "schemas.Entity").set("name", "Jun").toString();
    RestEntity restEntity = RestEntity.create(APPLICATION_JSON, value);
    restResponse = join(cacheClient.put("key", restEntity));
    assertThat(restResponse).containsReturnedText("make sure at least one field has the @Field annotation");
    // Cache should not have any data
    response = cacheClient.size();
    assertThat(response).containsReturnedText("0");
}
Also used : ConfigurationBuilder(org.infinispan.configuration.cache.ConfigurationBuilder) GlobalConfigurationBuilder(org.infinispan.configuration.global.GlobalConfigurationBuilder) DummyInMemoryStoreConfigurationBuilder(org.infinispan.persistence.dummy.DummyInMemoryStoreConfigurationBuilder) 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) Test(org.testng.annotations.Test)

Example 12 with RestEntity

use of org.infinispan.client.rest.RestEntity in project infinispan by infinispan.

the class CacheResourceV2Test method createAndWriteToCache.

private void createAndWriteToCache(String name, Configuration configuration) {
    String jsonConfig = cacheConfigToJson(name, configuration);
    RestEntity configEntity = RestEntity.create(APPLICATION_JSON, jsonConfig);
    CompletionStage<RestResponse> response = client.cache(name).createWithConfiguration(configEntity);
    assertThat(response).isOk();
    RestEntity valueEntity = RestEntity.create(APPLICATION_JSON, "{\"_type\":\"Simple\",\"value\":1}");
    response = client.cache(name).post("1", valueEntity);
    assertThat(response).isOk();
}
Also used : RestEntity(org.infinispan.client.rest.RestEntity) RestResponse(org.infinispan.client.rest.RestResponse) Util.getResourceAsString(org.infinispan.commons.util.Util.getResourceAsString)

Example 13 with RestEntity

use of org.infinispan.client.rest.RestEntity in project infinispan by infinispan.

the class CacheResourceV2Test method createCache.

private RestCacheClient createCache(RestClient c, String json, String name) {
    RestEntity jsonEntity = RestEntity.create(APPLICATION_JSON, json);
    RestCacheClient cache = c.cache(name);
    CompletionStage<RestResponse> response = cache.createWithConfiguration(jsonEntity);
    assertThat(response).isOk();
    return cache;
}
Also used : RestEntity(org.infinispan.client.rest.RestEntity) RestResponse(org.infinispan.client.rest.RestResponse) RestCacheClient(org.infinispan.client.rest.RestCacheClient)

Example 14 with RestEntity

use of org.infinispan.client.rest.RestEntity in project infinispan by infinispan.

the class CacheResourceV2Test method createCache.

private void createCache(String cacheName, MediaType mediaType) {
    RestCacheClient cacheClient = client.cache(cacheName);
    ConfigurationBuilder builder = new ConfigurationBuilder();
    builder.clustering().cacheMode(CacheMode.DIST_SYNC);
    if (mediaType != null)
        builder.encoding().mediaType(mediaType.toString());
    String jsonConfig = cacheConfigToJson(cacheName, builder.build());
    RestEntity cacheConfig = RestEntity.create(APPLICATION_JSON, jsonConfig);
    RestResponse response = join(cacheClient.createWithConfiguration(cacheConfig));
    assertThat(response).isOk();
}
Also used : ConfigurationBuilder(org.infinispan.configuration.cache.ConfigurationBuilder) GlobalConfigurationBuilder(org.infinispan.configuration.global.GlobalConfigurationBuilder) DummyInMemoryStoreConfigurationBuilder(org.infinispan.persistence.dummy.DummyInMemoryStoreConfigurationBuilder) 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 15 with RestEntity

use of org.infinispan.client.rest.RestEntity 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)

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