Search in sources :

Example 11 with DiskStoreFactory

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

the class DiskRegionDUnitTest method testValues.

/**
   * Tests iterating over all of the values when some have been overflowed.
   */
@Test
public void testValues() throws Exception {
    final String name = this.getUniqueName();
    AttributesFactory factory = new AttributesFactory();
    factory.setScope(Scope.LOCAL);
    factory.setEvictionAttributes(EvictionAttributes.createLRUEntryAttributes(100, EvictionAction.OVERFLOW_TO_DISK));
    File d = new File("DiskRegions" + OSProcess.getId());
    d.mkdirs();
    DiskStoreFactory dsf = getCache().createDiskStoreFactory();
    dsf.setDiskDirs(new File[] { d });
    DiskStore ds = dsf.create(name);
    factory.setDiskStoreName(ds.getName());
    Region region = createRegion(name, factory.create());
    // DiskRegion dr = ((LocalRegion) region).getDiskRegion();
    // DiskRegionStats diskStats = dr.getStats();
    LRUStatistics lruStats = getLRUStats(region);
    // Put in larger stuff until we start evicting
    int total;
    for (total = 0; lruStats.getEvictions() <= 0; total++) {
        int[] array = new int[250];
        array[0] = total;
        region.put(new Integer(total), array);
    }
    BitSet bits = new BitSet();
    Collection values = region.values();
    assertEquals(total, values.size());
    for (Iterator iter = values.iterator(); iter.hasNext(); ) {
        Object value = iter.next();
        assertNotNull(value);
        int[] array = (int[]) value;
        int i = array[0];
        assertFalse("Bit " + i + " is already set", bits.get(i));
        bits.set(i);
    }
}
Also used : BitSet(java.util.BitSet) DiskStoreFactory(org.apache.geode.cache.DiskStoreFactory) DiskStore(org.apache.geode.cache.DiskStore) AttributesFactory(org.apache.geode.cache.AttributesFactory) LRUStatistics(org.apache.geode.internal.cache.lru.LRUStatistics) Iterator(java.util.Iterator) DiskRegion(org.apache.geode.internal.cache.DiskRegion) LocalRegion(org.apache.geode.internal.cache.LocalRegion) Region(org.apache.geode.cache.Region) Collection(java.util.Collection) File(java.io.File) Test(org.junit.Test) DistributedTest(org.apache.geode.test.junit.categories.DistributedTest)

Example 12 with DiskStoreFactory

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

the class DiskRegionDUnitTest method testRegionEntryValues.

// testSwitchOut is no longer valid
// the test was not written correctly to recover
// and if it was it would now fail with a split brain
// testSwitchIn is no longer valid
// we no longer switchIn files if GII aborts.
/**
   * Tests getting the {@linkplain org.apache.geode.cache.Region.Entry#getValue values} of region
   * entries that have been overflowed.
   */
@Test
public void testRegionEntryValues() throws Exception {
    final String name = this.getUniqueName();
    AttributesFactory factory = new AttributesFactory();
    factory.setScope(Scope.LOCAL);
    factory.setEvictionAttributes(EvictionAttributes.createLRUEntryAttributes(100, EvictionAction.OVERFLOW_TO_DISK));
    File d = new File("DiskRegions" + OSProcess.getId());
    d.mkdirs();
    DiskStoreFactory dsf = getCache().createDiskStoreFactory();
    dsf.setDiskDirs(new File[] { d });
    DiskStore ds = dsf.create(name);
    factory.setDiskStoreName(ds.getName());
    Region region = createRegion(name, factory.create());
    // DiskRegion dr = ((LocalRegion) region).getDiskRegion();
    // DiskRegionStats diskStats = dr.getStats();
    LRUStatistics lruStats = getLRUStats(region);
    // Put in larger stuff until we start evicting
    int total;
    for (total = 0; lruStats.getEvictions() <= 0; total++) {
        int[] array = new int[250];
        array[0] = total;
        region.put(new Integer(total), array);
    }
    // BitSet bits = new BitSet();
    Set values = region.entrySet(false);
    assertEquals(total, values.size());
    for (Iterator iter = values.iterator(); iter.hasNext(); ) {
        Region.Entry entry = (Region.Entry) iter.next();
        Integer key = (Integer) entry.getKey();
        int[] value = (int[]) entry.getValue();
        assertNotNull(value);
        assertEquals("Key/value" + key, key.intValue(), value[0]);
    }
}
Also used : Set(java.util.Set) BitSet(java.util.BitSet) DiskStoreFactory(org.apache.geode.cache.DiskStoreFactory) DiskStore(org.apache.geode.cache.DiskStore) AttributesFactory(org.apache.geode.cache.AttributesFactory) LRUStatistics(org.apache.geode.internal.cache.lru.LRUStatistics) Iterator(java.util.Iterator) DiskRegion(org.apache.geode.internal.cache.DiskRegion) LocalRegion(org.apache.geode.internal.cache.LocalRegion) Region(org.apache.geode.cache.Region) File(java.io.File) Test(org.junit.Test) DistributedTest(org.apache.geode.test.junit.categories.DistributedTest)

