use of org.infinispan.client.rest.RestCacheClient in project infinispan by infinispan.
the class Put method exec.
@Override
protected CompletionStage<RestResponse> exec(ContextAwareCommandInvocation invocation, RestClient client, org.infinispan.cli.resources.Resource resource) {
if ((file != null) && (args.size() != 1)) {
throw Messages.MSG.illegalCommandArguments();
} else if ((file == null) && (args.size() != 2)) {
throw Messages.MSG.illegalCommandArguments();
}
RestCacheClient cacheClient = client.cache(cache != null ? cache : CacheResource.cacheName(resource));
MediaType putEncoding = encoding != null ? MediaType.fromString(encoding) : invocation.getContext().getEncoding();
RestEntity value = file != null ? RestEntity.create(putEncoding, new File(file.getAbsolutePath())) : RestEntity.create(putEncoding, args.get(1));
if (ifAbsent) {
return cacheClient.post(args.get(0), value, ttl, maxIdle);
} else {
return cacheClient.put(args.get(0), value, ttl, maxIdle);
}
}
use of org.infinispan.client.rest.RestCacheClient in project infinispan by infinispan.
the class EmbeddedRestHotRodTest method testCustomObjectRestPutHotRodEmbeddedGet.
public void testCustomObjectRestPutHotRodEmbeddedGet() throws Exception {
final String key = "77";
Person p = new Person("Iker");
// 1. Put with Rest
RestCacheClient restClient = cacheFactory.getRestCacheClient();
ByteArrayOutputStream bout = new ByteArrayOutputStream();
try (ObjectOutputStream oos = new ObjectOutputStream(bout)) {
oos.writeObject(p);
}
RestEntity value = RestEntity.create(APPLICATION_SERIALIZED_OBJECT, new ByteArrayInputStream(bout.toByteArray()));
join(restClient.put(key, value));
// 2. Get with Hot Rod
RemoteCache<String, Object> remote = cacheFactory.getHotRodCache();
assertEquals(p, remote.get(key));
// 3. Get with Embedded
assertEquals(p, cacheFactory.getEmbeddedCache().getAdvancedCache().get(key));
}
use of org.infinispan.client.rest.RestCacheClient in project infinispan by infinispan.
the class EmbeddedRestHotRodTest method testRestPutEmbeddedHotRodGet.
public void testRestPutEmbeddedHotRodGet() {
final String key = "1";
// 1. Put with REST
RestCacheClient restCacheClient = cacheFactory.getRestCacheClient();
CompletionStage<RestResponse> response = restCacheClient.put(key, RestEntity.create(TEXT_PLAIN, "<hey>ho</hey>"));
assertEquals(204, join(response).getStatus());
// 2. Get with Embedded
assertEquals("<hey>ho</hey>", cacheFactory.getEmbeddedCache().get(key));
// 3. Get with Hot Rod
assertEquals("<hey>ho</hey>", cacheFactory.getHotRodCache().get(key));
}
use of org.infinispan.client.rest.RestCacheClient in project infinispan by infinispan.
the class IndexedCacheNonIndexedEntityTest method shouldPreventNonIndexedEntities.
@Test
public void shouldPreventNonIndexedEntities() {
CompletionStage<RestResponse> response = client.schemas().post("customer", SCHEMA);
ResponseAssertion.assertThat(response).isOk();
ConfigurationBuilder configurationBuilder = getDefaultStandaloneCacheConfig(false);
configurationBuilder.statistics().enable();
configurationBuilder.encoding().mediaType(APPLICATION_PROTOSTREAM_TYPE).indexing().enable().storage(LOCAL_HEAP).addIndexedEntity("NonIndexed");
String config = cacheConfigToJson(CACHE_NAME, configurationBuilder.build());
RestEntity configEntity = RestEntity.create(MediaType.APPLICATION_JSON, config);
RestCacheClient cacheClient = client.cache(CACHE_NAME);
response = cacheClient.createWithConfiguration(configEntity, VOLATILE);
// The SearchMapping is started lazily, creating and starting the cache will not throw errors
ResponseAssertion.assertThat(response).isOk();
// Force initialization of the SearchMapping
response = cacheClient.query("FROM NonIndexed");
ResponseAssertion.assertThat(response).isBadRequest();
String errorText = "The configured indexed-entity type 'NonIndexed' must be indexed. Please annotate it with @Indexed";
ResponseAssertion.assertThat(response).containsReturnedText(errorText);
// Call Indexer operations
response = cacheClient.clearIndex();
ResponseAssertion.assertThat(response).containsReturnedText(errorText);
// The Indexer should not have "running" status
Indexer indexer = Search.getIndexer(cacheManager.getCache(CACHE_NAME));
assertFalse(indexer.isRunning());
}
use of org.infinispan.client.rest.RestCacheClient in project infinispan by infinispan.
the class RestMetricsResource method testTimerMetrics.
@Test
public void testTimerMetrics() throws Exception {
RestClient client = SERVER_TEST.rest().create();
RestMetricsClient metricsClient = client.metrics();
// this is a histogram of write times
String metricName = "cache_manager_default_cache_" + SERVER_TEST.getMethodName() + "_statistics_store_times";
int NUM_PUTS = 10;
try (RestResponse response = sync(metricsClient.metrics())) {
assertEquals(200, response.getStatus());
checkIsPrometheus(response.contentType());
String body = response.getBody();
assertThat(body).contains("base", "vendor", metricName);
checkRule(body, "vendor_" + metricName, (stringValue) -> {
double parsed = Double.parseDouble(stringValue);
assertThat(parsed).isZero();
});
}
// put some entries then check that the stats were updated
RestCacheClient cache = client.cache(SERVER_TEST.getMethodName());
for (int i = 0; i < NUM_PUTS; i++) {
RestResponse putResp = sync(cache.put("k" + i, "v" + i));
assertEquals(204, putResp.getStatus());
}
try (RestResponse response = sync(metricsClient.metrics())) {
assertEquals(200, response.getStatus());
checkIsPrometheus(response.contentType());
String body = response.getBody();
assertThat(body).contains("base", "vendor", metricName);
checkRule(body, "vendor_" + metricName, (stringValue) -> {
double parsed = Double.parseDouble(stringValue);
assertThat(parsed).isPositive();
});
}
}
Aggregations