Search in sources :

Example 41 with RegionEntry

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

the class MemoryIndexStoreJUnitTest method testDescendingIteratorWithRemovedKeysReturnsExpectedOrderOfEntries.

@Test
public void testDescendingIteratorWithRemovedKeysReturnsExpectedOrderOfEntries() throws Exception {
    RegionEntry mockEntry1 = mockEntries[0];
    RegionEntry mockEntry2 = mockEntries[1];
    RegionEntry mockEntry3 = mockEntries[2];
    store.addMapping("1", mockEntry1);
    store.addMapping("2", mockEntry2);
    store.addMapping("3", mockEntry3);
    Set keysToRemove = new HashSet();
    keysToRemove.add("2");
    Iterator iteratorFirst = store.descendingIterator(keysToRemove);
    assertEquals(2, numObjectsIterated(iteratorFirst));
    // keysToRemove has been modified by the store, we need to readd the key to remove
    keysToRemove.add("2");
    Iterator iterator = store.descendingIterator(keysToRemove);
    iterator.hasNext();
    assertEquals(mockEntry3, ((MemoryIndexStore.MemoryIndexStoreEntry) iterator.next()).getRegionEntry());
    iterator.hasNext();
    assertEquals(mockEntry1, ((MemoryIndexStore.MemoryIndexStoreEntry) iterator.next()).getRegionEntry());
    assertFalse(iterator.hasNext());
}
Also used : Set(java.util.Set) HashSet(java.util.HashSet) Iterator(java.util.Iterator) RegionEntry(org.apache.geode.internal.cache.RegionEntry) HashSet(java.util.HashSet) Test(org.junit.Test) UnitTest(org.apache.geode.test.junit.categories.UnitTest)

Example 42 with RegionEntry

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

the class MemoryIndexStoreJUnitTest method testRemoveMappingRemovesFromBackingMap.

@Test
public void testRemoveMappingRemovesFromBackingMap() throws Exception {
    RegionEntry mockEntry1 = mockEntries[0];
    RegionEntry mockEntry2 = mockEntries[1];
    store.addMapping("1", mockEntry1);
    store.addMapping("2", mockEntry2);
    store.removeMapping("1", mockEntry1);
    assertEquals(1, numObjectsInStore(store));
    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)

Example 43 with RegionEntry

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

the class MemoryIndexStoreJUnitTest method testGetWithIndexOnKeysReturnsExpectedIteratorValues.

@Test
public void testGetWithIndexOnKeysReturnsExpectedIteratorValues() throws Exception {
    RegionEntry mockEntry1 = mockEntries[0];
    RegionEntry mockEntry2 = mockEntries[1];
    store.setIndexOnValues(false);
    store.setIndexOnRegionKeys(true);
    store.addMapping("1", mockEntry1);
    store.addMapping("2", mockEntry2);
    assertEquals(1, numObjectsIterated(store.get("1")));
}
Also used : RegionEntry(org.apache.geode.internal.cache.RegionEntry) Test(org.junit.Test) UnitTest(org.apache.geode.test.junit.categories.UnitTest)

Example 44 with RegionEntry

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

the class MemoryIndexStoreJUnitTest method testCorrectlyRemovesEntryProvidedTheWrongKey.

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

Example 45 with RegionEntry

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

the class MemoryIndexStoreJUnitTest method createRegionEntry.

private RegionEntry createRegionEntry(Object key, Object value) {
    RegionEntry mockEntry = mock(RegionEntry.class);
    when(mockEntry.getValue(any())).thenReturn(value);
    when(mockEntry.getKey()).thenReturn(key);
    return mockEntry;
}
Also used : RegionEntry(org.apache.geode.internal.cache.RegionEntry)

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