use of org.apache.geode.test.dunit.SerializableRunnable in project geode by apache.
the class PRQueryDUnitHelper method getCacheSerializableRunnableForLocalRegionWithAsyncIndexCreation.
public CacheSerializableRunnable getCacheSerializableRunnableForLocalRegionWithAsyncIndexCreation(final String regionName, final Class constraint) {
SerializableRunnable createPrRegion;
createPrRegion = new CacheSerializableRunnable(regionName) {
@Override
public void run2() throws CacheException {
Cache cache = getCache();
Region localRegion = null;
try {
AttributesFactory attr = new AttributesFactory();
attr.setValueConstraint(constraint);
attr.setScope(Scope.LOCAL);
attr.setIndexMaintenanceSynchronous(false);
localRegion = cache.createRegion(regionName, attr.create());
} catch (IllegalStateException ex) {
org.apache.geode.test.dunit.LogWriterUtils.getLogWriter().warning("PRQueryDUnitHelper#getCacheSerializableRunnableForPRCreate: Creation caught IllegalStateException", ex);
}
assertNotNull("PRQueryDUnitHelper#getCacheSerializableRunnableForPRCreate: Partitioned Region " + regionName + " not in cache", cache.getRegion(regionName));
assertNotNull("PRQueryDUnitHelper#getCacheSerializableRunnableForPRCreate: Partitioned Region ref null", localRegion);
assertTrue("PRQueryDUnitHelper#getCacheSerializableRunnableForPRCreate: Partitioned Region ref claims to be destroyed", !localRegion.isDestroyed());
}
};
return (CacheSerializableRunnable) createPrRegion;
}
use of org.apache.geode.test.dunit.SerializableRunnable in project geode by apache.
the class PRQueryDUnitHelper method getCacheSerializableRunnableForPRRandomOps.
/**
* This function puts portfolio objects into the created Region (PR or RR). Also, other operation
* like, invalidate, destroy and create are performed in random manner based on
* {@link Random#nextInt(int)}.
*
* @param regionName
* @param to
* @param from
* @return cacheSerializable object
*/
public CacheSerializableRunnable getCacheSerializableRunnableForPRRandomOps(final String regionName, final int from, final int to) {
SerializableRunnable prPuts = new CacheSerializableRunnable("PRPuts") {
@Override
public void run2() throws CacheException {
Cache cache = getCache();
Region region = cache.getRegion(regionName);
for (int i = 0; i < 3; i++) {
for (int j = from; j < to; j++) {
int op = new Random().nextInt(4);
try {
switch(op) {
case 0:
// Put operation
region.put(new Integer(j), new Portfolio(j));
break;
case 1:
// invalidate
if (region.containsKey(new Integer(j))) {
region.invalidate(new Integer(j));
}
break;
case 2:
if (region.containsKey(new Integer(j))) {
region.destroy(new Integer(j));
}
break;
case 3:
if (!region.containsKey(new Integer(j))) {
region.create(new Integer(j), null);
}
break;
default:
break;
}
} catch (EntryExistsException e) {
// Do nothing let it go
org.apache.geode.test.dunit.LogWriterUtils.getLogWriter().info("EntryExistsException was thrown for key " + j);
} catch (EntryNotFoundException e) {
// Do nothing let it go
org.apache.geode.test.dunit.LogWriterUtils.getLogWriter().info("EntryNotFoundException was thrown for key " + j);
}
}
}
}
};
return (CacheSerializableRunnable) prPuts;
}
use of org.apache.geode.test.dunit.SerializableRunnable in project geode by apache.
the class PRQueryDUnitHelper method getCacheSerializableRunnableForPersistentPRCreate.
public CacheSerializableRunnable getCacheSerializableRunnableForPersistentPRCreate(final String regionName, final int redundancy, final Class constraint) {
SerializableRunnable createPrRegion;
createPrRegion = new CacheSerializableRunnable(regionName) {
@Override
public void run2() throws CacheException {
Cache cache = getCache();
Region partitionedregion = null;
try {
cache.createDiskStoreFactory().setDiskDirs(JUnit4CacheTestCase.getDiskDirs()).create("diskstore");
AttributesFactory attr = new AttributesFactory();
attr.setValueConstraint(constraint);
attr.setDataPolicy(DataPolicy.PERSISTENT_PARTITION);
attr.setDiskStoreName("diskstore");
PartitionAttributesFactory paf = new PartitionAttributesFactory();
PartitionAttributes prAttr = paf.setRedundantCopies(redundancy).create();
attr.setPartitionAttributes(prAttr);
partitionedregion = cache.createRegion(regionName, attr.create());
} catch (IllegalStateException ex) {
org.apache.geode.test.dunit.LogWriterUtils.getLogWriter().warning("PRQueryDUnitHelper#getCacheSerializableRunnableForPRCreateWithRedundancy: Creation caught IllegalStateException", ex);
}
assertNotNull("PRQueryDUnitHelper#getCacheSerializableRunnableForPRCreateWithRedundancy: Partitioned Region " + regionName + " not in cache", cache.getRegion(regionName));
assertNotNull("PRQueryDUnitHelper#getCacheSerializableRunnableForPRCreateWithRedundancy: Partitioned Region ref null", partitionedregion);
assertTrue("PRQueryDUnitHelper#getCacheSerializableRunnableForPRCreateWithRedundancy: Partitioned Region ref claims to be destroyed", !partitionedregion.isDestroyed());
}
};
return (CacheSerializableRunnable) createPrRegion;
}
use of org.apache.geode.test.dunit.SerializableRunnable in project geode by apache.
the class ConnectionPoolDUnitTest method test024CreateNullValue.
/**
* Tests that invoking {@link Region#create} with a <code>null</code> value does the right thing
* with the {@link Pool}.
*
* @since GemFire 3.5
*/
@Test
public void test024CreateNullValue() throws CacheException {
final String name = this.getName();
final Host host = Host.getHost(0);
VM vm0 = host.getVM(0);
VM vm1 = host.getVM(1);
VM vm2 = host.getVM(2);
final Object createCallbackArg = "CREATE CALLBACK ARG";
vm0.invoke(new CacheSerializableRunnable("Create Cache Server") {
public void run2() throws CacheException {
AttributesFactory factory = getBridgeServerRegionAttributes(null, null);
createRegion(name, factory.create());
// pause(1000);
try {
startBridgeServer(0);
} catch (Exception ex) {
org.apache.geode.test.dunit.Assert.fail("While starting CacheServer", ex);
}
}
});
final int port = vm0.invoke(() -> ConnectionPoolDUnitTest.getCacheServerPort());
final String host0 = NetworkUtils.getServerHostName(vm0.getHost());
SerializableRunnable create = new CacheSerializableRunnable("Create region") {
public void run2() throws CacheException {
getLonerSystem();
getCache();
AttributesFactory factory = new AttributesFactory();
factory.setScope(Scope.LOCAL);
factory.setConcurrencyChecksEnabled(false);
ClientServerTestCase.configureConnectionPool(factory, host0, port, -1, true, -1, -1, null);
createRegion(name, factory.create());
}
};
vm1.invoke(create);
vm2.invoke(create);
vm2.invoke(new CacheSerializableRunnable("Create nulls") {
public void run2() throws CacheException {
Region region = getRootRegion().getSubregion(name);
for (int i = 0; i < 10; i++) {
region.create(new Integer(i), null, createCallbackArg);
}
}
});
// Wait for updates to be propagated
Wait.pause(1000);
vm2.invoke(new CacheSerializableRunnable("Verify invalidates") {
public void run2() throws CacheException {
Region region = getRootRegion().getSubregion(name);
for (int i = 0; i < 10; i++) {
Region.Entry entry = region.getEntry(new Integer(i));
assertNotNull(entry);
assertNull(entry.getValue());
}
}
});
vm1.invoke(new CacheSerializableRunnable("Attempt to create values") {
public void run2() throws CacheException {
Region region = getRootRegion().getSubregion(name);
for (int i = 0; i < 10; i++) {
region.create(new Integer(i), "new" + i);
}
}
});
// Wait for updates to be propagated
Wait.pause(1000);
vm2.invoke(new CacheSerializableRunnable("Verify invalidates") {
public void run2() throws CacheException {
Region region = getRootRegion().getSubregion(name);
for (int i = 0; i < 10; i++) {
Region.Entry entry = region.getEntry(new Integer(i));
assertNotNull(entry);
assertNull(entry.getValue());
}
}
});
SerializableRunnable close = new CacheSerializableRunnable("Close Pool") {
public void run2() throws CacheException {
Region region = getRootRegion().getSubregion(name);
region.localDestroyRegion();
}
};
vm1.invoke(close);
vm2.invoke(close);
vm0.invoke(new SerializableRunnable("Stop CacheServer") {
public void run() {
stopBridgeServer(getCache());
}
});
}
use of org.apache.geode.test.dunit.SerializableRunnable in project geode by apache.
the class ConnectionPoolDUnitTest method test014InvalidateAndDestroyPropagation.
/**
* Tests that invalidates and destroys are propagated to {@link Pool}s.
*
* @since GemFire 3.5
*/
@Test
public void test014InvalidateAndDestroyPropagation() throws CacheException {
final String name = this.getName();
final Host host = Host.getHost(0);
VM vm0 = host.getVM(0);
VM vm1 = host.getVM(1);
VM vm2 = host.getVM(2);
vm0.invoke(new CacheSerializableRunnable("Create Cache Server") {
public void run2() throws CacheException {
AttributesFactory factory = getBridgeServerRegionAttributes(null, null);
createRegion(name, factory.create());
// pause(1000);
try {
startBridgeServer(0);
} catch (Exception ex) {
org.apache.geode.test.dunit.Assert.fail("While starting CacheServer", ex);
}
}
});
final int port = vm0.invoke(() -> ConnectionPoolDUnitTest.getCacheServerPort());
final String host0 = NetworkUtils.getServerHostName(vm0.getHost());
SerializableRunnable create = new CacheSerializableRunnable("Create region") {
public void run2() throws CacheException {
getLonerSystem();
getCache();
AttributesFactory factory = new AttributesFactory();
factory.setScope(Scope.LOCAL);
factory.setConcurrencyChecksEnabled(false);
ClientServerTestCase.configureConnectionPool(factory, host0, port, -1, true, -1, -1, null);
CertifiableTestCacheListener l = new CertifiableTestCacheListener(org.apache.geode.test.dunit.LogWriterUtils.getLogWriter());
factory.setCacheListener(l);
Region rgn = createRegion(name, factory.create());
rgn.registerInterestRegex(".*", false, false);
}
};
vm1.invoke(create);
vm1.invoke(new CacheSerializableRunnable("Populate region") {
public void run2() throws CacheException {
Region region = getRootRegion().getSubregion(name);
for (int i = 0; i < 10; i++) {
region.put(new Integer(i), "old" + i);
}
}
});
vm2.invoke(create);
Wait.pause(5 * 1000);
vm1.invoke(new CacheSerializableRunnable("Turn on history") {
public void run2() throws CacheException {
Region region = getRootRegion().getSubregion(name);
CertifiableTestCacheListener ctl = (CertifiableTestCacheListener) region.getAttributes().getCacheListener();
ctl.enableEventHistory();
}
});
vm2.invoke(new CacheSerializableRunnable("Update region") {
public void run2() throws CacheException {
Region region = getRootRegion().getSubregion(name);
for (int i = 0; i < 10; i++) {
region.put(new Integer(i), "new" + i, "callbackArg" + i);
}
}
});
Wait.pause(5 * 1000);
vm1.invoke(new CacheSerializableRunnable("Verify invalidates") {
public void run2() throws CacheException {
Region region = getRootRegion().getSubregion(name);
CertifiableTestCacheListener ctl = (CertifiableTestCacheListener) region.getAttributes().getCacheListener();
for (int i = 0; i < 10; i++) {
Object key = new Integer(i);
ctl.waitForInvalidated(key);
Region.Entry entry = region.getEntry(key);
assertNotNull(entry);
assertNull(entry.getValue());
}
{
List l = ctl.getEventHistory();
assertEquals(10, l.size());
for (int i = 0; i < 10; i++) {
Object key = new Integer(i);
EntryEvent ee = (EntryEvent) l.get(i);
assertEquals(key, ee.getKey());
assertEquals("old" + i, ee.getOldValue());
assertEquals(Operation.INVALIDATE, ee.getOperation());
assertEquals("callbackArg" + i, ee.getCallbackArgument());
assertEquals(true, ee.isOriginRemote());
}
}
}
});
vm2.invoke(new CacheSerializableRunnable("Validate original and destroy") {
public void run2() throws CacheException {
Region region = getRootRegion().getSubregion(name);
for (int i = 0; i < 10; i++) {
Object key = new Integer(i);
assertEquals("new" + i, region.getEntry(key).getValue());
region.destroy(key, "destroyCB" + i);
}
}
});
Wait.pause(5 * 1000);
vm1.invoke(new CacheSerializableRunnable("Verify destroys") {
public void run2() throws CacheException {
Region region = getRootRegion().getSubregion(name);
CertifiableTestCacheListener ctl = (CertifiableTestCacheListener) region.getAttributes().getCacheListener();
for (int i = 0; i < 10; i++) {
Object key = new Integer(i);
ctl.waitForDestroyed(key);
Region.Entry entry = region.getEntry(key);
assertNull(entry);
}
{
List l = ctl.getEventHistory();
assertEquals(10, l.size());
for (int i = 0; i < 10; i++) {
Object key = new Integer(i);
EntryEvent ee = (EntryEvent) l.get(i);
assertEquals(key, ee.getKey());
assertEquals(null, ee.getOldValue());
assertEquals(Operation.DESTROY, ee.getOperation());
assertEquals("destroyCB" + i, ee.getCallbackArgument());
assertEquals(true, ee.isOriginRemote());
}
}
}
});
vm2.invoke(new CacheSerializableRunnable("recreate") {
public void run2() throws CacheException {
Region region = getRootRegion().getSubregion(name);
for (int i = 0; i < 10; i++) {
Object key = new Integer(i);
region.create(key, "create" + i);
}
}
});
Wait.pause(5 * 1000);
vm1.invoke(new CacheSerializableRunnable("Verify creates") {
public void run2() throws CacheException {
Region region = getRootRegion().getSubregion(name);
CertifiableTestCacheListener ctl = (CertifiableTestCacheListener) region.getAttributes().getCacheListener();
List l = ctl.getEventHistory();
org.apache.geode.test.dunit.LogWriterUtils.getLogWriter().info("history (should be empty): " + l);
assertEquals(0, l.size());
// now see if we can get it from the server
for (int i = 0; i < 10; i++) {
Object key = new Integer(i);
assertEquals("create" + i, region.get(key, "loadCB" + i));
}
l = ctl.getEventHistory();
assertEquals(10, l.size());
for (int i = 0; i < 10; i++) {
Object key = new Integer(i);
EntryEvent ee = (EntryEvent) l.get(i);
org.apache.geode.test.dunit.LogWriterUtils.getLogWriter().info("processing " + ee);
assertEquals(key, ee.getKey());
assertEquals(null, ee.getOldValue());
assertEquals("create" + i, ee.getNewValue());
assertEquals(Operation.LOCAL_LOAD_CREATE, ee.getOperation());
assertEquals("loadCB" + i, ee.getCallbackArgument());
assertEquals(false, ee.isOriginRemote());
}
}
});
SerializableRunnable close = new CacheSerializableRunnable("Close Pool") {
public void run2() throws CacheException {
Region region = getRootRegion().getSubregion(name);
region.localDestroyRegion();
}
};
vm1.invoke(close);
vm2.invoke(close);
vm0.invoke(new SerializableRunnable("Stop CacheServer") {
public void run() {
stopBridgeServer(getCache());
}
});
}
Aggregations