Search in sources :

Example 6 with RegionEntry

use of org.apache.geode.internal.cache.RegionEntry in project geode by apache.

the class HashIndex method addToResultsFromEntries.

/**
   * @param entriesIter is Iterable<RegionEntry>
   */
private void addToResultsFromEntries(Iterator entriesIter, Collection result, CompiledValue iterOps, RuntimeIterator runtimeItr, ExecutionContext context, List projAttrib, SelectResults intermediateResults, boolean isIntersection, int limit, Set keysToRemove, boolean applyOrderBy, boolean asc, long iteratorCreationTime) throws FunctionDomainException, TypeMismatchException, NameResolutionException, QueryInvocationTargetException {
    QueryObserver observer = QueryObserverHolder.getInstance();
    if (result == null || (limit != -1 && result != null && result.size() == limit)) {
        return;
    }
    List orderedKeys = null;
    List orderedResults = null;
    if (applyOrderBy) {
        orderedKeys = new ArrayList();
        orderedResults = new ArrayList();
    }
    int i = 0;
    while (entriesIter.hasNext()) {
        // Check if query execution on this thread is canceled.
        QueryMonitor.isQueryExecutionCanceled();
        if (IndexManager.testHook != null) {
            if (logger.isDebugEnabled()) {
                logger.debug("IndexManager TestHook is set in addToResultsFromEntries.");
            }
            IndexManager.testHook.hook(11);
        }
        Object obj = entriesIter.next();
        Object key = null;
        if (obj != null && obj != HashIndexSet.REMOVED) {
            RegionEntry re = (RegionEntry) obj;
            if (applyOrderBy) {
                key = ((HashIndex.IMQEvaluator) evaluator).evaluateKey(obj);
                orderedKeys.add(new Object[] { key, i++ });
                addValueToResultSet(re, orderedResults, iterOps, runtimeItr, context, projAttrib, intermediateResults, isIntersection, limit, observer, iteratorCreationTime);
            } else {
                addValueToResultSet(re, result, iterOps, runtimeItr, context, projAttrib, intermediateResults, isIntersection, limit, observer, iteratorCreationTime);
            }
        }
    }
    if (applyOrderBy) {
        /*
       * For orderby queries, 1. Store the keys in a list along with the order. 2. Store the results
       * in another temp list. 3. Sort the keys. The order will also get sorted. 4. Fetch the result
       * objects from the temp list according to the sorted orders from the sorted list and add to
       * the result collection.
       */
        Collections.sort(orderedKeys, comparator);
        if (!asc) {
            Collections.reverse(orderedKeys);
        }
        Object[] temp = orderedResults.toArray();
        List tempResults = new ArrayList(temp.length);
        for (Object o : orderedKeys) {
            int index = (Integer) ((Object[]) o)[1];
            tempResults.add(temp[index]);
        }
        result.addAll(tempResults);
    }
}
Also used : QueryObserver(org.apache.geode.cache.query.internal.QueryObserver) ArrayList(java.util.ArrayList) RegionEntry(org.apache.geode.internal.cache.RegionEntry) List(java.util.List) ArrayList(java.util.ArrayList) StoredObject(org.apache.geode.internal.offheap.StoredObject)

Example 7 with RegionEntry

use of org.apache.geode.internal.cache.RegionEntry in project geode by apache.

the class QueryREUpdateInProgressJUnitTest method putREWithUpdateInProgressTrue.

private void putREWithUpdateInProgressTrue(String region) {
    Region reg = CacheUtils.getRegion(region);
    Portfolio[] values = createPortfoliosAndPositions(numOfEntries);
    int i = 0;
    for (Object val : values) {
        reg.put(i, val);
        i++;
    }
    // Set all RegionEntries to be updateInProgress.
    Iterator entryItr = reg.entrySet().iterator();
    while (entryItr.hasNext()) {
        Region.Entry nonTxEntry = (Region.Entry) entryItr.next();
        RegionEntry entry = ((NonTXEntry) nonTxEntry).getRegionEntry();
        entry.setUpdateInProgress(true);
        assertTrue(entry.isUpdateInProgress());
    }
}
Also used : RegionEntry(org.apache.geode.internal.cache.RegionEntry) NonTXEntry(org.apache.geode.internal.cache.LocalRegion.NonTXEntry) NonTXEntry(org.apache.geode.internal.cache.LocalRegion.NonTXEntry) Portfolio(org.apache.geode.cache.query.data.Portfolio) Iterator(java.util.Iterator) Region(org.apache.geode.cache.Region) RegionEntry(org.apache.geode.internal.cache.RegionEntry)

Example 8 with RegionEntry

use of org.apache.geode.internal.cache.RegionEntry in project geode by apache.

the class RegionJUnitTest method testRegionEntryAccess.

