use of org.infinispan.protostream.sampledomain.User in project infinispan by infinispan.
the class HotRodCacheQueries method testAttributeQuery.
@Test
public void testAttributeQuery() {
RemoteCache<Integer, User> remoteCache = ClusteredIT.createQueryableCache(SERVER_TEST, indexed);
remoteCache.put(1, createUser1());
remoteCache.put(2, createUser2());
// get user back from remote cache and check its attributes
User fromCache = remoteCache.get(1);
assertUser1(fromCache);
// get user back from remote cache via query and check its attributes
QueryFactory qf = Search.getQueryFactory(remoteCache);
Query<User> query = qf.create("FROM sample_bank_account.User WHERE name = 'Tom'");
List<User> list = query.execute().list();
assertNotNull(list);
assertEquals(1, list.size());
assertEquals(User.class, list.get(0).getClass());
assertUser1(list.get(0));
}
use of org.infinispan.protostream.sampledomain.User in project infinispan by infinispan.
the class HotRodCacheQueries method testEmbeddedAttributeQuery.
@Test
public void testEmbeddedAttributeQuery() {
RemoteCache<Integer, User> remoteCache = ClusteredIT.createQueryableCache(SERVER_TEST, indexed);
remoteCache.put(1, createUser1());
remoteCache.put(2, createUser2());
// get user back from remote cache via query and check its attributes
QueryFactory qf = Search.getQueryFactory(remoteCache);
Query<User> query = qf.create("FROM sample_bank_account.User u WHERE u.addresses.postCode = '1234'");
List<User> list = query.execute().list();
assertNotNull(list);
assertEquals(1, list.size());
assertEquals(User.class, list.get(0).getClass());
assertUser1(list.get(0));
}
use of org.infinispan.protostream.sampledomain.User in project infinispan by infinispan.
the class HotRodCacheQueries method testIteratorWithQuery.
@Test
public void testIteratorWithQuery() {
RemoteCache<Integer, User> remoteCache = ClusteredIT.createQueryableCache(SERVER_TEST, indexed);
remoteCache.put(1, createUser1());
remoteCache.put(2, createUser2());
QueryFactory qf = Search.getQueryFactory(remoteCache);
Query<User> simpleQuery = qf.create("FROM sample_bank_account.User WHERE name = 'Tom'");
List<Map.Entry<Object, Object>> entries = new ArrayList<>(1);
try (CloseableIterator<Map.Entry<Object, Object>> iter = remoteCache.retrieveEntriesByQuery(simpleQuery, null, 3)) {
while (iter.hasNext()) {
entries.add(iter.next());
}
}
assertEquals(1, entries.size());
assertEquals("Cat", ((User) entries.get(0).getValue()).getSurname());
}
use of org.infinispan.protostream.sampledomain.User in project infinispan by infinispan.
the class HotRodListenerWithDslFilter method testEventFilter.
@Test
public void testEventFilter() {
RemoteCache<Integer, User> remoteCache = ClusteredIT.createQueryableCache(SERVER_TEST, true);
User user1 = new User();
user1.setId(1);
user1.setName("John");
user1.setSurname("Doe");
user1.setGender(User.Gender.MALE);
user1.setAge(22);
user1.setAccountIds(new HashSet<>(Arrays.asList(1, 2)));
user1.setNotes("Lorem ipsum dolor sit amet");
Address address1 = new Address();
address1.setStreet("Main Street");
address1.setPostCode("X1234");
user1.setAddresses(Collections.singletonList(address1));
User user2 = new User();
user2.setId(2);
user2.setName("Spider");
user2.setSurname("Man");
user2.setGender(User.Gender.MALE);
user2.setAge(32);
user2.setAccountIds(Collections.singleton(3));
Address address2 = new Address();
address2.setStreet("Old Street");
address2.setPostCode("Y12");
Address address3 = new Address();
address3.setStreet("Bond Street");
address3.setPostCode("ZZ");
user2.setAddresses(Arrays.asList(address2, address3));
User user3 = new User();
user3.setId(3);
user3.setName("Spider");
user3.setSurname("Woman");
user3.setGender(User.Gender.FEMALE);
user3.setAge(31);
user3.setAccountIds(Collections.emptySet());
remoteCache.put(user1.getId(), user1);
remoteCache.put(user2.getId(), user2);
remoteCache.put(user3.getId(), user3);
assertEquals(3, remoteCache.size());
SerializationContext serCtx = MarshallerUtil.getSerializationContext(remoteCache.getRemoteCacheManager());
QueryFactory qf = Search.getQueryFactory(remoteCache);
Query<User> query = qf.<User>create("SELECT age FROM sample_bank_account.User WHERE age <= :ageParam").setParameter("ageParam", 32);
ClientEntryListener listener = new ClientEntryListener(serCtx);
ClientEvents.addClientQueryListener(remoteCache, listener, query);
expectElementsInQueue(listener.createEvents, 3);
user3.setAge(40);
remoteCache.put(user1.getId(), user1);
remoteCache.put(user2.getId(), user2);
remoteCache.put(user3.getId(), user3);
assertEquals(3, remoteCache.size());
expectElementsInQueue(listener.modifyEvents, 2);
remoteCache.removeClientListener(listener);
}
use of org.infinispan.protostream.sampledomain.User 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());
}
}
Aggregations