@Test(
     dependsOnMethods =
         "simpleIndexTest") // depends as otherwise the Person index is not initialized yet
 public void testPropertiesWhereRead() {
   SearchFactoryIntegrator searchFactory = TestQueryHelperFactory.extractSearchFactory(cache);
   DirectoryProvider[] directoryProviders = searchFactory.getDirectoryProviders(Person.class);
   assertEquals(1, directoryProviders.length);
   assertNotNull(directoryProviders[0]);
   assertTrue(directoryProviders[0] instanceof RAMDirectoryProvider);
 }
 public void simpleIndexTest() throws ParseException {
   cache.put("1", new Person("A Person's Name", "A paragraph containing some text", 75));
   CacheQuery cq = TestQueryHelperFactory.createCacheQuery(cache, "name", "Person");
   assertEquals(1, cq.getResultSize());
   List<Object> l = cq.list();
   assertEquals(1, l.size());
   Person p = (Person) l.get(0);
   assertEquals("A Person's Name", p.getName());
   assertEquals("A paragraph containing some text", p.getBlurb());
   assertEquals(75, p.getAge());
 }
Пример #3
0
  @Override
  protected EmbeddedCacheManager createCacheManager() throws Exception {
    Configuration c = getDefaultClusteredConfig(LOCAL, true);
    c.setIndexingEnabled(true);
    c.setIndexLocalOnly(false);
    cacheManager = TestCacheManagerFactory.createCacheManager(c, true);
    cache = cacheManager.getCache();
    qh = TestQueryHelperFactory.createTestQueryHelperInstance(cache, Person.class);

    person1 = new Person();
    person1.setName("Navin");
    person1.setBlurb("Owns a macbook");
    person1.setAge(20);
    return cacheManager;
  }
/** @author Sanne Grinovero <*****@*****.**> (C) 2011 Red Hat Inc. */
@Test(groups = "functional", testName = "query.cacheloaders.EntryActivatingTest")
public class EntryActivatingTest extends AbstractInfinispanTest {

  Cache<String, Country> cache;
  CacheStore store;
  CacheContainer cm;
  SearchManager search;
  QueryParser queryParser = TestQueryHelperFactory.createQueryParser("countryName");

  @BeforeTest
  public void setUp() {
    recreateCacheManager();
  }

  @AfterTest
  public void tearDown() {
    TestingUtil.killCacheManagers(cm);
  }

  public void testPersistence() throws CacheLoaderException, ParseException {
    verifyFullTextHasMatches(0);

    Country italy = new Country();
    italy.countryName = "Italy";
    City rome = new City();
    rome.name = "Rome";
    italy.cities.add(rome);

    cache.put("IT", italy);
    assert !store.containsKey("IT");

    verifyFullTextHasMatches(1);

    cache.evict("IT");
    assert store.containsKey("IT");

    InternalCacheEntry internalCacheEntry = cache.getAdvancedCache().getDataContainer().get("IT");
    assert internalCacheEntry == null;

    verifyFullTextHasMatches(1);

    Country country = cache.get("IT");
    assert country != null;
    assert "Italy".equals(country.countryName);

    verifyFullTextHasMatches(1);

    cache.stop();
    assert ((SearchFactoryIntegrator) search.getSearchFactory()).isStopped();
    TestingUtil.killCacheManagers(cm);

    // Now let's check the entry is not re-indexed during data preloading:
    recreateCacheManager();

    // People should generally use a persistent index; we use RAMDirectory for
    // test cleanup, so for our configuration it needs now to contain zero
    // matches: on filesystem it would be exactly one as expected (two when ISPN-1179 was open)
    verifyFullTextHasMatches(0);
  }

  private void recreateCacheManager() {
    ConfigurationBuilder cfg = new ConfigurationBuilder();
    cfg.loaders()
        .preload(true)
        .passivation(true)
        .addStore()
        .cacheStore(new DummyInMemoryCacheStore())
        .purgeOnStartup(true)
        .indexing()
        .enable()
        .addProperty("default.directory_provider", "ram")
        .addProperty("lucene_version", "LUCENE_CURRENT");
    cm = TestCacheManagerFactory.createCacheManager(cfg);
    cache = cm.getCache();
    store = TestingUtil.extractComponent(cache, CacheLoaderManager.class).getCacheStore();
    search = Search.getSearchManager(cache);
  }

  private void verifyFullTextHasMatches(int i) throws ParseException {
    Query query = queryParser.parse("Italy");
    List<Object> list = search.getQuery(query, Country.class, City.class).list();
    Assert.assertEquals(i, list.size());
  }
}