Search in sources :

Example 16 with RestResponse

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

the class SinglePortTest method shouldUpgradeThroughHTTP11UpgradeHeaders.

@Test
public void shouldUpgradeThroughHTTP11UpgradeHeaders() {
    // given
    restServer = RestTestingUtil.createDefaultRestServer("rest", "default");
    RestServerRouteDestination restDestination = new RestServerRouteDestination("rest1", restServer);
    SinglePortRouteSource singlePortSource = new SinglePortRouteSource();
    Route<SinglePortRouteSource, RestServerRouteDestination> routeToRest = new Route<>(singlePortSource, restDestination);
    RouterConfigurationBuilder routerConfigurationBuilder = new RouterConfigurationBuilder();
    routerConfigurationBuilder.singlePort().port(0).ip(InetAddress.getLoopbackAddress()).routing().add(routeToRest);
    router = new Router(routerConfigurationBuilder.build());
    router.start();
    int port = router.getRouter(EndpointRouter.Protocol.SINGLE_PORT).get().getPort();
    // when
    RestClientConfigurationBuilder builder = new RestClientConfigurationBuilder();
    builder.addServer().host("localhost").port(port).protocol(Protocol.HTTP_20);
    httpClient = RestClient.forConfiguration(builder.build());
    CompletionStage<RestResponse> response = httpClient.cache("default").post("test", VALUE);
    // then
    ResponseAssertion.assertThat(response).hasNoContent();
}
Also used : RestClientConfigurationBuilder(org.infinispan.client.rest.configuration.RestClientConfigurationBuilder) SinglePortRouteSource(org.infinispan.server.router.routes.singleport.SinglePortRouteSource) RestResponse(org.infinispan.client.rest.RestResponse) Router(org.infinispan.server.router.Router) EndpointRouter(org.infinispan.server.router.router.EndpointRouter) RestServerRouteDestination(org.infinispan.server.router.routes.rest.RestServerRouteDestination) RouterConfigurationBuilder(org.infinispan.server.router.configuration.builder.RouterConfigurationBuilder) Route(org.infinispan.server.router.routes.Route) Test(org.junit.Test)

Example 17 with RestResponse

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

the class BaseRestSearchTest method testQueryStats.

@Test
public void testQueryStats() throws Exception {
    RestResponse response = join(cacheClient.queryStats());
    if (!getConfigBuilder().indexing().enabled()) {
        ResponseAssertion.assertThat(response).isBadRequest();
    } else {
        ResponseAssertion.assertThat(response).isOk();
        Json stats = Json.read(response.getBody());
        assertTrue(stats.at("search_query_execution_count").asLong() >= 0);
        assertTrue(stats.at("search_query_total_time").asLong() >= 0);
        assertTrue(stats.at("search_query_execution_max_time").asLong() >= 0);
        assertTrue(stats.at("search_query_execution_avg_time").asLong() >= 0);
        assertTrue(stats.at("object_loading_total_time").asLong() >= 0);
        assertTrue(stats.at("object_loading_execution_max_time").asLong() >= 0);
        assertTrue(stats.at("object_loading_execution_avg_time").asLong() >= 0);
        assertTrue(stats.at("objects_loaded_count").asLong() >= 0);
        assertNotNull(stats.at("search_query_execution_max_time_query_string").asString());
        RestResponse clearResponse = join(cacheClient.clearQueryStats());
        response = join(cacheClient.queryStats());
        stats = Json.read(response.getBody());
        ResponseAssertion.assertThat(clearResponse).isOk();
        assertEquals(stats.at("search_query_execution_count").asLong(), 0);
        assertEquals(stats.at("search_query_execution_max_time").asLong(), 0);
    }
}
Also used : RestResponse(org.infinispan.client.rest.RestResponse) Json(org.infinispan.commons.dataconversion.internal.Json) Test(org.testng.annotations.Test) MultipleCacheManagersTest(org.infinispan.test.MultipleCacheManagersTest)

Example 18 with RestResponse

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

the class BaseRestSearchTest method testIndexStats.

