Search in sources :

Example 71 with SerializableRunnable

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

the class EventTrackerDUnitTest method checkReplicateEventTracker.

private SerializableRunnable checkReplicateEventTracker(VM vm, final int expectedEntryCount) {
    SerializableRunnable checkEventTracker = new SerializableRunnable("checkEventTracker") {

        public void run() {
            Cache cache = getCache();
            DistributedRegion region = (DistributedRegion) cache.getRegion("replicate");
            checkEventTracker(region, expectedEntryCount);
        }
    };
    vm.invoke(checkEventTracker);
    return checkEventTracker;
}
Also used : SerializableRunnable(org.apache.geode.test.dunit.SerializableRunnable) CacheSerializableRunnable(org.apache.geode.cache30.CacheSerializableRunnable) Cache(org.apache.geode.cache.Cache)

Example 72 with SerializableRunnable

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

the class EventTrackerDUnitTest method checkBucketEventTracker.

private SerializableRunnable checkBucketEventTracker(VM vm, final int bucketNumber, final int expectedEntryCount) {
    SerializableRunnable checkEventTracker = new SerializableRunnable("checkEventTracker") {

        public void run() {
            Cache cache = getCache();
            PartitionedRegion region = (PartitionedRegion) cache.getRegion("partitioned");
            BucketRegion br = region.getBucketRegion(bucketNumber);
            checkEventTracker(br, expectedEntryCount);
        }
    };
    vm.invoke(checkEventTracker);
    return checkEventTracker;
}
Also used : SerializableRunnable(org.apache.geode.test.dunit.SerializableRunnable) CacheSerializableRunnable(org.apache.geode.cache30.CacheSerializableRunnable) Cache(org.apache.geode.cache.Cache)

Example 73 with SerializableRunnable

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

the class PartitionedRegionLocalMaxMemoryOffHeapDUnitTest method preTearDownAssertions.

@Override
public final void preTearDownAssertions() throws Exception {
    SerializableRunnable checkOrphans = new SerializableRunnable() {

        @Override
        public void run() {
            if (hasCache()) {
                OffHeapTestUtil.checkOrphans();
            }
        }
    };
    Invoke.invokeInEveryVM(checkOrphans);
    checkOrphans.run();
}
Also used : SerializableRunnable(org.apache.geode.test.dunit.SerializableRunnable)

Example 74 with SerializableRunnable

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

the class PartitionedRegionLocalMaxMemoryDUnitTest method destroyRegion.

private void destroyRegion(VM vm) {
    SerializableRunnable destroyObj = new CacheSerializableRunnable("destroyObj") {

        public void run2() {
            Cache cache = getCache();
            PartitionedRegion pr = (PartitionedRegion) cache.getRegion(Region.SEPARATOR + "testLocalMaxMemoryInPartitionedRegion0");
            assertNotNull("Name of region : " + pr.getName(), pr);
            pr.destroyRegion();
        }
    };
    vm.invoke(destroyObj);
}
Also used : CacheSerializableRunnable(org.apache.geode.cache30.CacheSerializableRunnable) SerializableRunnable(org.apache.geode.test.dunit.SerializableRunnable) CacheSerializableRunnable(org.apache.geode.cache30.CacheSerializableRunnable) Cache(org.apache.geode.cache.Cache)

Example 75 with SerializableRunnable

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

the class PartitionedRegionEntryCountDUnitTest method testTotalEntryCountAfterLocalDestroyEviction.