Example 13 with DiskStoreFactory

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

the class DiskRegionDUnitTest method testRegionEvictValue.

/**
   * Tests for region.evictValue().
   */
@Test
public void testRegionEvictValue() throws Exception {
    final String name = this.getUniqueName() + "testRegionEvictValue";
    File d = new File("DiskRegions" + OSProcess.getId());
    d.mkdirs();
    AttributesFactory factory = new AttributesFactory();
    factory.setScope(Scope.LOCAL);
    factory.setDataPolicy(DataPolicy.PERSISTENT_REPLICATE);
    // factory.setEvictionAttributes(EvictionAttributes.createLIFOEntryAttributes(capacity,
    // EvictionAction.OVERFLOW_TO_DISK));
    DiskStoreFactory dsf = getCache().createDiskStoreFactory();
    dsf.setDiskDirs(new File[] { d });
    DiskStore ds = dsf.create(name);
    factory.setDiskStoreName(ds.getName());
    Region region = createRegion(name, factory.create());
    int size = 200;
    for (int i = 0; i < size; i++) {
        region.put("Key-" + i, new Integer(i));
    }
    // Evict alternate values.
    for (int i = 0; i < size / 2; i++) {
        if (i % 2 == 0) {
            ((LocalRegion) region).evictValue("Key-" + i);
        }
    }
    // Check if its moved to disk.
    for (int i = 0; i < size / 2; i++) {
        if (i % 2 == 0) {
            try {
                Object value = ((LocalRegion) region).getValueInVM("Key-" + i);
                if (value != null) {
                    fail("The values should have been evicted to disk, for key: " + "Key-" + i);
                }
            } catch (EntryNotFoundException e) {
                fail("Entry not found not expected but occurred ");
            }
        }
    }
}
Also used : DiskStore(org.apache.geode.cache.DiskStore) AttributesFactory(org.apache.geode.cache.AttributesFactory) EntryNotFoundException(org.apache.geode.cache.EntryNotFoundException) DiskRegion(org.apache.geode.internal.cache.DiskRegion) LocalRegion(org.apache.geode.internal.cache.LocalRegion) Region(org.apache.geode.cache.Region) LocalRegion(org.apache.geode.internal.cache.LocalRegion) File(java.io.File) DiskStoreFactory(org.apache.geode.cache.DiskStoreFactory) Test(org.junit.Test) DistributedTest(org.apache.geode.test.junit.categories.DistributedTest)

Example 14 with DiskStoreFactory

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

the class DiskRegionDUnitTest method testLowLevelGetMethods.

/**
   * Tests the {@link LocalRegion#getValueInVM getValueInVM} and {@link LocalRegion#getValueOnDisk
   * getValueOnDisk} methods that were added for testing.
   */
