Search in sources :

Example 21 with Person

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;
}
Also used : ConfigurationBuilder(org.infinispan.configuration.cache.ConfigurationBuilder) Person(org.infinispan.query.test.Person)

Example 22 with Person

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());
}
Also used : QueryFactory(org.infinispan.query.dsl.QueryFactory) Person(org.infinispan.query.test.Person)

Example 23 with Person

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<>());
}
Also used : QueryFactory(org.infinispan.query.dsl.QueryFactory) Person(org.infinispan.query.test.Person) SingleCacheManagerTest(org.infinispan.test.SingleCacheManagerTest) Test(org.testng.annotations.Test)

Example 24 with Person

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());
}
Also used : Person(org.infinispan.query.test.Person) SingleCacheManagerTest(org.infinispan.test.SingleCacheManagerTest) Test(org.testng.annotations.Test)

Example 25 with Person

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());
}
Also used : Person(org.infinispan.query.test.Person)

Aggregations

Person (org.infinispan.query.test.Person)82 QueryFactory (org.infinispan.query.dsl.QueryFactory)21 Test (org.testng.annotations.Test)11 ObjectFilter (org.infinispan.objectfilter.ObjectFilter)6 SingleCacheManagerTest (org.infinispan.test.SingleCacheManagerTest)6 TransactionManager (javax.transaction.TransactionManager)5 MultipleCacheManagersTest (org.infinispan.test.MultipleCacheManagersTest)5 MagicKey (org.infinispan.distribution.MagicKey)3 AnotherGrassEater (org.infinispan.query.test.AnotherGrassEater)3 ArrayList (java.util.ArrayList)2 ConfigurationBuilder (org.infinispan.configuration.cache.ConfigurationBuilder)2 NumberFormat (java.text.NumberFormat)1 HashMap (java.util.HashMap)1 Set (java.util.Set)1 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)1 MBeanServer (javax.management.MBeanServer)1 ObjectName (javax.management.ObjectName)1 RollbackException (javax.transaction.RollbackException)1 CacheException (org.infinispan.commons.CacheException)1 CacheEntry (org.infinispan.container.entries.CacheEntry)1