Search in sources :

Example 26 with Person

use of org.infinispan.query.test.Person in project infinispan by infinispan.

the class LoopingWriterTest method writeStuff.

/**
 * We write a lot of elements.. and run a Query occasionally to check.
 */
private void writeStuff(final Cache<Object, Object> cache) {
    final long startTime = System.nanoTime();
    for (int i = 1; i < TOTAL_LOOPS; i++) {
        final String key = "K" + i;
        final Person value = new Person(key, key, i);
        cache.put(key, value);
        if (i % QUERY_PERIODICITY == 0) {
            countElementsViaQuery(cache, i);
        }
        if (i % TIMESAMPLE_PERIODICITY == 0) {
            final long currentTimeStamp = System.nanoTime();
            final long elapsed = currentTimeStamp - startTime;
            final double elementsWrittenPerSecond = ((double) TimeUnit.NANOSECONDS.convert(i, TimeUnit.SECONDS)) / elapsed;
            NumberFormat nf = NumberFormat.getNumberInstance();
            nf.setMaximumFractionDigits(2);
            nf.setGroupingUsed(true);
            System.out.println("Transactions committed to index per second: " + nf.format(elementsWrittenPerSecond) + ". Total documents: " + i + " Total time: " + Util.prettyPrintTime(elapsed, TimeUnit.NANOSECONDS));
        }
    }
}
Also used : Person(org.infinispan.query.test.Person) NumberFormat(java.text.NumberFormat)

Example 27 with Person

use of org.infinispan.query.test.Person in project infinispan by infinispan.

the class SharedCacheLoaderQueryIndexTest method testPreloadIndexingAfterAddingNewNode.

public void testPreloadIndexingAfterAddingNewNode() {
    loadCacheEntries(this.<String, Person>caches().get(0));
    List<DummyInMemoryStore> cacheStores = TestingUtil.cachestores(caches());
    for (DummyInMemoryStore dimcs : cacheStores) {
        assertTrue("Cache misconfigured, maybe cache store not pointing to same place, maybe passivation on...etc", dimcs.contains(persons[0].getName()));
        int clear = dimcs.stats().get("clear");
        assertEquals("Cache store should not be cleared, purgeOnStartup is false", clear, 0);
        int write = dimcs.stats().get("write");
        assertEquals("Cache store should have been written to 4 times, but was written to " + write + " times", write, 4);
    }
    // Before adding a node, verify that the query resolves properly
    executeSimpleQuery(this.<String, Person>caches().get(0));
    addNodeCheckingContentsAndQuery();
}
Also used : DummyInMemoryStore(org.infinispan.persistence.dummy.DummyInMemoryStore) Person(org.infinispan.query.test.Person)

Example 28 with Person

use of org.infinispan.query.test.Person in project infinispan by infinispan.

the class QueryPhrasesTest method testKeyword.

public void testKeyword() {
    loadTestingData();
    Query<Person> cacheQuery = createCacheQuery(Person.class, "name:'Eats' OR blurb:'Eats'");
    List<Person> found = cacheQuery.execute().list();
    assertEquals(2, found.size());
    person4 = new Person();
    person4.setName("Some name with Eats");
    person4.setBlurb("Description without keyword.");
    cache.put("someKey", person4);
    found = cacheQuery.execute().list();
    assertEquals(3, found.size());
    assertTrue(found.contains(person2));
    assertTrue(found.contains(person3));
    assertTrue(found.contains(person4));
}
Also used : Person(org.infinispan.query.test.Person)

Example 29 with Person

use of org.infinispan.query.test.Person in project infinispan by infinispan.

the class QueryPhrasesTest method testPhraseSentence.

public void testPhraseSentence() {
    loadTestingData();
    Query<Person> cacheQuery = createCacheQuery(Person.class, "blurb:'Eats grass'");
    List<Person> found = cacheQuery.execute().list();
    assertEquals(1, found.size());
    assertTrue(found.contains(person2));
    person4 = new Person();
    person4.setName("Another goat");
    person4.setBlurb("Eats grass and drinks water.");
    cache.put("anotherKey", person4);
    found = cacheQuery.execute().list();
    assertEquals(2, found.size());
    assertTrue(found.contains(person2));
    assertTrue(found.contains(person4));
}
Also used : Person(org.infinispan.query.test.Person)

Example 30 with Person

use of org.infinispan.query.test.Person in project infinispan by infinispan.

the class QueryPhrasesTest method loadTestingData.

private void loadTestingData() {
    person1 = new Person();
    person1.setName("Navin Surtani");
    person1.setBlurb("Likes playing WoW");
    person1.setAge(20);
    person2 = new Person();
    person2.setName("Big Goat");
    person2.setBlurb("Eats grass");
    person2.setAge(30);
    person3 = new Person();
    person3.setName("Mini Goat");
    person3.setBlurb("Eats cheese");
    person3.setAge(25);
    cache.put(key1, person1);
    cache.put(key2, person2);
    cache.put(key3, person3);
}
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