Search in sources :

Example 41 with RestCacheClient

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());
}
Also used : RestResponse(org.infinispan.client.rest.RestResponse) RestCacheClient(org.infinispan.client.rest.RestCacheClient) Json(org.infinispan.commons.dataconversion.internal.Json) Util.getResourceAsString(org.infinispan.commons.util.Util.getResourceAsString) Test(org.testng.annotations.Test)

Example 42 with RestCacheClient

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);
}
Also used : RestEntity(org.infinispan.client.rest.RestEntity) RestResponse(org.infinispan.client.rest.RestResponse) RestCacheClient(org.infinispan.client.rest.RestCacheClient) Util.getResourceAsString(org.infinispan.commons.util.Util.getResourceAsString) Json(org.infinispan.commons.dataconversion.internal.Json) Test(org.testng.annotations.Test)

Example 43 with RestCacheClient

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();
}
Also used : RestResponse(org.infinispan.client.rest.RestResponse) RestCacheClient(org.infinispan.client.rest.RestCacheClient)

Example 44 with RestCacheClient

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"));
}
Also used : RestClient(org.infinispan.client.rest.RestClient) RestCacheClient(org.infinispan.client.rest.RestCacheClient) Test(org.testng.annotations.Test) AbstractMultipleSitesTest(org.infinispan.xsite.AbstractMultipleSitesTest)

Example 45 with RestCacheClient

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));
}
Also used : RestClient(org.infinispan.client.rest.RestClient) RestCacheClient(org.infinispan.client.rest.RestCacheClient) Json(org.infinispan.commons.dataconversion.internal.Json) Test(org.testng.annotations.Test) AbstractMultipleSitesTest(org.infinispan.xsite.AbstractMultipleSitesTest)

Aggregations

RestCacheClient (org.infinispan.client.rest.RestCacheClient)66 RestResponse (org.infinispan.client.rest.RestResponse)41 Test (org.testng.annotations.Test)34 Util.getResourceAsString (org.infinispan.commons.util.Util.getResourceAsString)16 RestEntity (org.infinispan.client.rest.RestEntity)14 Json (org.infinispan.commons.dataconversion.internal.Json)13 RestClient (org.infinispan.client.rest.RestClient)11 Test (org.junit.Test)8 ConfigurationBuilder (org.infinispan.configuration.cache.ConfigurationBuilder)7 AbstractMultipleSitesTest (org.infinispan.xsite.AbstractMultipleSitesTest)7 RestClientConfigurationBuilder (org.infinispan.client.rest.configuration.RestClientConfigurationBuilder)6 GlobalConfigurationBuilder (org.infinispan.configuration.global.GlobalConfigurationBuilder)5 TestClass (org.infinispan.rest.TestClass)5 TestUser (org.infinispan.server.test.api.TestUser)5 DummyInMemoryStoreConfigurationBuilder (org.infinispan.persistence.dummy.DummyInMemoryStoreConfigurationBuilder)3 HashMap (java.util.HashMap)2 RestCacheManagerClient (org.infinispan.client.rest.RestCacheManagerClient)2 RestMetricsClient (org.infinispan.client.rest.RestMetricsClient)2 MediaType (org.infinispan.commons.dataconversion.MediaType)2 EmbeddedCacheManager (org.infinispan.manager.EmbeddedCacheManager)2