use of org.infinispan.protostream.sampledomain.User in project camel by apache.
the class UserUtils method createUser.
public static User createUser(String name, String surname) {
User user = new User();
user.setName(name);
user.setSurname(surname);
return user;
}
use of org.infinispan.protostream.sampledomain.User in project infinispan by infinispan.
the class HotRodCacheContinuousQueries method testQueries.
@Test
public void testQueries() {
RemoteCache<Integer, User> remoteCache = ClusteredIT.createQueryableCache(SERVER_TEST, indexed);
remoteCache.put(1, createUser(1, 25));
remoteCache.put(2, createUser(2, 25));
remoteCache.put(3, createUser(3, 20));
assertEquals(3, remoteCache.size());
QueryFactory qf = Search.getQueryFactory(remoteCache);
Query<User> query = qf.create("FROM sample_bank_account.User WHERE name = 'user1' AND age > 20");
final BlockingQueue<Integer> joined = new LinkedBlockingQueue<>();
final BlockingQueue<Integer> updated = new LinkedBlockingQueue<>();
final BlockingQueue<Integer> left = new LinkedBlockingQueue<>();
ContinuousQueryListener<Integer, User> listener = new ContinuousQueryListener<Integer, User>() {
@Override
public void resultJoining(Integer key, User value) {
joined.add(key);
}
@Override
public void resultUpdated(Integer key, User value) {
updated.add(key);
}
@Override
public void resultLeaving(Integer key) {
left.add(key);
}
};
ContinuousQuery<Integer, User> continuousQuery = Search.getContinuousQuery(remoteCache);
continuousQuery.addContinuousQueryListener(query, listener);
expectElementsInQueue(joined, 1);
expectElementsInQueue(updated, 0);
expectElementsInQueue(left, 0);
User user4 = createUser(4, 30);
user4.setName("user1");
remoteCache.put(4, user4);
expectElementsInQueue(joined, 1);
expectElementsInQueue(updated, 0);
expectElementsInQueue(left, 0);
User user1 = remoteCache.get(1);
user1.setAge(19);
remoteCache.put(1, user1);
expectElementsInQueue(joined, 0);
expectElementsInQueue(updated, 0);
expectElementsInQueue(left, 1);
user4 = remoteCache.get(4);
user4.setAge(32);
remoteCache.put(4, user4);
expectElementsInQueue(joined, 0);
expectElementsInQueue(updated, 1);
expectElementsInQueue(left, 0);
remoteCache.clear();
expectElementsInQueue(joined, 0);
expectElementsInQueue(updated, 0);
expectElementsInQueue(left, 1);
continuousQuery.removeContinuousQueryListener(listener);
user1.setAge(25);
remoteCache.put(1, user1);
expectElementsInQueue(joined, 0);
expectElementsInQueue(updated, 0);
expectElementsInQueue(left, 0);
}
use of org.infinispan.protostream.sampledomain.User in project infinispan by infinispan.
the class HotRodCacheContinuousQueries method createUser.
private User createUser(int id, int age) {
User user = new User();
user.setId(id);
user.setName("user" + id);
user.setAge(age);
user.setSurname("Doesn't matter");
user.setGender(User.Gender.MALE);
return user;
}
use of org.infinispan.protostream.sampledomain.User in project infinispan by infinispan.
the class HotRodCacheQueries method testIteratorWithQueryAndProjections.
@Test
public void testIteratorWithQueryAndProjections() {
RemoteCache<Integer, User> remoteCache = ClusteredIT.createQueryableCache(SERVER_TEST, indexed);
remoteCache.put(1, createUser1());
remoteCache.put(2, createUser2());
QueryFactory qf = Search.getQueryFactory(remoteCache);
Query<Object[]> simpleQuery = qf.create("SELECT surname, name 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());
Object[] projections = (Object[]) entries.get(0).getValue();
assertEquals("Cat", projections[0]);
assertEquals("Tom", projections[1]);
}
use of org.infinispan.protostream.sampledomain.User in project infinispan by infinispan.
the class HotRodCacheQueries method testUninverting.
/**
* Sorting on a field that does not contain DocValues so Hibernate Search is forced to uninvert it.
*
* @see <a href="https://issues.jboss.org/browse/ISPN-5729">https://issues.jboss.org/browse/ISPN-5729</a>
*/
@Test
public void testUninverting() {
RemoteCache<Integer, User> remoteCache = ClusteredIT.createQueryableCache(SERVER_TEST, indexed);
remoteCache.put(1, createUser1());
remoteCache.put(2, createUser2());
QueryFactory qf = Search.getQueryFactory(remoteCache);
Query<User> query = qf.create("FROM sample_bank_account.User WHERE name = 'John' ORDER BY id ASC");
assertEquals(0, query.execute().list().size());
}
Aggregations