Search in sources :

Example 1 with AnotherGrassEater

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

the class LocalCacheTest method prepareTestingData.

private void prepareTestingData() {
    person1 = new Person();
    person1.setName("Navin Surtani");
    person1.setAge(20);
    person1.setBlurb("Likes playing WoW");
    person1.setNonIndexedField("test1");
    person2 = new Person();
    person2.setName("Big Goat");
    person2.setAge(30);
    person2.setBlurb("Eats grass");
    person2.setNonIndexedField("test2");
    person3 = new Person();
    person3.setName("Mini Goat");
    person3.setAge(25);
    person3.setBlurb("Eats cheese");
    person3.setNonIndexedField("test3");
    anotherGrassEater = new AnotherGrassEater("Another grass-eater", "Eats grass");
    StaticTestingErrorHandler.assertAllGood(cache);
}
Also used : AnotherGrassEater(org.infinispan.query.test.AnotherGrassEater) Person(org.infinispan.query.test.Person)

Example 2 with AnotherGrassEater

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

the class QueryMBeanTest method testQueryStats.

public void testQueryStats() throws Exception {
    // start cache
    Cache<String, Object> cache = cacheManager.getCache(CACHE_NAME);
    ObjectName name = getQueryStatsObjectName(TEST_JMX_DOMAIN, CACHE_NAME);
    MBeanServer mBeanServer = mBeanServerLookup.getMBeanServer();
    assertTrue(mBeanServer.isRegistered(name));
    // check that our settings are not ignored
    QueryFactory queryFactory = Search.getQueryFactory(cache);
    SearchStatistics searchStatistics = Search.getSearchStatistics(cache);
    assertTrue(searchStatistics.getQueryStatistics().isEnabled());
    // add some test data
    for (int i = 0; i < numberOfEntries; i++) {
        Person person = new Person();
        person.setName("key" + i);
        person.setAge(i);
        person.setBlurb("value " + i);
        person.setNonIndexedField("i: " + i);
        cache.put(person.getName(), person);
    }
    assertEquals(0L, mBeanServer.getAttribute(name, "SearchQueryExecutionCount"));
    String q = String.format("FROM %s WHERE blurb:'value'", Person.class.getName());
    Query<?> cacheQuery = queryFactory.create(q);
    // Executing first query
    List<?> found = cacheQuery.execute().list();
    assertEquals(1L, mBeanServer.getAttribute(name, "SearchQueryExecutionCount"));
    assertEquals(numberOfEntries, found.size());
    assertEquals(numberOfEntries, mBeanServer.invoke(name, "getNumberOfIndexedEntities", new Object[] { Person.class.getName() }, new String[] { String.class.getName() }));
    assertEquals(2, CompletionStages.join(searchStatistics.getIndexStatistics().computeIndexInfos()).size());
    // add more test data
    AnotherGrassEater anotherGrassEater = new AnotherGrassEater("Another grass-eater", "Eats grass");
    cache.put("key101", anotherGrassEater);
    // Executing second query
    found = cacheQuery.execute().list();
    assertEquals(numberOfEntries, found.size());
    assertEquals(1, mBeanServer.invoke(name, "getNumberOfIndexedEntities", new Object[] { AnotherGrassEater.class.getName() }, new String[] { String.class.getName() }));
    Set<String> classNames = (Set<String>) mBeanServer.getAttribute(name, "IndexedClassNames");
    assertEquals(2, classNames.size());
    assertTrue("The set should contain the Person class name.", classNames.contains(Person.class.getName()));
    assertTrue("The set should contain the AnotherGrassEater class name.", classNames.contains(AnotherGrassEater.class.getName()));
    assertEquals(2, CompletionStages.join(searchStatistics.getIndexStatistics().computeIndexInfos()).size());
    // check the statistics and see they have reasonable values
    assertTrue("The query execution total time should be > 0.", (Long) mBeanServer.getAttribute(name, "SearchQueryTotalTime") > 0);
    assertEquals(2L, mBeanServer.getAttribute(name, "SearchQueryExecutionCount"));
    assertEquals(q, mBeanServer.getAttribute(name, "SearchQueryExecutionMaxTimeQueryString"));
    assertTrue((Long) mBeanServer.getAttribute(name, "SearchQueryExecutionMaxTime") > 0);
    assertTrue((Long) mBeanServer.getAttribute(name, "SearchQueryExecutionAvgTime") > 0);
    mBeanServer.invoke(name, "clear", new Object[0], new String[0]);
    // after "clear" everything must be reset
    assertEquals(0L, mBeanServer.getAttribute(name, "SearchQueryExecutionCount"));
    assertEquals("", mBeanServer.getAttribute(name, "SearchQueryExecutionMaxTimeQueryString"));
    assertEquals(0L, mBeanServer.getAttribute(name, "SearchQueryExecutionMaxTime"));
    assertEquals(0L, mBeanServer.getAttribute(name, "SearchQueryExecutionAvgTime"));
    assertEquals(0L, mBeanServer.getAttribute(name, "ObjectsLoadedCount"));
    assertEquals(0L, mBeanServer.getAttribute(name, "ObjectLoadingTotalTime"));
    assertEquals(0L, mBeanServer.getAttribute(name, "ObjectLoadingExecutionMaxTime"));
    assertEquals(0L, mBeanServer.getAttribute(name, "ObjectLoadingExecutionAvgTime"));
}
Also used : QueryFactory(org.infinispan.query.dsl.QueryFactory) SearchStatistics(org.infinispan.query.core.stats.SearchStatistics) Set(java.util.Set) ObjectName(javax.management.ObjectName) AnotherGrassEater(org.infinispan.query.test.AnotherGrassEater) Person(org.infinispan.query.test.Person) MBeanServer(javax.management.MBeanServer)

Example 3 with AnotherGrassEater

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

the class NonLocalIndexingTest method testQueryAfterAddingNewNode.

public void testQueryAfterAddingNewNode() throws Exception {
    store("Astronaut", new Person("Astronaut", "is asking his timezone", 32), cache(0));
    assertFind("timezone", 1);
    assertFind("asking", 1);
    assertFind("cat", 0);
    store("Webdeveloper", new Person("Webdeveloper", "is confused by the timezone concept", 32), cache(1));
    assertFind("cat", 0);
    assertFind("timezone", 2);
    // We're using the name as a key so this is an update in practice of the Astronaut record:
    store("Astronaut", new Person("Astronaut", "thinks about his cat", 32), cache(1));
    assertFind("cat", 1);
    assertFind("timezone", 1);
    store("Astronaut", new AnotherGrassEater("Astronaut", "is having a hard time to find grass"), cache(1));
    // replacing same key with a new type:
    assertFind("cat", 0);
    assertFind("grass", 0);
}
Also used : AnotherGrassEater(org.infinispan.query.test.AnotherGrassEater) Person(org.infinispan.query.test.Person)

Aggregations

AnotherGrassEater (org.infinispan.query.test.AnotherGrassEater)3 Person (org.infinispan.query.test.Person)3 Set (java.util.Set)1 MBeanServer (javax.management.MBeanServer)1 ObjectName (javax.management.ObjectName)1 SearchStatistics (org.infinispan.query.core.stats.SearchStatistics)1 QueryFactory (org.infinispan.query.dsl.QueryFactory)1