Search in sources :

Example 56 with LoaderHelper

use of org.apache.geode.cache.LoaderHelper in project geode by apache.

the class LuceneQueriesIntegrationTest method shouldReturnCorrectResultsOnDeletionAfterQueryExecutionWithLoader.

@Test
public void shouldReturnCorrectResultsOnDeletionAfterQueryExecutionWithLoader() throws Exception {
    final int pageSize = 2;
    final LuceneQuery<Object, Object> query = addValuesAndCreateQuery(pageSize);
    region.getAttributesMutator().setCacheLoader(new CacheLoader() {

        @Override
        public Object load(final LoaderHelper helper) throws CacheLoaderException {
            return new TestObject("should not", "load this");
        }

        @Override
        public void close() {
        }
    });
    final PageableLuceneQueryResults<Object, Object> pages = query.findPages();
    List<LuceneResultStruct<Object, Object>> allEntries = new ArrayList<>();
    assertTrue(pages.hasNext());
    assertEquals(7, pages.size());
    // Destroying an entry from the region after the query is executed.
    region.destroy("C");
    final List<LuceneResultStruct<Object, Object>> page1 = pages.next();
    assertEquals(pageSize, page1.size());
    final List<LuceneResultStruct<Object, Object>> page2 = pages.next();
    assertEquals(pageSize, page2.size());
    final List<LuceneResultStruct<Object, Object>> page3 = pages.next();
    assertEquals(pageSize, page3.size());
    assertFalse(pages.hasNext());
    allEntries.addAll(page1);
    allEntries.addAll(page2);
    allEntries.addAll(page3);
    assertEquals(region.keySet(), allEntries.stream().map(entry -> entry.getKey()).collect(Collectors.toSet()));
    assertEquals(region.values(), allEntries.stream().map(entry -> entry.getValue()).collect(Collectors.toSet()));
}
Also used : LoaderHelper(org.apache.geode.cache.LoaderHelper) CacheLoaderException(org.apache.geode.cache.CacheLoaderException) ArrayList(java.util.ArrayList) TestObject(org.apache.geode.cache.lucene.test.TestObject) TestObject(org.apache.geode.cache.lucene.test.TestObject) CacheLoader(org.apache.geode.cache.CacheLoader) Test(org.junit.Test) IntegrationTest(org.apache.geode.test.junit.categories.IntegrationTest)

Aggregations

LoaderHelper (org.apache.geode.cache.LoaderHelper)56 Test (org.junit.Test)47 Region (org.apache.geode.cache.Region)45 AttributesFactory (org.apache.geode.cache.AttributesFactory)33 CacheException (org.apache.geode.cache.CacheException)32 CacheLoader (org.apache.geode.cache.CacheLoader)32 CacheLoaderException (org.apache.geode.cache.CacheLoaderException)32 VM (org.apache.geode.test.dunit.VM)29 Host (org.apache.geode.test.dunit.Host)26 DistributedTest (org.apache.geode.test.junit.categories.DistributedTest)26 LocalRegion (org.apache.geode.internal.cache.LocalRegion)22 FlakyTest (org.apache.geode.test.junit.categories.FlakyTest)19 SerializableRunnable (org.apache.geode.test.dunit.SerializableRunnable)18 PartitionedRegion (org.apache.geode.internal.cache.PartitionedRegion)15 TimeoutException (org.apache.geode.cache.TimeoutException)13 StoredObject (org.apache.geode.internal.offheap.StoredObject)13 CacheWriterException (org.apache.geode.cache.CacheWriterException)11 EntryEvent (org.apache.geode.cache.EntryEvent)10 RegionAttributes (org.apache.geode.cache.RegionAttributes)9 AttributesMutator (org.apache.geode.cache.AttributesMutator)7