Search in sources :

Example 36 with SerializableCallable

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

the class EvictionTestBase method validateNoOfEvictionsInDataStore3N4.

public void validateNoOfEvictionsInDataStore3N4(final String regionName, final int noOfEvictions) {
    final SerializableCallable validate = new SerializableCallable("Validate evictions") {

        public Object call() throws Exception {
            try {
                final PartitionedRegion pr = (PartitionedRegion) cache.getRegion(regionName);
                return new Long(((AbstractLRURegionMap) pr.entries)._getLruList().stats().getEvictions());
            } finally {
            }
        }
    };
    long evictionsInVM1 = (Long) dataStore3.invoke(validate);
    long evictionsInVM2 = (Long) dataStore4.invoke(validate);
    assertEquals(noOfEvictions, evictionsInVM1 + evictionsInVM2);
}
Also used : SerializableCallable(org.apache.geode.test.dunit.SerializableCallable)

Example 37 with SerializableCallable

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

the class EvictionTestBase method validateNoOfEvictions.

public void validateNoOfEvictions(final String regionName, final int noOfEvictions) {
    final SerializableCallable validate = new SerializableCallable("Validate evictions") {

        public Object call() throws Exception {
            try {
                final PartitionedRegion pr = (PartitionedRegion) cache.getRegion(regionName);
                for (final Iterator i = pr.getDataStore().getAllLocalBuckets().iterator(); i.hasNext(); ) {
                    final Map.Entry entry = (Map.Entry) i.next();
                    final BucketRegion bucketRegion = (BucketRegion) entry.getValue();
                    if (bucketRegion == null) {
                        continue;
                    }
                    LogWriterUtils.getLogWriter().info("FINAL bucket= " + bucketRegion.getFullPath() + "size= " + bucketRegion.size());
                }
                return new Long(((AbstractLRURegionMap) pr.entries)._getLruList().stats().getEvictions());
            } finally {
            }
        }
    };
    long evictionsInVM1 = (Long) dataStore1.invoke(validate);
    long evictionsInVM2 = (Long) dataStore2.invoke(validate);
    LogWriterUtils.getLogWriter().info("EEE evicitons = " + noOfEvictions + " " + (evictionsInVM1 + evictionsInVM2));
    assertEquals(noOfEvictions, (evictionsInVM1 + evictionsInVM2));
}
Also used : SerializableCallable(org.apache.geode.test.dunit.SerializableCallable) Iterator(java.util.Iterator) Map(java.util.Map)

Example 38 with SerializableCallable

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

the class EvictionTestBase method verifyThreadPoolTaskCount.

public void verifyThreadPoolTaskCount(final int taskCountToBeVerified) {
    final SerializableCallable getThreadPoolTaskCount = new SerializableCallable("Validate evictions") {

        public Object call() throws Exception {
            try {
                return getEvictor().getEvictorThreadPool() != null ? getEvictor().getEvictorThreadPool().getTaskCount() : 0;
            } finally {
            }
        }
    };
    Long taskCountOfVM = (Long) dataStore1.invoke(getThreadPoolTaskCount);
    assertTrue(taskCountOfVM > 0 && taskCountOfVM <= taskCountToBeVerified);
}
Also used : SerializableCallable(org.apache.geode.test.dunit.SerializableCallable)

Example 39 with SerializableCallable

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

the class PartitionedRegionInvalidateDUnitTest method testMultiVMInvalidate.

