Search in sources :

Example 66 with SerializableRunnable

use of org.apache.geode.test.dunit.SerializableRunnable in project geode by apache.

the class DeltaFaultInDUnitTest method test.

@Test
public void test() throws Exception {
    final Host host = Host.getHost(0);
    VM vm0 = host.getVM(0);
    VM vm1 = host.getVM(1);
    VM vm2 = host.getVM(2);
    final boolean copyOnRead = false;
    final boolean clone = true;
    SerializableCallable createDataRegion = new SerializableCallable("createDataRegion") {

        public Object call() throws Exception {
            Cache cache = getCache();
            cache.setCopyOnRead(copyOnRead);
            cache.createDiskStoreFactory().create("DeltaFaultInDUnitTestData");
            AttributesFactory attr = new AttributesFactory();
            attr.setDiskStoreName("DeltaFaultInDUnitTestData");
            PartitionAttributesFactory paf = new PartitionAttributesFactory();
            paf.setRedundantCopies(1);
            PartitionAttributes prAttr = paf.create();
            attr.setPartitionAttributes(prAttr);
            attr.setCloningEnabled(clone);
            attr.setEvictionAttributes(EvictionAttributes.createLRUEntryAttributes(1, EvictionAction.OVERFLOW_TO_DISK));
            Region region = cache.createRegion("region1", attr.create());
            return null;
        }
    };
    vm0.invoke(createDataRegion);
    SerializableRunnable createEmptyRegion = new SerializableRunnable("createEmptyRegion") {

        public void run() {
            Cache cache = getCache();
            cache.setCopyOnRead(copyOnRead);
            AttributesFactory<Integer, TestDelta> attr = new AttributesFactory<Integer, TestDelta>();
            attr.setCloningEnabled(clone);
            PartitionAttributesFactory<Integer, TestDelta> paf = new PartitionAttributesFactory<Integer, TestDelta>();
            paf.setRedundantCopies(1);
            paf.setLocalMaxMemory(0);
            PartitionAttributes<Integer, TestDelta> prAttr = paf.create();
            attr.setPartitionAttributes(prAttr);
            attr.setDataPolicy(DataPolicy.PARTITION);
            attr.setEvictionAttributes(EvictionAttributes.createLRUEntryAttributes(1, EvictionAction.OVERFLOW_TO_DISK));
            Region<Integer, TestDelta> region = cache.createRegion("region1", attr.create());
            // Put an entry
            region.put(new Integer(0), new TestDelta(false, "initial"));
            // Put a delta object that is larger
            region.put(new Integer(0), new TestDelta(true, "initial_plus_some_more_data"));
        }
    };
    vm1.invoke(createEmptyRegion);
    vm0.invoke(new SerializableRunnable("doPut") {

        public void run() {
            Cache cache = getCache();
            Region<Integer, TestDelta> region = cache.getRegion("region1");
            // Evict the other object
            region.put(new Integer(113), new TestDelta(false, "bogus"));
            // Something was going weird with the LRU list. It was evicting this object.
            // I want to make sure the other object is the one evicted.
            region.get(new Integer(113));
            long entriesEvicted = ((AbstractLRURegionMap) ((PartitionedRegion) region).entries)._getLruList().stats().getEvictions();
            // assertIndexDetailsEquals(1, entriesEvicted);
            TestDelta result = region.get(new Integer(0));
            assertEquals("initial_plus_some_more_data", result.info);
        }
    });
}
Also used : PartitionAttributes(org.apache.geode.cache.PartitionAttributes) SerializableRunnable(org.apache.geode.test.dunit.SerializableRunnable) Host(org.apache.geode.test.dunit.Host) PartitionAttributesFactory(org.apache.geode.cache.PartitionAttributesFactory) AttributesFactory(org.apache.geode.cache.AttributesFactory) PartitionAttributesFactory(org.apache.geode.cache.PartitionAttributesFactory) VM(org.apache.geode.test.dunit.VM) SerializableCallable(org.apache.geode.test.dunit.SerializableCallable) Region(org.apache.geode.cache.Region) Cache(org.apache.geode.cache.Cache) Test(org.junit.Test) DistributedTest(org.apache.geode.test.junit.categories.DistributedTest)

Example 67 with SerializableRunnable

use of org.apache.geode.test.dunit.SerializableRunnable in project geode by apache.

the class EvictionTestBase method createPartitionedRegionInAllVMS.

protected void createPartitionedRegionInAllVMS(final boolean setEvictionOn, final EvictionAlgorithm evictionAlgorithm, final String regionName, final int totalNoOfBuckets, final int evictionAction, final int evictorInterval, final int maxEntries) {
    dataStore1.invoke(new SerializableRunnable() {

        @Override
        public void run() {
            createPartitionedRegion(setEvictionOn, evictionAlgorithm, regionName, totalNoOfBuckets, evictionAction, evictorInterval, maxEntries);
        }
    });
    dataStore2.invoke(new SerializableRunnable() {

        @Override
        public void run() {
            createPartitionedRegion(setEvictionOn, evictionAlgorithm, regionName, totalNoOfBuckets, evictionAction, evictorInterval, maxEntries);
        }
    });
}
Also used : SerializableRunnable(org.apache.geode.test.dunit.SerializableRunnable) CacheSerializableRunnable(org.apache.geode.cache30.CacheSerializableRunnable)