@Test
public void testTotalEntryCountAfterLocalDestroyEviction() {
    final Host host = Host.getHost(0);
    final VM vm1 = host.getVM(0);
    final VM vm2 = host.getVM(1);
    final VM vm3 = host.getVM(2);
    final int redundantCopies = 1;
    final int maxEntriesForVm1 = 100;
    final int maxEntriesForOtherVm = 2000;
    final String name = "PR_TEMP";
    final SerializableRunnable create = new CacheSerializableRunnable("Create Entry LRU with local destroy on a partitioned Region having max entries " + maxEntriesForVm1) {

        public void run2() {
            final AttributesFactory factory = new AttributesFactory();
            factory.setPartitionAttributes(new PartitionAttributesFactory().setRedundantCopies(redundantCopies).create());
            factory.setEvictionAttributes(EvictionAttributes.createLRUEntryAttributes(maxEntriesForVm1, EvictionAction.LOCAL_DESTROY));
            final PartitionedRegion pr = (PartitionedRegion) createRootRegion(name, factory.create());
            assertNotNull(pr);
        }
    };
    vm1.invoke(create);
    final SerializableRunnable create2 = new SerializableRunnable("Create Entry LRU with local destroy on a partitioned Region having max entries " + maxEntriesForOtherVm) {

        public void run() {
            try {
                final AttributesFactory factory = new AttributesFactory();
                factory.setPartitionAttributes(new PartitionAttributesFactory().setRedundantCopies(redundantCopies).create());
                factory.setEvictionAttributes(EvictionAttributes.createLRUEntryAttributes(maxEntriesForOtherVm, EvictionAction.LOCAL_DESTROY));
                final PartitionedRegion pr = (PartitionedRegion) createRootRegion(name, factory.create());
                assertNotNull(pr);
            } catch (final CacheException ex) {
                Assert.fail("While creating Partitioned region", ex);
            }
        }
    };
    vm2.invoke(create2);
    vm3.invoke(create2);
    final SerializableRunnable putData = new SerializableRunnable("Puts Data") {

        public void run() {
            final PartitionedRegion pr = (PartitionedRegion) getRootRegion(name);
            assertNotNull(pr);
            for (int counter = 1; counter <= 6 * maxEntriesForVm1; counter++) {
                pr.put(new Integer(counter), new byte[1]);
            }
        }
    };
    vm1.invoke(putData);
    final SerializableCallable getTotalEntryCount = new SerializableCallable("Get total entry count") {

        public Object call() throws Exception {
            try {
                final PartitionedRegion pr = (PartitionedRegion) getRootRegion(name);
                assertNotNull(pr);
                return pr.entryCount(false);
            } finally {
            }
        }
    };
    Integer v1T = (Integer) vm1.invoke(getTotalEntryCount);
    Integer v2T = (Integer) vm2.invoke(getTotalEntryCount);
    Integer v3T = (Integer) vm3.invoke(getTotalEntryCount);
    assertEquals(v1T, v2T);
    assertEquals(v1T, v3T);
    assertEquals(v2T, v3T);
    final SerializableCallable getLocalEntryCount = new SerializableCallable("Get local entry count") {

        public Object call() throws Exception {
            try {
                final PartitionedRegion pr = (PartitionedRegion) getRootRegion(name);
                assertNotNull(pr);
                return pr.entryCount(pr.getDataStore().getAllLocalPrimaryBucketIds());
            } finally {
            }
        }
    };
    Integer v1L = (Integer) vm1.invoke(getLocalEntryCount);
    Integer v2L = (Integer) vm2.invoke(getLocalEntryCount);
    Integer v3L = (Integer) vm3.invoke(getLocalEntryCount);
    Integer total = v1L + v2L + v3L;
    assertEquals(v1T, total);
}
Also used : PartitionAttributesFactory(org.apache.geode.cache.PartitionAttributesFactory) AttributesFactory(org.apache.geode.cache.AttributesFactory) PartitionAttributesFactory(org.apache.geode.cache.PartitionAttributesFactory) CacheSerializableRunnable(org.apache.geode.cache30.CacheSerializableRunnable) CacheException(org.apache.geode.cache.CacheException) VM(org.apache.geode.test.dunit.VM) SerializableCallable(org.apache.geode.test.dunit.SerializableCallable) SerializableRunnable(org.apache.geode.test.dunit.SerializableRunnable) CacheSerializableRunnable(org.apache.geode.cache30.CacheSerializableRunnable) Host(org.apache.geode.test.dunit.Host) Test(org.junit.Test) DistributedTest(org.apache.geode.test.junit.categories.DistributedTest)

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