Search in sources :

Example 51 with RestCacheClient

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

the class CacheResourceTest method shouldConvertExistingSerializableObjectToXml.

@Test
public void shouldConvertExistingSerializableObjectToXml() {
    // given
    TestClass testClass = new TestClass();
    testClass.setName("test");
    RestCacheClient objectCache = client.cache("objectCache");
    String xml = "<org.infinispan.rest.TestClass><name>test</name></org.infinispan.rest.TestClass>";
    join(objectCache.put("test", RestEntity.create(APPLICATION_XML, xml)));
    // when
    RestResponse response = join(objectCache.get("test", APPLICATION_XML_TYPE));
    // then
    assertThat(response).isOk();
    assertThat(response).hasContentType("application/xml");
    assertThat(response).hasReturnedText(xml);
}
Also used : RestResponse(org.infinispan.client.rest.RestResponse) RestCacheClient(org.infinispan.client.rest.RestCacheClient) TestClass(org.infinispan.rest.TestClass) Util.getResourceAsString(org.infinispan.commons.util.Util.getResourceAsString) Test(org.testng.annotations.Test)

Example 52 with RestCacheClient

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

the class CacheResourceTest method shouldReadAsBinaryWithPojoCache.

@Test
public void shouldReadAsBinaryWithPojoCache() {
    // given
    RestCacheClient pojoCache = client.cache("pojoCache");
    String key = "test";
    TestClass value = new TestClass();
    value.setName("test");
    join(pojoCache.put(key, value.toJson().toString()));
    // when
    RestResponse response = join(pojoCache.get(key, APPLICATION_OCTET_STREAM_TYPE));
    // then
    assertThat(response).isOk();
    assertThat(response).hasContentType(APPLICATION_OCTET_STREAM_TYPE);
}
Also used : RestResponse(org.infinispan.client.rest.RestResponse) RestCacheClient(org.infinispan.client.rest.RestCacheClient) TestClass(org.infinispan.rest.TestClass) Util.getResourceAsString(org.infinispan.commons.util.Util.getResourceAsString) Test(org.testng.annotations.Test)

Example 53 with RestCacheClient

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

the class CacheResourceTest method shouldIgnoreDisabledCaches.

@Test
public void shouldIgnoreDisabledCaches() {
    putStringValueInCache("default", "K", "V");
    RestCacheClient cacheClient = client.cache("default");
    CompletionStage<RestResponse> response = cacheClient.get("K");
    assertThat(response).isOk();
    if (security) {
        Security.doAs(TestingUtil.makeSubject(AuthorizationPermission.ADMIN.name()), (PrivilegedAction<Void>) () -> {
            restServer().ignoreCache("default");
            return null;
        });
    } else {
        restServer().ignoreCache("default");
    }
    response = cacheClient.get("K");
    assertThat(response).isServiceUnavailable();
    if (security) {
        Security.doAs(TestingUtil.makeSubject(AuthorizationPermission.ADMIN.name()), (PrivilegedAction<Void>) () -> {
            restServer().unignoreCache("default");
            return null;
        });
    } else {
        restServer().unignoreCache("default");
    }
    response = cacheClient.get("K");
    assertThat(response).isOk();
}
Also used : RestResponse(org.infinispan.client.rest.RestResponse) RestCacheClient(org.infinispan.client.rest.RestCacheClient) Test(org.testng.annotations.Test)

Example 54 with RestCacheClient

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

the class CacheResourceTest method shouldDeleteExistingValueEvenWithoutMetadata.

@Test
public void shouldDeleteExistingValueEvenWithoutMetadata() {
    RestCacheClient defaultCache = client.cache("default");
    join(defaultCache.put("test", "test"));
    // when
    CompletionStage<RestResponse> response = defaultCache.remove("test");
    // then
    assertThat(response).isOk();
    Assertions.assertThat(join(defaultCache.size()).getBody()).isEqualTo("0");
}
Also used : RestResponse(org.infinispan.client.rest.RestResponse) RestCacheClient(org.infinispan.client.rest.RestCacheClient) Test(org.testng.annotations.Test)