@Test
public void testLowLevelGetMethods() throws Exception {
    final String name = this.getUniqueName();
    AttributesFactory factory = new AttributesFactory();
    factory.setScope(Scope.LOCAL);
    factory.setEvictionAttributes(EvictionAttributes.createLRUEntryAttributes(100, EvictionAction.OVERFLOW_TO_DISK));
    DiskStoreFactory dsf = getCache().createDiskStoreFactory();
    factory.setDiskSynchronous(true);
    File d = new File("DiskRegions" + OSProcess.getId());
    d.mkdirs();
    dsf.setDiskDirs(new File[] { d });
    DiskStore ds = dsf.create(name);
    factory.setDiskStoreName(ds.getName());
    LocalRegion region = (LocalRegion) createRegion(name, factory.create());
    // DiskRegion dr = region.getDiskRegion();
    // DiskRegionStats diskStats = dr.getStats();
    LRUStatistics lruStats = getLRUStats(region);
    // Put in larger stuff until we start evicting
    int total;
    for (total = 0; lruStats.getEvictions() <= 2; total++) {
        int[] array = new int[250];
        array[0] = total;
        Integer key = new Integer(total);
        region.put(key, array);
        array = (int[]) region.getValueInVM(key);
        assertNotNull(array);
        assertEquals(total, array[0]);
        assertNull(region.getValueOnDisk(key));
    }
    Integer key = new Integer(1);
    assertNull(region.getValueInVM(key));
    int[] array = (int[]) region.getValueOnDisk(key);
    assertNotNull(array);
    assertEquals(1, array[0]);
    region.get(key);
    CachedDeserializable cd = (CachedDeserializable) region.getValueInVM(key);
    array = (int[]) cd.getValue();
    assertNotNull(array);
    assertEquals(1, array[0]);
    array = (int[]) region.getValueOnDisk(key);
    assertNotNull(array);
    assertEquals(1, array[0]);
}
Also used : DiskStore(org.apache.geode.cache.DiskStore) AttributesFactory(org.apache.geode.cache.AttributesFactory) CachedDeserializable(org.apache.geode.internal.cache.CachedDeserializable) LRUStatistics(org.apache.geode.internal.cache.lru.LRUStatistics) LocalRegion(org.apache.geode.internal.cache.LocalRegion) File(java.io.File) DiskStoreFactory(org.apache.geode.cache.DiskStoreFactory) Test(org.junit.Test) DistributedTest(org.apache.geode.test.junit.categories.DistributedTest)

Example 15 with DiskStoreFactory

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

the class DiskRegionDUnitTest method testTestHookStatistics.

/**
   * Tests that the "test hook" {@link DiskRegionStats} work as advertised.
   */
