use of org.infinispan.query.test.Person in project infinispan by infinispan.
the class KeyTypeTest method createCacheManager.
@Override
protected EmbeddedCacheManager createCacheManager() throws Exception {
ConfigurationBuilder cfg = getDefaultStandaloneCacheConfig(true);
cfg.transaction().transactionMode(TransactionMode.TRANSACTIONAL).indexing().enable().storage(LOCAL_HEAP).addIndexedEntity(Person.class);
cacheManager = TestCacheManagerFactory.createCacheManager(cfg);
person1 = new Person();
person1.setName("Navin");
person1.setBlurb("Owns a macbook");
person1.setAge(20);
return cacheManager;
}
use of org.infinispan.query.test.Person in project infinispan by infinispan.
the class ContinuousQueryTest method testContinuousQuery.
public void testContinuousQuery() {
for (int i = 0; i < 2; i++) {
Person value = new Person();
value.setName("John");
value.setAge(30 + i);
cache().put(i, value);
}
QueryFactory qf = Search.getQueryFactory(cache());
ContinuousQuery<Integer, Person> cq = Search.getContinuousQuery(cache());
Query<Object[]> query = qf.create("SELECT age FROM org.infinispan.query.test.Person WHERE age <= :ageParam");
query.setParameter("ageParam", 30);
CallCountingCQResultListener<Integer, Person> listener = new CallCountingCQResultListener<>();
cq.addContinuousQueryListener(query, listener);
final Map<Integer, Integer> joined = listener.getJoined();
final Map<Integer, Integer> updated = listener.getUpdated();
final Map<Integer, Integer> left = listener.getLeft();
assertEquals(1, joined.size());
assertEquals(0, updated.size());
assertEquals(0, left.size());
joined.clear();
for (int i = 0; i < 10; i++) {
Person value = new Person();
value.setName("John");
value.setAge(i + 25);
cache().put(i, value);
}
assertEquals(5, joined.size());
assertEquals(1, updated.size());
assertEquals(0, left.size());
joined.clear();
for (int i = 0; i < 2; i++) {
Person value = new Person();
value.setName("John");
value.setAge(i + 40);
cache().put(i, value);
}
assertEquals(0, joined.size());
assertEquals(1, updated.size());
assertEquals(2, left.size());
left.clear();
for (int i = 4; i < 20; i++) {
cache().remove(i);
}
assertEquals(0, joined.size());
assertEquals(1, updated.size());
assertEquals(2, left.size());
left.clear();
// todo [anistor] Does this generate MODIFY instead of REMOVE ???
cache().clear();
assertEquals(0, joined.size());
assertEquals(1, updated.size());
assertEquals(2, left.size());
left.clear();
for (int i = 0; i < 2; i++) {
Person value = new Person();
value.setName("John");
value.setAge(i + 20);
cache().put(i, value, 5, TimeUnit.MILLISECONDS);
}
assertEquals(2, joined.size());
assertEquals(1, updated.size());
assertEquals(0, left.size());
joined.clear();
timeService.advance(6);
cache.getAdvancedCache().getExpirationManager().processExpiration();
assertEquals(0, cache().size());
assertEquals(0, joined.size());
assertEquals(1, updated.size());
assertEquals(2, left.size());
left.clear();
cq.removeContinuousQueryListener(listener);
for (int i = 0; i < 3; i++) {
Person value = new Person();
value.setName("John");
value.setAge(i + 20);
cache().put(i, value);
}
assertEquals(0, joined.size());
assertEquals(1, updated.size());
assertEquals(0, left.size());
}
use of org.infinispan.query.test.Person in project infinispan by infinispan.
the class ContinuousQueryTest method testDisallowFullTextQuery.
/**
* Fulltext continuous queries are not allowed.
*/
@Test(expectedExceptions = ParsingException.class, expectedExceptionsMessageRegExp = ".*ISPN028521:.*")
public void testDisallowFullTextQuery() {
QueryFactory qf = Search.getQueryFactory(cache());
Query<Person> query = qf.create("FROM org.infinispan.query.test.Person WHERE name : 'john'");
ContinuousQuery<Object, Object> cq = Search.getContinuousQuery(cache());
cq.addContinuousQueryListener(query, new CallCountingCQResultListener<>());
}
use of org.infinispan.query.test.Person in project infinispan by infinispan.
the class OffHeapQueryTest method testQuery.
@Test
public void testQuery() throws Exception {
cache.put("1", new Person("Donald", "MAGA", 78));
assertEquals(getIndexDocs(), 1);
Query<Object> queryFromLucene = createCacheQuery(Person.class, cache, "name", "Donald");
assertEquals(1, queryFromLucene.execute().list().size());
Query<Object> queryFromIckle = Search.getQueryFactory(cache).create("From org.infinispan.query.test.Person p where p.name:'Donald'");
assertEquals(1, queryFromIckle.execute().list().size());
}
use of org.infinispan.query.test.Person in project infinispan by infinispan.
the class DeclarativeConfigTest method simpleIndexTest.
public void simpleIndexTest() {
cache.put("1", new Person("A Person's Name", "A paragraph containing some text", 75));
Query<Person> cq = TestQueryHelperFactory.createCacheQuery(Person.class, cache, "name", "Name");
assertEquals(1, cq.execute().hitCount().orElse(-1));
List<Person> l = cq.execute().list();
assertEquals(1, l.size());
Person p = l.get(0);
assertEquals("A Person's Name", p.getName());
assertEquals("A paragraph containing some text", p.getBlurb());
assertEquals(75, p.getAge());
}
Aggregations