@Test
public void testRegionEntryAccess() throws Exception {
    Iterator entriesIter = region.entrySet(false).iterator();
    while (entriesIter.hasNext()) {
        Region.Entry entry = (Region.Entry) entriesIter.next();
        RegionEntry regionEntry = null;
        if (entry instanceof LocalRegion.NonTXEntry) {
            regionEntry = ((LocalRegion.NonTXEntry) entry).getRegionEntry();
        } else {
            regionEntry = ((EntrySnapshot) entry).getRegionEntry();
        }
        assertNotNull(regionEntry);
    }
    LocalRegion lRegion = (LocalRegion) region;
    Iterator keysIterator = lRegion.keys().iterator();
    while (keysIterator.hasNext()) {
        Object key = keysIterator.next();
        Region.Entry rEntry = lRegion.getEntry(key);
        RegionEntry regionEntry = null;
        if (rEntry instanceof LocalRegion.NonTXEntry) {
            regionEntry = ((LocalRegion.NonTXEntry) rEntry).getRegionEntry();
        } else {
            regionEntry = ((EntrySnapshot) rEntry).getRegionEntry();
        }
        assertNotNull(regionEntry);
    }
}
Also used : RegionEntry(org.apache.geode.internal.cache.RegionEntry) Iterator(java.util.Iterator) LocalRegion(org.apache.geode.internal.cache.LocalRegion) Region(org.apache.geode.cache.Region) RegionEntry(org.apache.geode.internal.cache.RegionEntry) LocalRegion(org.apache.geode.internal.cache.LocalRegion) Test(org.junit.Test) IntegrationTest(org.apache.geode.test.junit.categories.IntegrationTest)

Example 9 with RegionEntry

use of org.apache.geode.internal.cache.RegionEntry in project geode by apache.

the class PdxStringQueryJUnitTest method makeREUpdateInProgress.

public void makeREUpdateInProgress() {
    Iterator entryItr = r.entrySet().iterator();
    while (entryItr.hasNext()) {
        Region.Entry nonTxEntry = (Region.Entry) entryItr.next();
        RegionEntry entry = ((NonTXEntry) nonTxEntry).getRegionEntry();
        entry.setUpdateInProgress(true);
        assertTrue(entry.isUpdateInProgress());
    }
}
Also used : RegionEntry(org.apache.geode.internal.cache.RegionEntry) NonTXEntry(org.apache.geode.internal.cache.LocalRegion.NonTXEntry) IndexStoreEntry(org.apache.geode.cache.query.internal.index.IndexStore.IndexStoreEntry) NonTXEntry(org.apache.geode.internal.cache.LocalRegion.NonTXEntry) CloseableIterator(org.apache.geode.internal.cache.persistence.query.CloseableIterator) Region(org.apache.geode.cache.Region) RegionEntry(org.apache.geode.internal.cache.RegionEntry)

Example 10 with RegionEntry

use of org.apache.geode.internal.cache.RegionEntry in project geode by apache.

the class MemoryIndexStoreJUnitTest method testAddMappingAddsToBackingMap.

@Test
public void testAddMappingAddsToBackingMap() throws Exception {
    RegionEntry mockEntry1 = mockEntries[0];
    RegionEntry mockEntry2 = mockEntries[1];
    store.addMapping("1", mockEntry1);
    store.addMapping("2", mockEntry2);
    assertEquals(2, numObjectsInStore(store));
    assertTrue(objectContainedIn(store, mockEntry1));
    assertTrue(objectContainedIn(store, mockEntry2));
}
Also used : RegionEntry(org.apache.geode.internal.cache.RegionEntry) Test(org.junit.Test) UnitTest(org.apache.geode.test.junit.categories.UnitTest)

Aggregations

RegionEntry (org.apache.geode.internal.cache.RegionEntry)56 Test (org.junit.Test)32 LocalRegion (org.apache.geode.internal.cache.LocalRegion)20 UnitTest (org.apache.geode.test.junit.categories.UnitTest)15 Iterator (java.util.Iterator)13 Region (org.apache.geode.cache.Region)13 VM (org.apache.geode.test.dunit.VM)13 DistributedTest (org.apache.geode.test.junit.categories.DistributedTest)11 VersionTag (org.apache.geode.internal.cache.versions.VersionTag)10 Host (org.apache.geode.test.dunit.Host)9 SerializableRunnable (org.apache.geode.test.dunit.SerializableRunnable)9 Map (java.util.Map)8 PartitionedRegion (org.apache.geode.internal.cache.PartitionedRegion)8 CacheException (org.apache.geode.cache.CacheException)7 EntrySnapshot (org.apache.geode.internal.cache.EntrySnapshot)7 CloseableIterator (org.apache.geode.internal.cache.persistence.query.CloseableIterator)7 HashMap (java.util.HashMap)6 HashSet (java.util.HashSet)5 Entry (java.util.Map.Entry)5 Cache (org.apache.geode.cache.Cache)5