@Test
public void testTestHookStatistics() throws Exception {
    final String name = this.getUniqueName();
    AttributesFactory factory = new AttributesFactory();
    factory.setScope(Scope.LOCAL);
    // factory.setConcurrencyChecksEnabled(false);
    factory.setEvictionAttributes(EvictionAttributes.createLRUEntryAttributes(100, EvictionAction.OVERFLOW_TO_DISK));
    DiskStoreFactory dsf = getCache().createDiskStoreFactory();
    factory.setDiskSynchronous(true);
    File d = new File("DiskRegions" + OSProcess.getId());
    d.mkdirs();
    dsf.setDiskDirs(new File[] { d });
    DiskStore ds = dsf.create(name);
    factory.setDiskStoreName(ds.getName());
    LocalRegion region = (LocalRegion) createRegion(name, factory.create());
    DiskRegion dr = region.getDiskRegion();
    DiskRegionStats diskStats = dr.getStats();
    LRUStatistics lruStats = getLRUStats(region);
    // Put in stuff until we start evicting
    int total;
    for (total = 0; lruStats.getEvictions() <= 0; total++) {
        int[] array = new int[1];
        array[0] = total;
        region.put(new Integer(total), array);
        if (lruStats.getEvictions() <= 0) {
            assertEquals(total + 1, diskStats.getNumEntriesInVM());
        }
    }
    assertEquals(1, diskStats.getNumOverflowOnDisk());
    // Net change of zero
    region.get(new Integer(0));
    assertEquals(region.entryCount(), diskStats.getNumEntriesInVM() + diskStats.getNumOverflowOnDisk());
    assertEquals(total - 1, diskStats.getNumEntriesInVM());
    assertEquals(1, diskStats.getNumOverflowOnDisk());
    // Kick out 4 entries
    region.put(new Integer(total + 10), new int[1]);
    region.put(new Integer(total + 11), new int[1]);
    region.put(new Integer(total + 12), new int[1]);
    region.put(new Integer(total + 13), new int[1]);
    assertEquals(region.entryCount(), diskStats.getNumEntriesInVM() + diskStats.getNumOverflowOnDisk());
    assertEquals(total - 1, diskStats.getNumEntriesInVM());
    assertEquals(5, diskStats.getNumOverflowOnDisk());
    // Make sure invalidate of inVM entry changes inVM count but not disk
    region.invalidate(new Integer(total + 10));
    assertEquals(region.entryCount() - 1, diskStats.getNumEntriesInVM() + diskStats.getNumOverflowOnDisk());
    assertEquals(total - 2, diskStats.getNumEntriesInVM());
    assertEquals(5, diskStats.getNumOverflowOnDisk());
    // Make sure local-invalidate of inVM entry changes inVM count but not disk
    region.localInvalidate(new Integer(total + 11));
    assertEquals(region.entryCount() - 2, diskStats.getNumEntriesInVM() + diskStats.getNumOverflowOnDisk());
    assertEquals(total - 3, diskStats.getNumEntriesInVM());
    assertEquals(5, diskStats.getNumOverflowOnDisk());
    // Make sure destroy of invalid entry does not change inVM or onDisk but changes entry count
    region.destroy(new Integer(total + 10));
    // ((LocalRegion)region).dumpBackingMap();
    assertEquals(region.entryCount() - 1, diskStats.getNumEntriesInVM() + diskStats.getNumOverflowOnDisk());
    assertEquals(total - 3, diskStats.getNumEntriesInVM());
    assertEquals(5, diskStats.getNumOverflowOnDisk());
    // Make sure destroy of inVM entry does change inVM but not onDisk
    region.destroy(new Integer(total + 12));
    assertEquals(region.entryCount() - 1, diskStats.getNumEntriesInVM() + diskStats.getNumOverflowOnDisk());
    assertEquals(total - 4, diskStats.getNumEntriesInVM());
    assertEquals(5, diskStats.getNumOverflowOnDisk());
    // Destroy an entry that has been overflowed
    region.destroy(new Integer(3));
    assertEquals(region.entryCount() - 1, diskStats.getNumEntriesInVM() + diskStats.getNumOverflowOnDisk());
    assertEquals(total - 4, diskStats.getNumEntriesInVM());
    assertEquals(4, diskStats.getNumOverflowOnDisk());
}
Also used : DiskStore(org.apache.geode.cache.DiskStore) AttributesFactory(org.apache.geode.cache.AttributesFactory) DiskRegion(org.apache.geode.internal.cache.DiskRegion) DiskRegionStats(org.apache.geode.internal.cache.DiskRegionStats) LRUStatistics(org.apache.geode.internal.cache.lru.LRUStatistics) LocalRegion(org.apache.geode.internal.cache.LocalRegion) File(java.io.File) DiskStoreFactory(org.apache.geode.cache.DiskStoreFactory) Test(org.junit.Test) DistributedTest(org.apache.geode.test.junit.categories.DistributedTest)

Aggregations

DiskStoreFactory (org.apache.geode.cache.DiskStoreFactory)132 File (java.io.File)95 DiskStore (org.apache.geode.cache.DiskStore)91 Test (org.junit.Test)86 AttributesFactory (org.apache.geode.cache.AttributesFactory)56 Region (org.apache.geode.cache.Region)46 IntegrationTest (org.apache.geode.test.junit.categories.IntegrationTest)46 DistributedTest (org.apache.geode.test.junit.categories.DistributedTest)35 Cache (org.apache.geode.cache.Cache)32 LocalRegion (org.apache.geode.internal.cache.LocalRegion)24 RegionFactory (org.apache.geode.cache.RegionFactory)22 SerializableRunnable (org.apache.geode.test.dunit.SerializableRunnable)21 DiskRegion (org.apache.geode.internal.cache.DiskRegion)19 Properties (java.util.Properties)18 VM (org.apache.geode.test.dunit.VM)18 LRUStatistics (org.apache.geode.internal.cache.lru.LRUStatistics)16 GatewaySenderFactory (org.apache.geode.cache.wan.GatewaySenderFactory)12 FlakyTest (org.apache.geode.test.junit.categories.FlakyTest)11 IOException (java.io.IOException)10 PartitionAttributesFactory (org.apache.geode.cache.PartitionAttributesFactory)10