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);
}
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));
}
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);
}
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;
}
});
}
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);
}
Aggregations