Search in sources :

Example 11 with RegionEntry

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

the class MemoryIndexStoreJUnitTest method testClear.

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

Example 12 with RegionEntry

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

the class MemoryIndexStoreJUnitTest method testDescendingIteratorReturnsExpectedOrderOfEntries.

@Test
public void testDescendingIteratorReturnsExpectedOrderOfEntries() throws Exception {
    RegionEntry mockEntry1 = mockEntries[0];
    RegionEntry mockEntry2 = mockEntries[1];
    store.addMapping("1", mockEntry1);
    store.addMapping("2", mockEntry2);
    Iterator iteratorFirst = store.descendingIterator(null);
    assertEquals(2, numObjectsIterated(iteratorFirst));
    Iterator iterator = store.descendingIterator(null);
    iterator.hasNext();
    assertEquals(mockEntry2, ((MemoryIndexStore.MemoryIndexStoreEntry) iterator.next()).getRegionEntry());
    iterator.hasNext();
    assertEquals(mockEntry1, ((MemoryIndexStore.MemoryIndexStoreEntry) iterator.next()).getRegionEntry());
}
Also used : Iterator(java.util.Iterator) RegionEntry(org.apache.geode.internal.cache.RegionEntry) Test(org.junit.Test) UnitTest(org.apache.geode.test.junit.categories.UnitTest)

Example 13 with RegionEntry

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

the class MemoryIndexStoreJUnitTest method testGetReturnsExpectedIteratorValue.

@Test
public void testGetReturnsExpectedIteratorValue() throws Exception {
    RegionEntry mockEntry1 = mockEntries[0];
    RegionEntry mockEntry2 = mockEntries[1];
    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 14 with RegionEntry

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

the class MemoryIndexStoreJUnitTest method testGetReturnsExpectedIteratorWithMultipleValues.

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

Example 15 with RegionEntry

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

the class MultiVMRegionTestCase method versionTestGIISendsTombstones.

/*
   * This test creates a server cache in vm0 and a peer cache in vm1. It then tests to see if GII
   * transferred tombstones to vm1 like it's supposed to. A client cache is created in vm2 and the
   * same sort of check is performed for register-interest.
   */
public void versionTestGIISendsTombstones() throws Exception {
    Host host = Host.getHost(0);
    VM vm0 = host.getVM(0);
    VM vm1 = host.getVM(1);
    VM vm2 = host.getVM(2);
    final int serverPort = AvailablePortHelper.getRandomAvailableTCPPort();
    // create replicated regions in VM 0 and 1, then perform concurrent ops
    // on the same key while creating the region in VM2. Afterward make
    // sure that all three regions are consistent
    final String name = this.getUniqueName() + "-CC";
    SerializableRunnable createRegion = new SerializableRunnable("Create Region") {

        @Override
        public void run() {
            try {
                RegionFactory f = getCache().createRegionFactory(getRegionAttributes());
                CCRegion = (LocalRegion) f.create(name);
                if (VM.getCurrentVMNum() == 0) {
                    CacheServer bridge = CCRegion.getCache().addCacheServer();
                    bridge.setPort(serverPort);
                    try {
                        bridge.start();
                    } catch (IOException ex) {
                        fail("While creating bridge", ex);
                    }
                }
            } catch (CacheException ex) {
                fail("While creating region", ex);
            }
        }
    };
    SerializableRunnable asserter = new SerializableRunnable("ensure tombstone has been received") {

        @Override
        public void run() {
            RegionEntry entry = CCRegion.getRegionEntry("object2");
            assertTrue(entry != null);
            assertTrue(entry.isTombstone());
        }
    };
    vm0.invoke(createRegion);
    vm0.invoke(new SerializableRunnable("create some tombstones") {

        @Override
        public void run() {
            CCRegion.put("object1", "value1");
            CCRegion.put("object2", "value2");
            CCRegion.put("object3", "value3");
            CCRegion.destroy("object2");
        }
    });
    try {
        vm0.invoke(asserter);
        vm1.invoke(createRegion);
        vm1.invoke(asserter);
    // vm2.invoke(createClientCache);
    // vm2.invoke(asserter);
    } finally {
        disconnectAllFromDS();
    }
}
Also used : RegionFactory(org.apache.geode.cache.RegionFactory) CacheException(org.apache.geode.cache.CacheException) VM(org.apache.geode.test.dunit.VM) SerializableRunnable(org.apache.geode.test.dunit.SerializableRunnable) CacheServer(org.apache.geode.cache.server.CacheServer) RegionEntry(org.apache.geode.internal.cache.RegionEntry) Host(org.apache.geode.test.dunit.Host) IOException(java.io.IOException)

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