Search in sources :

Example 51 with AttributesFactory

use of org.apache.geode.cache.AttributesFactory 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 52 with AttributesFactory

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

the class ClearMultiVmCallBkDUnitTest method createCache.

public static void createCache() {
    CacheListener aListener = new ListenerCallBk();
    ds = (new ClearMultiVmCallBkDUnitTest()).getSystem(props);
    cache = CacheFactory.create(ds);
    AttributesFactory factory = new AttributesFactory();
    factory.setScope(Scope.DISTRIBUTED_ACK);
    // Set Cachelisterner : aListener
    factory.setCacheListener(aListener);
    RegionAttributes attr = factory.create();
    region = cache.createRegion("map", attr);
}
Also used : AttributesFactory(org.apache.geode.cache.AttributesFactory) RegionAttributes(org.apache.geode.cache.RegionAttributes) CacheListener(org.apache.geode.cache.CacheListener)

Example 53 with AttributesFactory

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

the class ClearMultiVmDUnitTest method testClearSimpleScenarios.

// test methods
@Test
public void testClearSimpleScenarios() {
    Host host = Host.getHost(0);
    VM vm0 = host.getVM(0);
    VM vm1 = host.getVM(1);
    // verifying Single VM clear functionalities
    vm0.invoke(new CacheSerializableRunnable("temp1") {

        public void run2() throws CacheException {
            region.put(new Integer(1), new String("first"));
            region.put(new Integer(2), new String("second"));
            region.put(new Integer(3), new String("third"));
            region.clear();
            assertEquals(0, region.size());
        }
    });
    vm1.invoke(new CacheSerializableRunnable("temp1vm1") {

        public void run2() throws CacheException {
            assertEquals(0, region.size());
        }
    });
    // verifying Single VM and single transaction clear functionalities
    vm1.invoke(new CacheSerializableRunnable("temp2") {

        public void run2() throws CacheException {
            try {
                region.put(new Integer(1), new String("first"));
                region.put(new Integer(2), new String("second"));
                region.put(new Integer(3), new String("third"));
                cacheTxnMgr = cache.getCacheTransactionManager();
                cacheTxnMgr.begin();
                region.put(new Integer(4), new String("forth"));
                try {
                    region.clear();
                    fail("expected exception not thrown");
                } catch (UnsupportedOperationInTransactionException e) {
                // expected
                }
                region.put(new Integer(5), new String("fifth"));
                cacheTxnMgr.commit();
                assertEquals(5, region.size());
                assertEquals("fifth", region.get(new Integer(5)).toString());
            } catch (CacheException ce) {
                ce.printStackTrace();
            } finally {
                if (cacheTxnMgr.exists()) {
                    try {
                        cacheTxnMgr.commit();
                    } catch (Exception cce) {
                        cce.printStackTrace();
                    }
                }
            }
        }
    });
    // verifying that region.clear does not clear the entries from sub region
    vm0.invoke(new CacheSerializableRunnable("temp3") {

        public void run2() throws CacheException {
            region.put(new Integer(1), new String("first"));
            region.put(new Integer(2), new String("second"));
            AttributesFactory factory = new AttributesFactory();
            factory.setScope(Scope.DISTRIBUTED_ACK);
            RegionAttributes attr = factory.create();
            Region subRegion = region.createSubregion("subr", attr);
            subRegion.put(new Integer(3), new String("third"));
            subRegion.put(new Integer(4), new String("forth"));
            region.clear();
            assertEquals(0, region.size());
            assertEquals(2, subRegion.size());
        }
    });
}
Also used : AttributesFactory(org.apache.geode.cache.AttributesFactory) CacheException(org.apache.geode.cache.CacheException) RegionAttributes(org.apache.geode.cache.RegionAttributes) VM(org.apache.geode.test.dunit.VM) Region(org.apache.geode.cache.Region) Host(org.apache.geode.test.dunit.Host) UnsupportedOperationInTransactionException(org.apache.geode.cache.UnsupportedOperationInTransactionException) RegionDestroyedException(org.apache.geode.cache.RegionDestroyedException) UnsupportedOperationInTransactionException(org.apache.geode.cache.UnsupportedOperationInTransactionException) CacheException(org.apache.geode.cache.CacheException) Test(org.junit.Test) DistributedTest(org.apache.geode.test.junit.categories.DistributedTest)

Example 54 with AttributesFactory

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

the class ClearMultiVmDUnitTest method testGiiandClear.

