Search in sources :

Example 76 with RestResponse

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

the class CacheResourceV2Test method correctReportNotQueryableCache.

private void correctReportNotQueryableCache(String name, Configuration configuration) {
    createAndWriteToCache(name, configuration);
    RestResponse response = queryCache(name);
    assertThat(response).isBadRequest();
    Json json = Json.read(response.getBody());
    assertTrue(json.at("error").at("cause").toString().matches(".*ISPN028015.*"));
}
Also used : RestResponse(org.infinispan.client.rest.RestResponse) Json(org.infinispan.commons.dataconversion.internal.Json)

Example 77 with RestResponse

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

the class CacheResourceV2Test method createDeleteCache.

private void createDeleteCache(String xml) {
    RestEntity xmlEntity = RestEntity.create(APPLICATION_XML, xml);
    RestCacheClient cacheClient = client.cache("cacheCRUD");
    CompletionStage<RestResponse> response = cacheClient.createWithConfiguration(xmlEntity, VOLATILE);
    assertThat(response).isOk();
    response = cacheClient.stats();
    assertThat(response).isOk().hasJson().hasProperty("current_number_of_entries").is(-1);
    response = cacheClient.delete();
    assertThat(response).isOk();
    response = cacheClient.stats();
    assertThat(response).isNotFound().hasReturnedText("ISPN012010: Cache with name 'cacheCRUD' not found amongst the configured caches");
}
Also used : RestEntity(org.infinispan.client.rest.RestEntity) RestResponse(org.infinispan.client.rest.RestResponse) RestCacheClient(org.infinispan.client.rest.RestCacheClient)

Example 78 with RestResponse

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

the class CacheResourceV2Test method testIndexDataSyncInvalidSchema.

@Test
public void testIndexDataSyncInvalidSchema() {
    String notQuiteIndexed = "package schemas;\n" + " /* @Indexed */\n" + " message Entity {\n" + "    optional string name=1;\n" + " }";
    // Register schema
    RestResponse restResponse = join(client.schemas().put("schemas.proto", notQuiteIndexed));
    assertThat(restResponse).isOk();
    // Create the indexed cache
    ConfigurationBuilder builder = new ConfigurationBuilder();
    builder.indexing().enable().storage(LOCAL_HEAP).addIndexedEntities("schemas.Entity");
    String cacheConfig = cacheConfigToJson("sync-data-index", builder.build());
    RestCacheClient cacheClient = client.cache("sync-data-index");
    RestEntity config = RestEntity.create(APPLICATION_JSON, cacheConfig);
    CompletionStage<RestResponse> response = cacheClient.createWithConfiguration(config);
    assertThat(response).isOk();
    // Write an entry, it should error
    String value = Json.object().set("_type", "schemas.Entity").set("name", "Jun").toString();
    RestEntity restEntity = RestEntity.create(APPLICATION_JSON, value);
    restResponse = join(cacheClient.put("key", restEntity));
    assertThat(restResponse).containsReturnedText("make sure at least one field has the @Field annotation");
    // Cache should not have any data
    response = cacheClient.size();
    assertThat(response).containsReturnedText("0");
}
Also used : ConfigurationBuilder(org.infinispan.configuration.cache.ConfigurationBuilder) GlobalConfigurationBuilder(org.infinispan.configuration.global.GlobalConfigurationBuilder) DummyInMemoryStoreConfigurationBuilder(org.infinispan.persistence.dummy.DummyInMemoryStoreConfigurationBuilder) 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) Test(org.testng.annotations.Test)

Example 79 with RestResponse

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

the class CacheResourceV2Test method testGetAllKeys.

@Test
public void testGetAllKeys() {
    RestResponse response = join(client.cache("default").keys());
    Collection<?> emptyKeys = Json.read(response.getBody()).asJsonList();
    assertEquals(0, emptyKeys.size());
    putTextEntryInCache("default", "1", "value");
    response = join(client.cache("default").keys());
    Collection<?> singleSet = Json.read(response.getBody()).asJsonList();
    assertEquals(1, singleSet.size());
    int entries = 10;
    for (int i = 0; i < entries; i++) {
        putTextEntryInCache("default", String.valueOf(i), "value");
    }
    response = join(client.cache("default").keys());
    Set<?> keys = Json.read(response.getBody()).asJsonList().stream().map(Json::asInteger).collect(Collectors.toSet());
    assertEquals(entries, keys.size());
    assertTrue(IntStream.range(0, entries).allMatch(keys::contains));
    response = join(client.cache("default").keys(5));
    Set<?> keysLimited = Json.read(response.getBody()).asJsonList().stream().map(Json::asInteger).collect(Collectors.toSet());
    assertEquals(5, keysLimited.size());
}
Also used : RestResponse(org.infinispan.client.rest.RestResponse) Test(org.testng.annotations.Test)

Example 80 with RestResponse

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

the class CacheResourceV2Test method testSourceConnected.

@Test
public void testSourceConnected() {
    RestCacheClient cacheClient = client.cache("default");
    RestResponse restResponse = join(cacheClient.sourceConnected());
    ResponseAssertion.assertThat(restResponse).isNotFound();
}
Also used : RestResponse(org.infinispan.client.rest.RestResponse) RestCacheClient(org.infinispan.client.rest.RestCacheClient) Test(org.testng.annotations.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