Search in sources :

Example 21 with RestResponse

use of org.infinispan.client.rest.RestResponse in project infinispan by infinispan.

the class SearchCountClusteredTest method assertTotalAndPageSize.

private void assertTotalAndPageSize(CompletionStage<RestResponse> response, int totalResults, int pageSize) {
    RestResponse restResponse = await(response);
    String body = restResponse.getBody();
    Json responseDoc = Json.read(body);
    Json total = responseDoc.at("total_results");
    assertEquals(totalResults, total.asLong());
    long hitsSize = responseDoc.at("hits").asJsonList().size();
    assertEquals(pageSize, hitsSize);
}
Also used : RestResponse(org.infinispan.client.rest.RestResponse) Json(org.infinispan.commons.dataconversion.internal.Json)

Example 22 with RestResponse

use of org.infinispan.client.rest.RestResponse in project infinispan by infinispan.

the class SearchCountClusteredTest method setUp.

@BeforeClass
public void setUp() {
    LongStream.range(0, INDEXED_ENTRIES).forEach(i -> {
        String str = "index " + i;
        String value = Json.object().set("_type", "IndexedEntity").set("indexedStoredField", str).set("indexedNotStoredField", str).set("sortableStoredField", i % 20).set("sortableNotStoredField", "index_" + i % 20).set("notIndexedField", str).toString();
        RestResponse response = await(indexedCache().put(String.valueOf(i), RestEntity.create(APPLICATION_JSON, value)));
        assertEquals(204, response.getStatus());
        assertTrue(response.getBody().isEmpty());
    });
    LongStream.range(0, NOT_INDEXED_ENTRIES).forEach(i -> {
        String value = "text " + i;
        Json json = Json.object().set("_type", "NotIndexedEntity").set("field1", value).set("field2", value);
        RestResponse response = await(nonIndexedCache().put(String.valueOf(i), RestEntity.create(APPLICATION_JSON, json.toString())));
        assertEquals(204, response.getStatus());
        assertTrue(response.getBody().isEmpty());
    });
}
Also used : RestResponse(org.infinispan.client.rest.RestResponse) Json(org.infinispan.commons.dataconversion.internal.Json) BeforeClass(org.testng.annotations.BeforeClass)

Example 23 with RestResponse

use of org.infinispan.client.rest.RestResponse in project infinispan by infinispan.

the class BackupManagerIT method testManagerBackupParameters.

@Test
public void testManagerBackupParameters() throws Exception {
    String name = "testManagerBackupParameters";
    performTest(client -> {
        Map<String, List<String>> params = new HashMap<>();
        params.put("caches", Collections.singletonList("*"));
        params.put("counters", Collections.singletonList("weak-volatile"));
        RestCacheManagerClient cm = client.cacheManager("clustered");
        RestResponse response = await(cm.createBackup(name, params));
        assertEquals(202, response.getStatus());
        return awaitOk(() -> cm.getBackup(name, false));
    }, client -> await(client.cacheManager("clustered").deleteBackup(name)), (zip, client) -> {
        Map<String, List<String>> params = new HashMap<>();
        params.put("caches", Collections.singletonList("cache1"));
        params.put("counters", Collections.singletonList("*"));
        RestCacheManagerClient cm = client.cacheManager("clustered");
        RestResponse response = await(cm.restore(name, zip, params));
        assertEquals(202, response.getStatus());
        return awaitCreated(() -> cm.getRestore(name));
    }, client -> {
        // Assert that only caches and the specified "weak-volatile" counter have been backed up. Internal caches will still be present
        assertEquals("[\"___protobuf_metadata\",\"memcachedCache\",\"cache1\",\"___script_cache\"]", await(client.caches()).getBody());
        assertEquals("[\"weak-volatile\"]", await(client.counters()).getBody());
        assertEquals(404, await(client.schemas().get("schema.proto")).getStatus());
        assertEquals("[]", await(client.tasks().list(RestTaskClient.ResultType.USER)).getBody());
    }, false);
}
Also used : HashMap(java.util.HashMap) RestCacheManagerClient(org.infinispan.client.rest.RestCacheManagerClient) RestResponse(org.infinispan.client.rest.RestResponse) List(java.util.List) Test(org.junit.Test)