@Test
public void testIndexStats() {
    RestResponse response = join(cacheClient.indexStats());
    if (!getConfigBuilder().indexing().enabled()) {
        ResponseAssertion.assertThat(response).isBadRequest();
    } else {
        ResponseAssertion.assertThat(response).isOk();
        Json stats = Json.read(response.getBody());
        Json indexClassNames = stats.at("indexed_class_names");
        String indexName = "org.infinispan.rest.search.entity.Person";
        assertEquals(indexClassNames.at(0).asString(), indexName);
        assertNotNull(stats.at("indexed_entities_count"));
        // TODO: Index sizes are not currently exposed (HSEARCH-4056)
        assertTrue(stats.at("index_sizes").at(indexName).asInteger() >= 0);
    }
}
Also used : RestResponse(org.infinispan.client.rest.RestResponse) Json(org.infinispan.commons.dataconversion.internal.Json) Test(org.testng.annotations.Test) MultipleCacheManagersTest(org.infinispan.test.MultipleCacheManagersTest)

Example 19 with RestResponse

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

the class IndexedCacheNonIndexedEntityTest method shouldPreventNonIndexedEntities.

@Test
public void shouldPreventNonIndexedEntities() {
    CompletionStage<RestResponse> response = client.schemas().post("customer", SCHEMA);
    ResponseAssertion.assertThat(response).isOk();
    ConfigurationBuilder configurationBuilder = getDefaultStandaloneCacheConfig(false);
    configurationBuilder.statistics().enable();
    configurationBuilder.encoding().mediaType(APPLICATION_PROTOSTREAM_TYPE).indexing().enable().storage(LOCAL_HEAP).addIndexedEntity("NonIndexed");
    String config = cacheConfigToJson(CACHE_NAME, configurationBuilder.build());
    RestEntity configEntity = RestEntity.create(MediaType.APPLICATION_JSON, config);
    RestCacheClient cacheClient = client.cache(CACHE_NAME);
    response = cacheClient.createWithConfiguration(configEntity, VOLATILE);
    // The SearchMapping is started lazily, creating and starting the cache will not throw errors
    ResponseAssertion.assertThat(response).isOk();
    // Force initialization of the SearchMapping
    response = cacheClient.query("FROM NonIndexed");
    ResponseAssertion.assertThat(response).isBadRequest();
    String errorText = "The configured indexed-entity type 'NonIndexed' must be indexed. Please annotate it with @Indexed";
    ResponseAssertion.assertThat(response).containsReturnedText(errorText);
    // Call Indexer operations
    response = cacheClient.clearIndex();
    ResponseAssertion.assertThat(response).containsReturnedText(errorText);
    // The Indexer should not have "running" status
    Indexer indexer = Search.getIndexer(cacheManager.getCache(CACHE_NAME));
    assertFalse(indexer.isRunning());
}
Also used : ConfigurationBuilder(org.infinispan.configuration.cache.ConfigurationBuilder) GlobalConfigurationBuilder(org.infinispan.configuration.global.GlobalConfigurationBuilder) RestClientConfigurationBuilder(org.infinispan.client.rest.configuration.RestClientConfigurationBuilder) Indexer(org.infinispan.query.Indexer) RestEntity(org.infinispan.client.rest.RestEntity) RestResponse(org.infinispan.client.rest.RestResponse) RestCacheClient(org.infinispan.client.rest.RestCacheClient) SingleCacheManagerTest(org.infinispan.test.SingleCacheManagerTest) Test(org.testng.annotations.Test)

Example 20 with RestResponse

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

the class IndexedRestSearchTest method testReplaceIndexedDocument.

@Test
public void testReplaceIndexedDocument() throws Exception {
    put(10, createPerson(0, "P", "", "?", "?", "MALE").toString());
    put(10, createPerson(0, "P", "Surname", "?", "?", "MALE").toString());
    RestResponse response = join(get("10", "application/json"));
    Json person = Json.read(response.getBody());
    assertEquals("Surname", person.at("surname").asString());
}
Also used : RestResponse(org.infinispan.client.rest.RestResponse) Json(org.infinispan.commons.dataconversion.internal.Json) 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