use of org.infinispan.client.rest.RestCacheClient in project infinispan by infinispan.
the class CacheResourceV2Test method testSearchStatistics.
@Test
public void testSearchStatistics() {
RestCacheClient cacheClient = adminClient.cache("indexedCache");
join(cacheClient.clear());
// Clear all stats
RestResponse response = join(cacheClient.clearSearchStats());
assertThat(response).isOk();
response = join(cacheClient.searchStats());
Json statJson = Json.read(response.getBody());
assertIndexStatsEmpty(statJson.at("index"));
assertAllQueryStatsEmpty(statJson.at("query"));
// Insert some data
insertEntity(1, "Entity", 1, "One");
insertEntity(11, "Entity", 11, "Eleven");
insertEntity(21, "Entity", 21, "Twenty One");
insertEntity(3, "Another", 3, "Three");
insertEntity(33, "Another", 33, "Thirty Three");
response = join(cacheClient.size());
assertThat(response).hasReturnedText("5");
response = join(cacheClient.searchStats());
assertThat(response).isOk();
// All stats should be zero in the absence of query
statJson = Json.read(response.getBody());
assertAllQueryStatsEmpty(statJson.at("query"));
// Execute some indexed queries
String indexedQuery = "FROM Entity WHERE value > 5";
IntStream.range(0, 3).forEach(i -> {
RestResponse response1 = join(cacheClient.query(indexedQuery));
assertThat(response1).isOk();
Json queryJson = Json.read(response1.getBody());
assertEquals(2, queryJson.at("total_results").asInteger());
});
response = join(cacheClient.searchStats());
statJson = Json.read(response.getBody());
// Hybrid and non-indexed queries stats should be empty
assertEquals(0, statJson.at("query").at("hybrid").at("count").asLong());
assertEquals(0, statJson.at("query").at("non_indexed").at("count").asLong());
Json queryStats = statJson.at("query");
assertQueryStatEmpty(queryStats.at("hybrid"));
assertQueryStatEmpty(queryStats.at("non_indexed"));
// Indexed queries should be recorded
assertEquals(3, statJson.at("query").at("indexed_local").at("count").asLong());
assertTrue(statJson.at("query").at("indexed_local").at("average").asLong() > 0);
assertTrue(statJson.at("query").at("indexed_local").at("max").asLong() > 0);
assertEquals(3, statJson.at("query").at("indexed_distributed").at("count").asLong());
assertTrue(statJson.at("query").at("indexed_distributed").at("average").asLong() > 0);
assertTrue(statJson.at("query").at("indexed_distributed").at("max").asLong() > 0);
// Execute a hybrid query
String hybrid = "FROM Entity WHERE value > 5 AND description = 'One'";
response = join(cacheClient.query(hybrid));
Json queryJson = Json.read(response.getBody());
assertEquals(0, queryJson.at("total_results").asInteger());
response = join(cacheClient.searchStats());
statJson = Json.read(response.getBody());
// Hybrid queries should be recorded
assertEquals(1, statJson.at("query").at("hybrid").at("count").asLong());
assertTrue(statJson.at("query").at("hybrid").at("average").asLong() > 0);
assertTrue(statJson.at("query").at("hybrid").at("max").asLong() > 0);
// Check index stats
response = join(cacheClient.searchStats());
statJson = Json.read(response.getBody());
assertEquals(3, statJson.at("index").at("types").at("Entity").at("count").asInteger());
assertEquals(2, statJson.at("index").at("types").at("Another").at("count").asInteger());
assertThat(statJson.at("index").at("types").at("Entity").at("size").asLong()).isGreaterThan(MIN_NON_EMPTY_INDEX_SIZE);
assertThat(statJson.at("index").at("types").at("Another").at("size").asLong()).isGreaterThan(MIN_NON_EMPTY_INDEX_SIZE);
assertFalse(statJson.at("index").at("reindexing").asBoolean());
}
use of org.infinispan.client.rest.RestCacheClient 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.RestCacheClient in project infinispan by infinispan.
the class CacheResourceV2Test method writeEntry.
private void writeEntry(String key, String value, String cacheName, MediaType mediaType) {
RestCacheClient cacheClient = client.cache(cacheName);
RestResponse response;
if (mediaType == null) {
response = join(cacheClient.put(key, value));
} else {
response = join(cacheClient.put(key, mediaType.toString(), RestEntity.create(mediaType, value)));
}
assertThat(response).isOk();
}
use of org.infinispan.client.rest.RestCacheClient in project infinispan by infinispan.
the class XSiteResourceTest method testInvalidSite.
@Test
public void testInvalidSite() {
RestClient client = clientPerSite.get(LON);
RestCacheClient cache = client.cache(CACHE_1);
assertStatus(404, cache.backupStatus("invalid-site"));
}
use of org.infinispan.client.rest.RestCacheClient in project infinispan by infinispan.
the class XSiteResourceTest method testPushAllCaches.
@Test
public void testPushAllCaches() {
RestClient restClientLon = clientPerSite.get(LON);
RestClient restClientSfo = clientPerSite.get(SFO);
RestCacheClient cache1Lon = restClientLon.cache(CACHE_1);
RestCacheClient cache2Lon = restClientLon.cache(CACHE_2);
RestCacheClient cache1Sfo = restClientSfo.cache(CACHE_1);
RestCacheClient cache2Sfo = restClientSfo.cache(CACHE_2);
// Take SFO offline for all caches
assertSuccessful(restClientLon.cacheManager(CACHE_MANAGER).takeOffline(SFO));
Json backupStatuses = jsonResponseBody(restClientLon.cacheManager(CACHE_MANAGER).backupStatuses());
assertEquals("offline", backupStatuses.at(SFO).at("status").asString());
// Write to the caches
int entries = 10;
IntStream.range(0, entries).forEach(i -> {
String key = String.valueOf(i);
String value = "value";
assertNoContent(cache1Lon.put(key, value));
assertNoContent(cache2Lon.put(key, value));
});
// Backups should be empty
assertEquals(0, getCacheSize(cache1Sfo));
assertEquals(0, getCacheSize(cache2Sfo));
// Start state push
assertSuccessful(restClientLon.cacheManager(CACHE_MANAGER).pushSiteState(SFO));
// Backups go online online immediately
assertEquals(ONLINE, getBackupStatus(LON, SFO));
// State push should eventually finish
eventuallyEquals("OK", () -> pushStateStatus(cache1Lon, SFO));
eventuallyEquals("OK", () -> pushStateStatus(cache2Lon, SFO));
// ... and with state
assertEquals(entries, getCacheSize(cache1Sfo));
assertEquals(entries, getCacheSize(cache2Sfo));
}
Aggregations