Example 24 with RestResponse

use of org.infinispan.client.rest.RestResponse in project infinispan by infinispan.

the class BackupManagerIT method createCounter.

private void createCounter(String name, Element type, Storage storage, RestClient client, long delta) {
    String config = String.format("{\n" + "    \"%s\":{\n" + "        \"initial-value\":0,\n" + "        \"storage\":\"%s\"\n" + "    }\n" + "}", type, storage.toString());
    RestCounterClient counterClient = client.counter(name);
    RestResponse rsp = await(counterClient.create(RestEntity.create(MediaType.APPLICATION_JSON, config)));
    assertEquals(200, rsp.getStatus());
    if (delta != 0) {
        rsp = await(counterClient.add(delta));
        assertEquals(name, name.contains("strong") ? 200 : 204, rsp.getStatus());
        assertNotNull(rsp.getBody());
    }
}
Also used : RestCounterClient(org.infinispan.client.rest.RestCounterClient) RestResponse(org.infinispan.client.rest.RestResponse)

Example 25 with RestResponse

use of org.infinispan.client.rest.RestResponse in project infinispan by infinispan.

the class BackupManagerIT method testClusterBackupFromFile.

@Test
public void testClusterBackupFromFile() throws Exception {
    String name = "testClusterBackup";
    performTest(client -> {
        RestClusterClient cluster = client.cluster();
        RestResponse response = await(cluster.createBackup(name));
        assertEquals(202, response.getStatus());
        return awaitOk(() -> cluster.getBackup(name, false));
    }, client -> await(client.cacheManager("clustered").deleteBackup(name)), (zip, client) -> {
        RestClusterClient c = client.cluster();
        RestResponse response = await(c.restore(name, zip.getPath()));
        assertEquals(202, response.getStatus());
        return awaitCreated(() -> c.getRestore(name));
    }, this::assertWildcardContent, true);
}
Also used : RestResponse(org.infinispan.client.rest.RestResponse) RestClusterClient(org.infinispan.client.rest.RestClusterClient) Test(org.junit.Test)

Aggregations

RestResponse (org.infinispan.client.rest.RestResponse)233 Test (org.testng.annotations.Test)108 Json (org.infinispan.commons.dataconversion.internal.Json)52 RestCacheClient (org.infinispan.client.rest.RestCacheClient)42 Test (org.junit.Test)41 Util.getResourceAsString (org.infinispan.commons.util.Util.getResourceAsString)39 RestClient (org.infinispan.client.rest.RestClient)37 RestEntity (org.infinispan.client.rest.RestEntity)36 RestClientConfigurationBuilder (org.infinispan.client.rest.configuration.RestClientConfigurationBuilder)23 HashMap (java.util.HashMap)8 RestCounterClient (org.infinispan.client.rest.RestCounterClient)8 TestClass (org.infinispan.rest.TestClass)8 RestSchemaClient (org.infinispan.client.rest.RestSchemaClient)7 ConfigurationBuilder (org.infinispan.configuration.cache.ConfigurationBuilder)7 RestCacheManagerClient (org.infinispan.client.rest.RestCacheManagerClient)6 RestMetricsClient (org.infinispan.client.rest.RestMetricsClient)6 GlobalConfigurationBuilder (org.infinispan.configuration.global.GlobalConfigurationBuilder)6 Cache (org.infinispan.Cache)5 RestRawClient (org.infinispan.client.rest.RestRawClient)5 MultipleCacheManagersTest (org.infinispan.test.MultipleCacheManagersTest)5