Search in sources :

Example 81 with Json

use of org.infinispan.commons.dataconversion.internal.Json in project infinispan by infinispan.

the class CacheResourceV2Test method testStreamEntries.

@Test
public void testStreamEntries() {
    RestResponse response = join(client.cache("default").entries());
    Collection<?> emptyEntries = Json.read(response.getBody()).asJsonList();
    assertEquals(0, emptyEntries.size());
    putTextEntryInCache("default", "key_0", "value_0");
    response = join(client.cache("default").entries());
    Collection<?> singleSet = Json.read(response.getBody()).asJsonList();
    assertEquals(1, singleSet.size());
    for (int i = 0; i < 20; i++) {
        putTextEntryInCache("default", "key_" + i, "value_" + i);
    }
    response = join(client.cache("default").entries());
    List<Json> jsons = Json.read(response.getBody()).asJsonList();
    assertEquals(20, jsons.size());
    response = join(client.cache("default").entries(3));
    jsons = Json.read(response.getBody()).asJsonList();
    assertEquals(3, jsons.size());
    Json first = jsons.get(0);
    String entry = first.toPrettyString();
    assertThat(entry).contains("\"key\" : \"key_");
    assertThat(entry).contains("\"value\" : \"value_");
    assertThat(entry).doesNotContain("timeToLiveSeconds");
    assertThat(entry).doesNotContain("maxIdleTimeSeconds");
    assertThat(entry).doesNotContain("created");
    assertThat(entry).doesNotContain("lastUsed");
    assertThat(entry).doesNotContain("expireTime");
}
Also used : RestResponse(org.infinispan.client.rest.RestResponse) Json(org.infinispan.commons.dataconversion.internal.Json) Util.getResourceAsString(org.infinispan.commons.util.Util.getResourceAsString) Test(org.testng.annotations.Test)

Example 82 with Json

use of org.infinispan.commons.dataconversion.internal.Json 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 83 with Json

use of org.infinispan.commons.dataconversion.internal.Json 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 84 with Json

use of org.infinispan.commons.dataconversion.internal.Json in project infinispan by infinispan.

the class ContainerResourceTest method testCacheConfigs.

@Test
public void testCacheConfigs() {
    String accept = "text/plain; q=0.9, application/json; q=0.6";
    RestResponse response = join(cacheManagerClient.cacheConfigurations(accept));
    ResponseAssertion.assertThat(response).isOk();
    String json = response.getBody();
    Json jsonNode = Json.read(json);
    Map<String, String> cachesAndConfig = cacheAndConfig(jsonNode);
    assertEquals(cachesAndConfig.get("template"), cacheConfigToJson("template", templateConfig));
    assertEquals(cachesAndConfig.get("cache2"), cacheConfigToJson("cache2", cache2Config));
}
Also used : RestResponse(org.infinispan.client.rest.RestResponse) Json(org.infinispan.commons.dataconversion.internal.Json) Test(org.testng.annotations.Test)

Example 85 with Json

use of org.infinispan.commons.dataconversion.internal.Json in project infinispan by infinispan.

the class ContainerResourceTest method testCacheConfigsTemplates.

@Test
public void testCacheConfigsTemplates() {
    String accept = "text/plain; q=0.9, application/json; q=0.6";
    RestResponse response = join(cacheManagerClient.templates(accept));
    ResponseAssertion.assertThat(response).isOk();
    String json = response.getBody();
    Json jsonNode = Json.read(json);
    Map<String, String> cachesAndConfig = cacheAndConfig(jsonNode);
    assertEquals(cachesAndConfig.get("template"), cacheConfigToJson("template", templateConfig));
    assertFalse(cachesAndConfig.containsKey("cache1"));
    assertFalse(cachesAndConfig.containsKey("cache2"));
}
Also used : RestResponse(org.infinispan.client.rest.RestResponse) Json(org.infinispan.commons.dataconversion.internal.Json) Test(org.testng.annotations.Test)

Aggregations

Json (org.infinispan.commons.dataconversion.internal.Json)130 RestResponse (org.infinispan.client.rest.RestResponse)51 Test (org.testng.annotations.Test)51 RestClient (org.infinispan.client.rest.RestClient)15 Util.getResourceAsString (org.infinispan.commons.util.Util.getResourceAsString)13 Test (org.junit.Test)13 RestCacheClient (org.infinispan.client.rest.RestCacheClient)12 MultipleCacheManagersTest (org.infinispan.test.MultipleCacheManagersTest)12 AbstractMultipleSitesTest (org.infinispan.xsite.AbstractMultipleSitesTest)7 ArrayList (java.util.ArrayList)6 List (java.util.List)6 Map (java.util.Map)6 NettyRestResponse (org.infinispan.rest.NettyRestResponse)6 ResourceUtil.addEntityAsJson (org.infinispan.rest.resources.ResourceUtil.addEntityAsJson)6 HashMap (java.util.HashMap)5 RestEntity (org.infinispan.client.rest.RestEntity)5 IOException (java.io.IOException)4 HashSet (java.util.HashSet)4 Request (okhttp3.Request)4 RestSchemaClient (org.infinispan.client.rest.RestSchemaClient)4