use of org.apache.geode.test.dunit.SerializableRunnable in project geode by apache.
the class PartitionedRegionCreationDUnitTest method getCacheSerializableRunnableForPRPersistence.
/**
* this function creates partition region with the specified persistence and throws appropriate
* exception
*/
public CacheSerializableRunnable getCacheSerializableRunnableForPRPersistence(final String regionName, final int localMaxMemory, final boolean isPersistent, final boolean expectException) {
SerializableRunnable createPrRegion1;
createPrRegion1 = new CacheSerializableRunnable(regionName) {
@Override
public void run2() throws CacheException {
Cache cache = getCache();
Region partitionedregion = null;
try {
AttributesFactory attr = new AttributesFactory();
PartitionAttributesFactory paf = new PartitionAttributesFactory();
// 0: accessor
paf.setLocalMaxMemory(localMaxMemory);
PartitionAttributes prAttr = paf.create();
attr.setPartitionAttributes(prAttr);
if (isPersistent) {
attr.setDataPolicy(DataPolicy.PERSISTENT_PARTITION);
} else {
attr.setDataPolicy(DataPolicy.PARTITION);
}
partitionedregion = cache.createRegion(regionName, attr.create());
if (expectException) {
fail("Expect exception but it did not");
}
assertNotNull("Partitioned Region " + regionName + " not in cache", cache.getRegion(regionName));
assertNotNull("Partitioned Region ref null", partitionedregion);
assertTrue("Partitioned Region ref claims to be destroyed", !partitionedregion.isDestroyed());
} catch (IllegalStateException ex) {
if (localMaxMemory > 0) {
// datastore
assertTrue(ex.getMessage().contains("DataPolicy for Datastore members should all be persistent or not."));
} else {
assertTrue(ex.getMessage().contains("Persistence is not allowed when local-max-memory is zero."));
}
}
}
};
return (CacheSerializableRunnable) createPrRegion1;
}
use of org.apache.geode.test.dunit.SerializableRunnable in project geode by apache.
the class PartitionedRegionCreationDUnitTest method getCacheSerializableRunnableForPRInitialize.
/**
* This function tests root, allpartition region and their scope and mirrortype attribute.
*/
public CacheSerializableRunnable getCacheSerializableRunnableForPRInitialize() {
SerializableRunnable initializePrRegion;
initializePrRegion = new CacheSerializableRunnable("initialize") {
@Override
public void run2() throws CacheException {
Cache cache = getCache();
Region root = cache.getRegion(PartitionedRegionHelper.PR_ROOT_REGION_NAME);
if (root == null)
fail("PartionedRegionInitializationDUnitTest() - the " + PartitionedRegionHelper.PR_ROOT_REGION_NAME + " do not exists");
RegionAttributes regionAttribs = root.getAttributes();
Scope scope = regionAttribs.getScope();
if (!scope.isDistributedAck())
fail("PartionedRegionInitializationDUnitTest() - the " + PartitionedRegionHelper.PR_ROOT_REGION_NAME + " scope is not distributedAck");
assertEquals("PartionedRegionInitializationTest() - the " + PartitionedRegionHelper.PR_ROOT_REGION_NAME + " does not have the proper data policy" + DataPolicy.REPLICATE, DataPolicy.REPLICATE, regionAttribs.getDataPolicy());
// Region allPartitionedRegions = root
// .getSubregion(PartitionedRegionHelper.PARTITIONED_REGION_CONFIG_NAME);
// if (allPartitionedRegions == null)
// fail("PartionedRegionInitializationTest() - the "
// + PartitionedRegionHelper.PARTITIONED_REGION_CONFIG_NAME
// + " do not exists");
// regionAttribs = allPartitionedRegions.getAttributes();
// scope = regionAttribs.getScope();
// if (!scope.isDistributedAck())
// fail("PartionedRegionInitializationTest() - the "
// + PartitionedRegionHelper.PARTITIONED_REGION_CONFIG_NAME
// + " scope is not global");
// DataPolicy datapolicy = regionAttribs.getDataPolicy();
// if (! DataPolicy.REPLICATE.equals(datapolicy))
// fail("PartionedRegionInitializationTest() - the "
// + PartitionedRegionHelper.PARTITIONED_REGION_CONFIG_NAME
// + " data policy is not " + DataPolicy.REPLICATE);
}
};
return (CacheSerializableRunnable) initializePrRegion;
}
use of org.apache.geode.test.dunit.SerializableRunnable in project geode by apache.
the class PartitionedRegionOffHeapEvictionDUnitTest 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();
}
use of org.apache.geode.test.dunit.SerializableRunnable in project geode by apache.
the class PartitionedRegionDelayedRecoveryDUnitTest method testStartupDelay.
// GEODE-757: time sensitive, fails because event occurs 2 millis too
@Category(FlakyTest.class)
// thread unsafe test hook
@Test
public void testStartupDelay() {
Host host = Host.getHost(0);
VM vm0 = host.getVM(0);
VM vm1 = host.getVM(1);
VM vm2 = host.getVM(2);
SerializableRunnable createPrRegions = new SerializableRunnable("createRegions") {
public void run() {
Cache cache = getCache();
InternalResourceManager.setResourceObserver(new MyResourceObserver());
AttributesFactory attr = new AttributesFactory();
PartitionAttributesFactory paf = new PartitionAttributesFactory();
paf.setStartupRecoveryDelay(5000);
paf.setRedundantCopies(1);
PartitionAttributes prAttr = paf.create();
attr.setPartitionAttributes(prAttr);
cache.createRegion("region1", attr.create());
}
};
// create the region in 2 VMS
vm0.invoke(createPrRegions);
vm1.invoke(createPrRegions);
// Do 1 put, which should create 1 bucket
vm0.invoke(new SerializableRunnable("putData") {
public void run() {
Cache cache = getCache();
PartitionedRegion region1 = (PartitionedRegion) cache.getRegion("region1");
region1.put(Integer.valueOf(1), "B");
region1.put(Integer.valueOf(2), "B");
region1.put(Integer.valueOf(3), "B");
region1.put(Integer.valueOf(4), "B");
}
});
// close 1 cache, which should make the bucket drop below
// the expected redundancy level.
vm1.invoke(new SerializableRunnable("close cache") {
public void run() {
Cache cache = getCache();
cache.close();
}
});
final long begin = System.currentTimeMillis();
// create the region in a third VM, which won't have any buckets
vm2.invoke(createPrRegions);
long elapsed = System.currentTimeMillis() - begin;
assertTrue("Create region should not have waited to recover redundancy. Elapsed=" + elapsed, elapsed < 5000);
// wait for the bucket to be copied
elapsed = waitForBucketRecovery(vm2, 4, begin);
assertTrue("Did not wait at least 5 seconds to create the bucket. Elapsed=" + elapsed, elapsed >= 5000);
vm2.invoke(new SerializableCallable("wait for primary move") {
public Object call() throws Exception {
Cache cache = getCache();
MyResourceObserver observer = (MyResourceObserver) InternalResourceManager.getResourceObserver();
observer.waitForRecovery(30, TimeUnit.SECONDS);
PartitionedRegion region1 = (PartitionedRegion) cache.getRegion("region1");
assertEquals(2, region1.getDataStore().getNumberOfPrimaryBucketsManaged());
return null;
}
});
}
use of org.apache.geode.test.dunit.SerializableRunnable in project geode by apache.
the class PartitionedRegionDelayedRecoveryDUnitTest method testDelay.
// GEODE-860: time sensitive, thread unsafe test hook, CountDownLatch,
@Category(FlakyTest.class)
// InterruptedException
@Test
public void testDelay() {
Host host = Host.getHost(0);
VM vm0 = host.getVM(0);
VM vm1 = host.getVM(1);
VM vm2 = host.getVM(2);
SerializableRunnable createPrRegions = new SerializableRunnable("createRegions") {
public void run() {
final CountDownLatch rebalancingFinished = new CountDownLatch(1);
InternalResourceManager.setResourceObserver(new ResourceObserverAdapter() {
@Override
public void rebalancingOrRecoveryFinished(Region region) {
rebalancingFinished.countDown();
}
});
try {
Cache cache = getCache();
AttributesFactory attr = new AttributesFactory();
PartitionAttributesFactory paf = new PartitionAttributesFactory();
paf.setRecoveryDelay(5000);
paf.setRedundantCopies(1);
PartitionAttributes prAttr = paf.create();
attr.setPartitionAttributes(prAttr);
cache.createRegion("region1", attr.create());
if (!rebalancingFinished.await(60000, TimeUnit.MILLISECONDS)) {
fail("Redundancy recovery did not happen within 60 seconds");
}
} catch (InterruptedException e) {
Assert.fail("interrupted", e);
} finally {
InternalResourceManager.setResourceObserver(null);
}
}
};
// create the region in 2 VMS
vm0.invoke(createPrRegions);
vm1.invoke(createPrRegions);
// Do 1 put, which should create 1 bucket
vm0.invoke(new SerializableRunnable("putData") {
public void run() {
Cache cache = getCache();
PartitionedRegion region1 = (PartitionedRegion) cache.getRegion("region1");
region1.put("A", "B");
}
});
// create the region in a third VM, which won't have any buckets
vm2.invoke(createPrRegions);
final long begin = System.currentTimeMillis();
// close 1 cache, which should make the bucket drop below
// the expected redundancy level.
vm1.invoke(new SerializableRunnable("close cache") {
public void run() {
Cache cache = getCache();
cache.close();
}
});
long elapsed = waitForBucketRecovery(vm2, 1, begin);
assertTrue("Did not wait at least 5 seconds to create the bucket. Elapsed=" + elapsed, elapsed >= 5000);
}
Aggregations