use of org.infinispan.client.rest.RestCacheClient in project infinispan by infinispan.
the class CacheResourceTest method shouldConvertExistingSerializableObjectToXml.
@Test
public void shouldConvertExistingSerializableObjectToXml() {
// given
TestClass testClass = new TestClass();
testClass.setName("test");
RestCacheClient objectCache = client.cache("objectCache");
String xml = "<org.infinispan.rest.TestClass><name>test</name></org.infinispan.rest.TestClass>";
join(objectCache.put("test", RestEntity.create(APPLICATION_XML, xml)));
// when
RestResponse response = join(objectCache.get("test", APPLICATION_XML_TYPE));
// then
assertThat(response).isOk();
assertThat(response).hasContentType("application/xml");
assertThat(response).hasReturnedText(xml);
}
use of org.infinispan.client.rest.RestCacheClient in project infinispan by infinispan.
the class CacheResourceTest method shouldReadAsBinaryWithPojoCache.
@Test
public void shouldReadAsBinaryWithPojoCache() {
// given
RestCacheClient pojoCache = client.cache("pojoCache");
String key = "test";
TestClass value = new TestClass();
value.setName("test");
join(pojoCache.put(key, value.toJson().toString()));
// when
RestResponse response = join(pojoCache.get(key, APPLICATION_OCTET_STREAM_TYPE));
// then
assertThat(response).isOk();
assertThat(response).hasContentType(APPLICATION_OCTET_STREAM_TYPE);
}
use of org.infinispan.client.rest.RestCacheClient in project infinispan by infinispan.
the class CacheResourceTest method shouldIgnoreDisabledCaches.
@Test
public void shouldIgnoreDisabledCaches() {
putStringValueInCache("default", "K", "V");
RestCacheClient cacheClient = client.cache("default");
CompletionStage<RestResponse> response = cacheClient.get("K");
assertThat(response).isOk();
if (security) {
Security.doAs(TestingUtil.makeSubject(AuthorizationPermission.ADMIN.name()), (PrivilegedAction<Void>) () -> {
restServer().ignoreCache("default");
return null;
});
} else {
restServer().ignoreCache("default");
}
response = cacheClient.get("K");
assertThat(response).isServiceUnavailable();
if (security) {
Security.doAs(TestingUtil.makeSubject(AuthorizationPermission.ADMIN.name()), (PrivilegedAction<Void>) () -> {
restServer().unignoreCache("default");
return null;
});
} else {
restServer().unignoreCache("default");
}
response = cacheClient.get("K");
assertThat(response).isOk();
}
use of org.infinispan.client.rest.RestCacheClient in project infinispan by infinispan.
the class CacheResourceTest method shouldDeleteExistingValueEvenWithoutMetadata.
@Test
public void shouldDeleteExistingValueEvenWithoutMetadata() {
RestCacheClient defaultCache = client.cache("default");
join(defaultCache.put("test", "test"));
// when
CompletionStage<RestResponse> response = defaultCache.remove("test");
// then
assertThat(response).isOk();
Assertions.assertThat(join(defaultCache.size()).getBody()).isEqualTo("0");
}
use of org.infinispan.client.rest.RestCacheClient in project infinispan by infinispan.
the class RestMetricsResource method testMetrics.
@Test
public void testMetrics() throws Exception {
RestClient client = SERVER_TEST.rest().create();
RestMetricsClient metricsClient = client.metrics();
String metricName = "cache_manager_default_cache_" + SERVER_TEST.getMethodName() + "_statistics_stores";
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).isEqualTo(10.0);
});
}
// delete cache and check that the metric is gone
sync(client.cache(SERVER_TEST.getMethodName()).delete());
try (RestResponse response = sync(metricsClient.metrics())) {
assertEquals(200, response.getStatus());
checkIsPrometheus(response.contentType());
String body = response.getBody();
assertThat(body).contains("base", "vendor");
// metric is not present anymore:
assertThat(body).doesNotContain(metricName);
}
}
Aggregations