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();
}
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);
}
}
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);
}
}
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());
}
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());
}
Aggregations