@Test
public void testMultiVMInvalidate() {
    Host host = Host.getHost(0);
    VM vm0 = host.getVM(0);
    VM vm1 = host.getVM(1);
    VM vm2 = host.getVM(2);
    VM vm3 = host.getVM(3);
    final String rName = getUniqueName();
    class CreateRegion extends SerializableCallable {

        boolean originRemote;

        public CreateRegion(boolean originRemote) {
            this.originRemote = originRemote;
        }

        public Object call() throws Exception {
            createRegion(rName, false, 1);
            Region r = getCache().getRegion(rName);
            InvalidatePRListener l = new InvalidatePRListener();
            l.originRemote = originRemote;
            r.getAttributesMutator().addCacheListener(l);
            InvalidatePRWriter w = new InvalidatePRWriter();
            r.getAttributesMutator().setCacheWriter(w);
            return null;
        }
    }
    ;
    vm0.invoke(new CreateRegion(true));
    vm1.invoke(new CreateRegion(false));
    vm2.invoke(new CreateRegion(true));
    vm3.invoke(new CreateRegion(true));
    vm1.invoke(new SerializableCallable() {

        public Object call() throws Exception {
            Region r = getCache().getRegion(rName);
            for (int i = 0; i <= 113; i++) {
                r.put(i, "value" + i);
            }
            for (int i = 0; i <= 113; i++) {
                assertNotNull(r.get(i));
            }
            r.invalidateRegion();
            return null;
        }
    });
    SerializableCallable validateCallbacks = new SerializableCallable() {

        public Object call() throws Exception {
            Region r = getCache().getRegion(rName);
            InvalidatePRListener l = (InvalidatePRListener) r.getAttributes().getCacheListeners()[0];
            assertTrue(l.afterRegionInvalidateCalled);
            l.afterRegionInvalidateCalled = false;
            l.callbackArg = "CallBACK";
            return null;
        }
    };
    vm0.invoke(validateCallbacks);
    vm1.invoke(validateCallbacks);
    vm2.invoke(validateCallbacks);
    vm3.invoke(validateCallbacks);
    vm1.invoke(new SerializableCallable() {

        public Object call() throws Exception {
            Region r = getCache().getRegion(rName);
            InvalidatePRListener l = (InvalidatePRListener) r.getAttributes().getCacheListeners()[0];
            for (int i = 0; i <= 113; i++) {
                r.put(i, "value" + i);
            }
            Object callbackArg = "CallBACK";
            l.callbackArg = callbackArg;
            r.invalidateRegion(callbackArg);
            return null;
        }
    });
    vm0.invoke(validateCallbacks);
    vm1.invoke(validateCallbacks);
    vm2.invoke(validateCallbacks);
    vm3.invoke(validateCallbacks);
    vm1.invoke(new SerializableCallable() {

        public Object call() throws Exception {
            Region r = getCache().getRegion(rName);
            for (int i = 0; i <= 113; i++) {
                assertNull("Expected null but was " + r.get(i), r.get(i));
            }
            return null;
        }
    });
}
Also used : VM(org.apache.geode.test.dunit.VM) SerializableCallable(org.apache.geode.test.dunit.SerializableCallable) Region(org.apache.geode.cache.Region) Host(org.apache.geode.test.dunit.Host) CacheWriterException(org.apache.geode.cache.CacheWriterException) Test(org.junit.Test) DistributedTest(org.apache.geode.test.junit.categories.DistributedTest)

Example 40 with SerializableCallable

use of org.apache.geode.test.dunit.SerializableCallable 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

SerializableCallable (org.apache.geode.test.dunit.SerializableCallable)502 VM (org.apache.geode.test.dunit.VM)326 Test (org.junit.Test)314 DistributedTest (org.apache.geode.test.junit.categories.DistributedTest)311 Host (org.apache.geode.test.dunit.Host)306 Region (org.apache.geode.cache.Region)224 PartitionedRegion (org.apache.geode.internal.cache.PartitionedRegion)157 IgnoredException (org.apache.geode.test.dunit.IgnoredException)155 AttributesFactory (org.apache.geode.cache.AttributesFactory)139 Cache (org.apache.geode.cache.Cache)109 PartitionAttributesFactory (org.apache.geode.cache.PartitionAttributesFactory)95 FunctionException (org.apache.geode.cache.execute.FunctionException)88 ArrayList (java.util.ArrayList)83 HashSet (java.util.HashSet)83 CacheLoaderException (org.apache.geode.cache.CacheLoaderException)77 Execution (org.apache.geode.cache.execute.Execution)74 CommitConflictException (org.apache.geode.cache.CommitConflictException)70 SerializableRunnable (org.apache.geode.test.dunit.SerializableRunnable)66 Function (org.apache.geode.cache.execute.Function)63 IOException (java.io.IOException)62