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");
}
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();
}
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;
}
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();
}
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");
}
Aggregations