Search in sources :

Example 16 with RestCacheClient

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

the class BaseCacheResourceTest method shouldPutImmortalEntryWithZeroTtlAndIdleTime.

@Test
public void shouldPutImmortalEntryWithZeroTtlAndIdleTime() {
    RestCacheClient expirationCache = client.cache("expiration");
    // when
    CompletionStage<RestResponse> response = expirationCache.post("test", "test", 0, 0);
    ResponseAssertion.assertThat(response).isOk();
    RestResponse getResponse = join(expirationCache.get("test"));
    // then
    ResponseAssertion.assertThat(getResponse).isOk();
    Assertions.assertThat(getLifespan(getResponse)).isEqualTo(DEFAULT_LIFESPAN_SECONDS);
    Assertions.assertThat(getMaxIdle(getResponse)).isEqualTo(DEFAULT_MAX_IDLE_SECONDS);
}
Also used : RestResponse(org.infinispan.client.rest.RestResponse) RestCacheClient(org.infinispan.client.rest.RestCacheClient) Test(org.testng.annotations.Test)

Example 17 with RestCacheClient

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

the class BaseCacheResourceTest method shouldPutLargeObject.

@Test
public void shouldPutLargeObject() {
    byte[] payload = new byte[1_000_000];
    final RestCacheClient binaryCache = client.cache("binary");
    CompletionStage<RestResponse> response = binaryCache.post("test", RestEntity.create(APPLICATION_OCTET_STREAM, payload));
    ResponseAssertion.assertThat(response).isOk();
    ResponseAssertion.assertThat(response).hasEtag();
    RestResponse getResponse = join(binaryCache.get("test"));
    Assertions.assertThat(getResponse.getBodyAsByteArray().length).isEqualTo(1_000_000);
}
Also used : RestResponse(org.infinispan.client.rest.RestResponse) RestCacheClient(org.infinispan.client.rest.RestCacheClient) Test(org.testng.annotations.Test)

Example 18 with RestCacheClient

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

the class BaseCacheResourceTest method shouldPutImmortalEntryWithMinusOneTtlAndIdleTime.

@Test
public void shouldPutImmortalEntryWithMinusOneTtlAndIdleTime() {
    RestCacheClient expirationCache = client.cache("expiration");
    // when
    CompletionStage<RestResponse> response = expirationCache.put("test", "test", -1, -1);
    ResponseAssertion.assertThat(response).isOk();
    RestResponse getResponse = join(expirationCache.get("test"));
    // then
    ResponseAssertion.assertThat(getResponse).isOk();
    Assertions.assertThat(getLifespan(getResponse)).isNull();
    Assertions.assertThat(getMaxIdle(getResponse)).isNull();
}
Also used : RestResponse(org.infinispan.client.rest.RestResponse) RestCacheClient(org.infinispan.client.rest.RestCacheClient) Test(org.testng.annotations.Test)

Example 19 with RestCacheClient

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

the class CacheResourceTest method testIfModifiedHeaderForCache.

@Test
public void testIfModifiedHeaderForCache() {
    putStringValueInCache("expiration", "test", "test");
    RestCacheClient cacheClient = client.cache("expiration");
    RestResponse resp = join(cacheClient.get("test"));
    String dateLast = resp.headers().get("Last-Modified").get(0);
    CompletionStage<RestResponse> sameLastModAndIfModified = cacheClient.get("test", createHeaders(IF_MODIFIED_SINCE, dateLast));
    assertThat(sameLastModAndIfModified).isNotModified();
    putStringValueInCache("expiration", "test", "test-new");
    RestResponse lastmodAfterIfModified = join(cacheClient.get("test"));
    dateLast = lastmodAfterIfModified.headers().get("Last-Modified").get(0);
    assertThat(lastmodAfterIfModified).isOk();
    Map<String, String> header = createHeaders(IF_MODIFIED_SINCE, plus1Day(dateLast));
    CompletionStage<RestResponse> lastmodBeforeIfModified = cacheClient.get("test", header);
    assertThat(lastmodBeforeIfModified).isNotModified();
}
Also used : 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 20 with RestCacheClient

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

the class CacheResourceTest method shouldReadTextWithPojoCache.

@Test
public void shouldReadTextWithPojoCache() {
    // given
    RestCacheClient pojoCache = client.cache("pojoCache");
    String key = "k1";
    String value = "v1";
    join(pojoCache.put(key, value));
    // when
    RestResponse response = join(pojoCache.get(key));
    // then
    assertThat(response).isOk();
    assertThat(response).hasContentType(TEXT_PLAIN_TYPE);
    assertThat(response).hasReturnedText(value);
}
Also used : 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)

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