use of org.infinispan.client.rest.RestEntity in project infinispan by infinispan.
the class BaseJsonTest method writeCurrencyViaJson.
private void writeCurrencyViaJson(String key, String description, int rank) {
Json currency = Json.object();
currency.set(TYPE, getJsonType());
currency.set("description", description);
currency.set("rank", rank);
RestEntity value = RestEntity.create(MediaType.APPLICATION_JSON, currency.toString());
RestResponse response = join(restCacheClient.put(key, value));
assertEquals(response.getStatus(), 204);
}
use of org.infinispan.client.rest.RestEntity in project infinispan by infinispan.
the class CacheResourceV2Test method testCRUDWithProtobufPrimitives.
@Test
public void testCRUDWithProtobufPrimitives() throws Exception {
RestCacheClient client = this.client.cache("proto");
MediaType integerType = MediaType.APPLICATION_OBJECT.withClassType(Integer.class);
// Insert a pair of Integers
RestEntity value = RestEntity.create(integerType, "1");
CompletionStage<RestResponse> response = client.put("1", integerType.toString(), value);
assertThat(response).isOk();
// Change the value to another Integer
RestEntity anotherValue = RestEntity.create(integerType, "2");
response = client.put("1", integerType.toString(), anotherValue);
assertThat(response).isOk();
// Read the changed value as an integer
Map<String, String> headers = new HashMap<>();
headers.put(KEY_CONTENT_TYPE_HEADER.getValue(), integerType.toString());
headers.put(ACCEPT_HEADER.getValue(), integerType.toString());
response = client.get("1", headers);
assertThat(response).isOk();
assertThat(response).hasReturnedText("2");
// Read the changed value as protobuf
headers = new HashMap<>();
headers.put(KEY_CONTENT_TYPE_HEADER.getValue(), integerType.toString());
headers.put(ACCEPT_HEADER.getValue(), MediaType.APPLICATION_PROTOSTREAM_TYPE);
response = client.get("1", headers);
assertThat(response).isOk();
assertThat(response).hasReturnedBytes(new ProtoStreamMarshaller().objectToByteBuffer(2));
}
use of org.infinispan.client.rest.RestEntity in project infinispan by infinispan.
the class CacheResourceV2Test method testLazySearchMapping.
@Test
public void testLazySearchMapping() {
String proto = " package future;\n" + " /* @Indexed */\n" + " message Entity {\n" + " /* @Field */\n" + " optional string name=1;\n" + " }";
String value = Json.object().set("_type", "future.Entity").set("name", "Kim").toString();
RestEntity restEntity = RestEntity.create(APPLICATION_JSON, value);
// Create a cache with a declared, not yet registered protobuf entity
ConfigurationBuilder builder = new ConfigurationBuilder();
builder.indexing().enable().storage(LOCAL_HEAP).addIndexedEntities("future.Entity");
String cacheConfig = cacheConfigToJson("index-lazy", builder.build());
RestCacheClient cacheClient = client.cache("index-lazy");
RestEntity config = RestEntity.create(APPLICATION_JSON, cacheConfig);
CompletionStage<RestResponse> response = cacheClient.createWithConfiguration(config);
assertThat(response).isOk();
// Queries should return error
RestResponse restResponse = join(cacheClient.query("From future.Entity"));
assertThat(restResponse).containsReturnedText("Unknown type name : future.Entity");
// Writes too
restResponse = join(cacheClient.put("key", restEntity));
assertThat(restResponse).containsReturnedText("Unknown type name : future.Entity");
// Register the protobuf
restResponse = join(client.schemas().put("future.proto", proto));
assertThat(restResponse).isOk();
// All operations should work
restResponse = join(cacheClient.put("key", restEntity));
assertThat(restResponse).isOk();
restResponse = join(cacheClient.query("From future.Entity"));
assertThat(restResponse).isOk();
assertThat(restResponse).containsReturnedText("Kim");
}
use of org.infinispan.client.rest.RestEntity in project infinispan by infinispan.
the class CacheResourceV2Test method testCacheV2Stats.
@Test
public void testCacheV2Stats() {
String cacheJson = "{ \"distributed-cache\" : { \"statistics\":true } }";
RestCacheClient cacheClient = client.cache("statCache");
RestEntity jsonEntity = RestEntity.create(APPLICATION_JSON, cacheJson);
CompletionStage<RestResponse> response = cacheClient.createWithConfiguration(jsonEntity, VOLATILE);
assertThat(response).isOk();
putStringValueInCache("statCache", "key1", "data");
putStringValueInCache("statCache", "key2", "data");
response = cacheClient.stats();
assertThat(response).isOk();
Json jsonNode = Json.read(join(response).getBody());
assertEquals(jsonNode.at("current_number_of_entries").asInteger(), 2);
assertEquals(jsonNode.at("stores").asInteger(), 2);
response = cacheClient.clear();
assertThat(response).isOk();
response = cacheClient.stats();
assertThat(response).isOk().hasJson().hasProperty("current_number_of_entries").is(0);
}
use of org.infinispan.client.rest.RestEntity in project infinispan by infinispan.
the class TasksResourceTest method testTaskUpload.
@Test
public void testTaskUpload() throws Exception {
RestTaskClient taskClient = client.tasks();
String script = getResourceAsString("hello.js", getClass().getClassLoader());
RestEntity scriptEntity = RestEntity.create(APPLICATION_JAVASCRIPT, script);
CompletionStage<RestResponse> response = taskClient.uploadScript("hello", scriptEntity);
ResponseAssertion.assertThat(response).isOk();
response = taskClient.exec("hello", Collections.singletonMap("greetee", "Friend"));
ResponseAssertion.assertThat(response).isOk();
Json jsonNode = Json.read(join(response).getBody());
assertEquals("Hello Friend", jsonNode.asString());
}
Aggregations