use of org.infinispan.client.rest.RestCacheClient in project infinispan by infinispan.
the class AbstractAuthorization method testRestWriterCannotRead.
private void testRestWriterCannotRead(String... explicitRoles) {
restCreateAuthzCache(explicitRoles);
RestCacheClient writerCache = getServerTest().rest().withClientConfiguration(restBuilders.get(TestUser.WRITER)).get().cache(getServerTest().getMethodName());
sync(writerCache.put("k1", "v1"));
assertStatus(FORBIDDEN, writerCache.get("k1"));
for (TestUser user : EnumSet.of(TestUser.OBSERVER, TestUser.DEPLOYER)) {
RestCacheClient userCache = getServerTest().rest().withClientConfiguration(restBuilders.get(user)).get().cache(getServerTest().getMethodName());
assertEquals("v1", sync(userCache.get("k1")).getBody());
}
}
use of org.infinispan.client.rest.RestCacheClient in project infinispan by infinispan.
the class AbstractAuthorization method testNonBulkReadUsersCannotQuery.
@Test
public void testNonBulkReadUsersCannotQuery() {
org.infinispan.configuration.cache.ConfigurationBuilder builder = prepareIndexedCache();
// Hot Rod
for (TestUser user : EnumSet.of(TestUser.READER, TestUser.WRITER)) {
RemoteCache<Integer, User> userCache = getServerTest().hotrod().withClientConfiguration(clientConfigurationWithProtostreamMarshaller(user)).withServerConfiguration(builder).get();
QueryFactory qf = Search.getQueryFactory(userCache);
Query<User> query = qf.create("FROM sample_bank_account.User WHERE name = 'Tom'");
Exceptions.expectException(HotRodClientException.class, "(?s).*ISPN000287.*", () -> query.execute().list());
}
// REST
for (TestUser user : EnumSet.of(TestUser.READER, TestUser.WRITER, TestUser.MONITOR)) {
RestCacheClient userCache = getServerTest().rest().withClientConfiguration(restBuilders.get(user)).get().cache(getServerTest().getMethodName());
assertStatus(FORBIDDEN, userCache.query("FROM sample_bank_account.User WHERE name = 'Tom'"));
assertStatus(OK, userCache.searchStats());
assertStatus(OK, userCache.indexStats());
assertStatus(OK, userCache.queryStats());
}
}
use of org.infinispan.client.rest.RestCacheClient in project infinispan by infinispan.
the class RestOperations method testRestOperations.
@Test
public void testRestOperations() {
RestClientConfigurationBuilder builder = new RestClientConfigurationBuilder();
builder.protocol(protocol);
RestClient client = SERVER_TEST.rest().withClientConfiguration(builder).create();
RestCacheClient cache = client.cache(SERVER_TEST.getMethodName());
RestResponse response = sync(cache.put("k1", "v1"));
assertEquals(204, response.getStatus());
assertEquals(protocol, response.getProtocol());
response = sync(cache.get("k1"));
assertEquals(200, response.getStatus());
assertEquals(protocol, response.getProtocol());
assertEquals("v1", response.getBody());
response = sync(cache.remove("k1"));
assertEquals(204, response.getStatus());
assertEquals(protocol, response.getProtocol());
response = sync(cache.get("k1"));
assertEquals(404, response.getStatus());
assertEquals(protocol, response.getProtocol());
}
use of org.infinispan.client.rest.RestCacheClient in project infinispan by infinispan.
the class RestOperations method testPutWithTimeToLive.
@Test
public void testPutWithTimeToLive() throws InterruptedException {
RestClientConfigurationBuilder builder = new RestClientConfigurationBuilder();
builder.protocol(protocol);
RestClient client = SERVER_TEST.rest().withClientConfiguration(builder).create();
RestCacheClient cache = client.cache(SERVER_TEST.getMethodName());
sync(cache.post("k1", "v1", 1, 1));
assertEquals(HttpResponseStatus.OK.code(), sync(cache.get("k1")).getStatus());
Thread.sleep(2000);
assertEquals(HttpResponseStatus.NOT_FOUND.code(), sync(cache.get("k1")).getStatus());
}
use of org.infinispan.client.rest.RestCacheClient in project infinispan by infinispan.
the class XSiteHotRodCacheOperations method getTotalMemoryEntries.
private int getTotalMemoryEntries(String lonXML) {
RestClient restClient = SERVER_TEST.rest(LON).withServerConfiguration(new StringConfiguration(lonXML)).get();
RestCacheClient client = restClient.cache(SERVER_TEST.getMethodName());
Json json = Json.read(sync(client.stats()).getBody());
return json.asJsonMap().get("current_number_of_entries_in_memory").asInteger();
}
Aggregations