// end of testClearExceptions
@Test
public void testGiiandClear() throws Throwable {
    if (false) {
        getSystem().getLogWriter().severe("testGiiandClear skipped because of bug 34963");
    } else {
        Host host = Host.getHost(0);
        VM vm0 = host.getVM(0);
        VM vm1 = host.getVM(1);
        SerializableRunnable create = new CacheSerializableRunnable("create mirrored region") {

            public void run2() throws CacheException {
                AttributesFactory factory1 = new AttributesFactory();
                factory1.setScope(Scope.DISTRIBUTED_ACK);
                factory1.setDataPolicy(DataPolicy.REPLICATE);
                RegionAttributes attr1 = factory1.create();
                mirroredRegion = cache.createRegion("mirrored", attr1);
                // reset slow
                org.apache.geode.internal.cache.InitialImageOperation.slowImageProcessing = 0;
            }
        };
        vm0.invoke(create);
        vm0.invoke(new CacheSerializableRunnable("put initial data") {

            public void run2() throws CacheException {
                for (int i = 0; i < 1000; i++) {
                    mirroredRegion.put(new Integer(i), (new Integer(i)).toString());
                }
            }
        });
        // slow down image processing to make it more likely to get async updates
        vm1.invoke(new SerializableRunnable("set slow image processing") {

            public void run() {
                // if this is a no_ack test, then we need to slow down more because of the
                // pauses in the nonblocking operations
                int pause = 50;
                org.apache.geode.internal.cache.InitialImageOperation.slowImageProcessing = pause;
            }
        });
        // now do the get initial image in vm1
        AsyncInvocation async1 = vm1.invokeAsync(create);
        // try to time a distributed clear to happen in the middle of gii
        vm0.invoke(new SerializableRunnable("call clear when gii") {

            public void run() {
                try {
                    Thread.sleep(3 * 1000);
                } catch (InterruptedException ex) {
                    fail("interrupted");
                }
                mirroredRegion.clear();
                assertEquals(0, mirroredRegion.size());
            }
        });
        ThreadUtils.join(async1, 30 * 1000);
        if (async1.exceptionOccurred()) {
            Assert.fail("async1 failed", async1.getException());
        }
        SerializableRunnable validate = new CacheSerializableRunnable("validate for region size") {

            public void run2() throws CacheException {
                assertEquals(0, mirroredRegion.size());
            }
        };
        vm0.invoke(validate);
        vm1.invoke(validate);
    }
}
Also used : AttributesFactory(org.apache.geode.cache.AttributesFactory) RegionAttributes(org.apache.geode.cache.RegionAttributes) CacheException(org.apache.geode.cache.CacheException) VM(org.apache.geode.test.dunit.VM) SerializableRunnable(org.apache.geode.test.dunit.SerializableRunnable) Host(org.apache.geode.test.dunit.Host) AsyncInvocation(org.apache.geode.test.dunit.AsyncInvocation) Test(org.junit.Test) DistributedTest(org.apache.geode.test.junit.categories.DistributedTest)

Example 55 with AttributesFactory

use of org.apache.geode.cache.AttributesFactory 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)

Aggregations

AttributesFactory (org.apache.geode.cache.AttributesFactory)1156 Region (org.apache.geode.cache.Region)565 Test (org.junit.Test)550 RegionAttributes (org.apache.geode.cache.RegionAttributes)471 PartitionAttributesFactory (org.apache.geode.cache.PartitionAttributesFactory)468 DistributedTest (org.apache.geode.test.junit.categories.DistributedTest)356 VM (org.apache.geode.test.dunit.VM)304 Host (org.apache.geode.test.dunit.Host)288 Properties (java.util.Properties)244 CacheException (org.apache.geode.cache.CacheException)243 Cache (org.apache.geode.cache.Cache)229 SerializableRunnable (org.apache.geode.test.dunit.SerializableRunnable)206 PartitionedRegion (org.apache.geode.internal.cache.PartitionedRegion)201 ConfigurationProperties (org.apache.geode.distributed.ConfigurationProperties)199 LocalRegion (org.apache.geode.internal.cache.LocalRegion)173 CacheSerializableRunnable (org.apache.geode.cache30.CacheSerializableRunnable)156 SerializableCallable (org.apache.geode.test.dunit.SerializableCallable)139 FlakyTest (org.apache.geode.test.junit.categories.FlakyTest)129 IntegrationTest (org.apache.geode.test.junit.categories.IntegrationTest)126 IgnoredException (org.apache.geode.test.dunit.IgnoredException)125