Example 68 with SerializableRunnable

use of org.apache.geode.test.dunit.SerializableRunnable in project geode by apache.

the class EvictionTestBase method prepareScenario2.

public void prepareScenario2(final EvictionAlgorithm evictionAlgorithm, final String partitionRegion1, final String partitionRegion2) {
    dataStore3.invoke(new SerializableRunnable() {

        @Override
        public void run() {
            createCache();
        }
    });
    dataStore4.invoke(new SerializableRunnable() {

        @Override
        public void run() {
            createCache();
        }
    });
    dataStore3.invoke(() -> EvictionTestBase.setTolerance());
    dataStore4.invoke(() -> EvictionTestBase.setTolerance());
    dataStore3.invoke(new SerializableRunnable() {

        @Override
        public void run() {
            createPartitionedRegion(true, evictionAlgorithm, partitionRegion1, 2, 2, 10000, 0);
        }
    });
    dataStore4.invoke(new SerializableRunnable() {

        @Override
        public void run() {
            createPartitionedRegion(true, evictionAlgorithm, partitionRegion1, 2, 2, 10000, 0);
        }
    });
    dataStore3.invoke(new SerializableRunnable() {

        @Override
        public void run() {
            createPartitionedRegion(true, evictionAlgorithm, partitionRegion2, 2, 2, 10000, 0);
        }
    });
    dataStore4.invoke(new SerializableRunnable() {

        @Override
        public void run() {
            createPartitionedRegion(true, evictionAlgorithm, partitionRegion2, 2, 2, 10000, 0);
        }
    });
}
Also used : SerializableRunnable(org.apache.geode.test.dunit.SerializableRunnable) CacheSerializableRunnable(org.apache.geode.cache30.CacheSerializableRunnable)

Example 69 with SerializableRunnable

use of org.apache.geode.test.dunit.SerializableRunnable in project geode by apache.

the class EvictionStatsDUnitTest method createPartitionedRegionInAllVMS.

private void createPartitionedRegionInAllVMS(final boolean setEvictionOn, final EvictionAlgorithm evictionAlgorithm, final String regionName, final int totalNoOfBuckets, final int evictionAction, final int evictorInterval) {
    dataStore1.invoke(new SerializableRunnable() {

        @Override
        public void run() {
            createPartitionedRegion(setEvictionOn, evictionAlgorithm, regionName, totalNoOfBuckets, evictionAction, evictorInterval);
        }
    });
    dataStore2.invoke(new SerializableRunnable() {

        @Override
        public void run() {
            createPartitionedRegion(setEvictionOn, evictionAlgorithm, regionName, totalNoOfBuckets, evictionAction, evictorInterval);
        }
    });
}
Also used : SerializableRunnable(org.apache.geode.test.dunit.SerializableRunnable) CacheSerializableRunnable(org.apache.geode.cache30.CacheSerializableRunnable)

Example 70 with SerializableRunnable

use of org.apache.geode.test.dunit.SerializableRunnable in project geode by apache.

the class EvictionTestBase method createCacheInAllVms.

public void createCacheInAllVms() {
    dataStore1.invoke(new SerializableRunnable() {

        @Override
        public void run() {
            createCache();
        }
    });
    dataStore2.invoke(new SerializableRunnable() {

        @Override
        public void run() {
            createCache();
        }
    });
}
Also used : SerializableRunnable(org.apache.geode.test.dunit.SerializableRunnable) CacheSerializableRunnable(org.apache.geode.cache30.CacheSerializableRunnable)

Aggregations

SerializableRunnable (org.apache.geode.test.dunit.SerializableRunnable)741 VM (org.apache.geode.test.dunit.VM)405 Test (org.junit.Test)403 DistributedTest (org.apache.geode.test.junit.categories.DistributedTest)353 Region (org.apache.geode.cache.Region)347 Host (org.apache.geode.test.dunit.Host)344 Cache (org.apache.geode.cache.Cache)274 CacheSerializableRunnable (org.apache.geode.cache30.CacheSerializableRunnable)259 CacheException (org.apache.geode.cache.CacheException)207 AttributesFactory (org.apache.geode.cache.AttributesFactory)204 FlakyTest (org.apache.geode.test.junit.categories.FlakyTest)198 PartitionedRegion (org.apache.geode.internal.cache.PartitionedRegion)166 LocalRegion (org.apache.geode.internal.cache.LocalRegion)160 IOException (java.io.IOException)145 PartitionAttributesFactory (org.apache.geode.cache.PartitionAttributesFactory)120 Properties (java.util.Properties)66 SerializableCallable (org.apache.geode.test.dunit.SerializableCallable)66 AsyncInvocation (org.apache.geode.test.dunit.AsyncInvocation)65 IgnoredException (org.apache.geode.test.dunit.IgnoredException)61 WaitCriterion (org.apache.geode.test.dunit.WaitCriterion)53