Example 55 with RestCacheClient

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

the class RestMetricsResource method testMetrics.

@Test
public void testMetrics() throws Exception {
    RestClient client = SERVER_TEST.rest().create();
    RestMetricsClient metricsClient = client.metrics();
    String metricName = "cache_manager_default_cache_" + SERVER_TEST.getMethodName() + "_statistics_stores";
    int NUM_PUTS = 10;
    try (RestResponse response = sync(metricsClient.metrics())) {
        assertEquals(200, response.getStatus());
        checkIsPrometheus(response.contentType());
        String body = response.getBody();
        assertThat(body).contains("base", "vendor", metricName);
        checkRule(body, "vendor_" + metricName, (stringValue) -> {
            double parsed = Double.parseDouble(stringValue);
            assertThat(parsed).isZero();
        });
    }
    // put some entries then check that the stats were updated
    RestCacheClient cache = client.cache(SERVER_TEST.getMethodName());
    for (int i = 0; i < NUM_PUTS; i++) {
        RestResponse putResp = sync(cache.put("k" + i, "v" + i));
        assertEquals(204, putResp.getStatus());
    }
    try (RestResponse response = sync(metricsClient.metrics())) {
        assertEquals(200, response.getStatus());
        checkIsPrometheus(response.contentType());
        String body = response.getBody();
        assertThat(body).contains("base", "vendor", metricName);
        checkRule(body, "vendor_" + metricName, (stringValue) -> {
            double parsed = Double.parseDouble(stringValue);
            assertThat(parsed).isEqualTo(10.0);
        });
    }
    // delete cache and check that the metric is gone
    sync(client.cache(SERVER_TEST.getMethodName()).delete());
    try (RestResponse response = sync(metricsClient.metrics())) {
        assertEquals(200, response.getStatus());
        checkIsPrometheus(response.contentType());
        String body = response.getBody();
        assertThat(body).contains("base", "vendor");
        // metric is not present anymore:
        assertThat(body).doesNotContain(metricName);
    }
}
Also used : RestResponse(org.infinispan.client.rest.RestResponse) RestClient(org.infinispan.client.rest.RestClient) RestCacheClient(org.infinispan.client.rest.RestCacheClient) RestMetricsClient(org.infinispan.client.rest.RestMetricsClient) Test(org.junit.Test)

Aggregations

RestCacheClient (org.infinispan.client.rest.RestCacheClient)66 RestResponse (org.infinispan.client.rest.RestResponse)41 Test (org.testng.annotations.Test)34 Util.getResourceAsString (org.infinispan.commons.util.Util.getResourceAsString)16 RestEntity (org.infinispan.client.rest.RestEntity)14 Json (org.infinispan.commons.dataconversion.internal.Json)13 RestClient (org.infinispan.client.rest.RestClient)11 Test (org.junit.Test)8 ConfigurationBuilder (org.infinispan.configuration.cache.ConfigurationBuilder)7 AbstractMultipleSitesTest (org.infinispan.xsite.AbstractMultipleSitesTest)7 RestClientConfigurationBuilder (org.infinispan.client.rest.configuration.RestClientConfigurationBuilder)6 GlobalConfigurationBuilder (org.infinispan.configuration.global.GlobalConfigurationBuilder)5 TestClass (org.infinispan.rest.TestClass)5 TestUser (org.infinispan.server.test.api.TestUser)5 DummyInMemoryStoreConfigurationBuilder (org.infinispan.persistence.dummy.DummyInMemoryStoreConfigurationBuilder)3 HashMap (java.util.HashMap)2 RestCacheManagerClient (org.infinispan.client.rest.RestCacheManagerClient)2 RestMetricsClient (org.infinispan.client.rest.RestMetricsClient)2 MediaType (org.infinispan.commons.dataconversion.MediaType)2 EmbeddedCacheManager (org.infinispan.manager.EmbeddedCacheManager)2