use of org.apache.geode.test.dunit.AsyncInvocation in project geode by apache.
the class PersistentColocatedPartitionedRegionDUnitTest method testMissingColocatedParentPRWherePRConfigExists.
/**
* Testing that parent colocated persistent PRs only missing on local member throws exception
*/
@Test
public void testMissingColocatedParentPRWherePRConfigExists() throws Throwable {
Host host = Host.getHost(0);
VM vm0 = host.getVM(0);
VM vm1 = host.getVM(1);
vm0.invoke(createPRsColocatedPairThread);
vm1.invoke(createPRsColocatedPairThread);
createData(vm0, 0, NUM_BUCKETS, "a");
createData(vm0, 0, NUM_BUCKETS, "b", "region2");
Set<Integer> vm0Buckets = getBucketList(vm0, PR_REGION_NAME);
assertFalse(vm0Buckets.isEmpty());
assertEquals(vm0Buckets, getBucketList(vm0, "region2"));
Set<Integer> vm1Buckets = getBucketList(vm1, PR_REGION_NAME);
assertEquals(vm1Buckets, getBucketList(vm1, "region2"));
closeCache(vm0);
closeCache(vm1);
AsyncInvocation async0 = null;
AsyncInvocation async1a = null;
AsyncInvocation async1b = null;
try {
async0 = vm0.invokeAsync(createPRsColocatedPairThread);
Object logMsg = "";
Object remoteException = null;
async1a = vm1.invokeAsync(delayedCreatePRsMissingParentRegionThread);
remoteException = async1a.get(MAX_WAIT, TimeUnit.MILLISECONDS);
assertEquals("Expected IllegalState Exception for missing colocated parent region", IllegalStateException.class, remoteException.getClass());
assertTrue("Expected IllegalState Exception for missing colocated parent region", remoteException.toString().matches("java.lang.IllegalStateException: Region specified in 'colocated-with'.*"));
} finally {
// The real test is done now (either passing or failing) but there's some cleanup in this test
// that needs to be done.
//
// The vm0 invokeAsync thread is still alive after the expected exception on vm1. Cleanup by
// first re-creating both regions
// on vm1, vm0 thread should now complete. Then wait (i.e. join() on the thread) for the new
// vm1 thread and the vm0 thread to
// verify they terminated without timing out, and close the caches.
async1b = vm1.invokeAsync(createPRsColocatedPairThread);
async1b.join(MAX_WAIT);
async0.join(MAX_WAIT);
closeCache(vm1);
closeCache(vm0);
}
}
use of org.apache.geode.test.dunit.AsyncInvocation in project geode by apache.
the class PersistentColocatedPartitionedRegionDUnitTest method testRecoverySystemWithConcurrentPutter.
/**
* Test what happens when we restart persistent members while there is an accessor concurrently
* performing puts. This is for bug 43899
*/
@Test
public void testRecoverySystemWithConcurrentPutter() throws Throwable {
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);
// Define all of the runnables used in this test
// runnable to create accessors
SerializableRunnable createAccessor = new SerializableRunnable("createAccessor") {
public void run() {
Cache cache = getCache();
AttributesFactory af = new AttributesFactory();
PartitionAttributesFactory paf = new PartitionAttributesFactory();
paf.setRedundantCopies(1);
paf.setLocalMaxMemory(0);
af.setPartitionAttributes(paf.create());
af.setDataPolicy(DataPolicy.PARTITION);
cache.createRegion(PR_REGION_NAME, af.create());
paf.setColocatedWith(PR_REGION_NAME);
af.setPartitionAttributes(paf.create());
cache.createRegion("region2", af.create());
}
};
// runnable to create PRs
SerializableRunnable createPRs = new SerializableRunnable("createPRs") {
public void run() {
Cache cache = getCache();
DiskStore ds = cache.findDiskStore("disk");
if (ds == null) {
ds = cache.createDiskStoreFactory().setDiskDirs(getDiskDirs()).create("disk");
}
AttributesFactory af = new AttributesFactory();
PartitionAttributesFactory paf = new PartitionAttributesFactory();
paf.setRedundantCopies(1);
af.setPartitionAttributes(paf.create());
af.setDataPolicy(DataPolicy.PERSISTENT_PARTITION);
af.setDiskStoreName("disk");
cache.createRegion(PR_REGION_NAME, af.create());
paf.setColocatedWith(PR_REGION_NAME);
af.setPartitionAttributes(paf.create());
cache.createRegion("region2", af.create());
}
};
// runnable to close the cache.
SerializableRunnable closeCache = new SerializableRunnable("closeCache") {
public void run() {
closeCache();
}
};
// Runnable to do a bunch of puts handle exceptions
// due to the fact that member is offline.
SerializableRunnable doABunchOfPuts = new SerializableRunnable("doABunchOfPuts") {
public void run() {
Cache cache = getCache();
Region region = cache.getRegion(PR_REGION_NAME);
try {
for (int i = 0; ; i++) {
try {
region.get(i % NUM_BUCKETS);
} catch (PartitionOfflineException expected) {
// do nothing.
} catch (PartitionedRegionStorageException expected) {
// do nothing.
}
Thread.yield();
}
} catch (CacheClosedException expected) {
// ok, we're done.
}
}
};
// Runnable to clean up disk dirs on a members
SerializableRunnable cleanDiskDirs = new SerializableRunnable("Clean disk dirs") {
public void run() {
try {
cleanDiskDirs();
} catch (IOException e) {
throw new RuntimeException(e);
}
}
};
// Create the PR two members
vm1.invoke(createPRs);
vm2.invoke(createPRs);
// create the accessor.
vm0.invoke(createAccessor);
// Create some buckets.
createData(vm0, 0, NUM_BUCKETS, "a");
createData(vm0, 0, NUM_BUCKETS, "a", "region2");
// backup the system. We use this to get a snapshot of vm1 and vm2
// when they both are online. Recovering from this backup simulates
// a simulataneous kill and recovery.
backup(vm3);
// close vm1 and vm2.
vm1.invoke(closeCache);
vm2.invoke(closeCache);
// restore the backup
vm1.invoke(cleanDiskDirs);
vm2.invoke(cleanDiskDirs);
restoreBackup(2);
// in vm0, start doing a bunch of concurrent puts.
AsyncInvocation async0 = vm0.invokeAsync(doABunchOfPuts);
// This recovery should not hang (that's what we're testing for
// here.
AsyncInvocation async1 = vm1.invokeAsync(createPRs);
AsyncInvocation async2 = vm2.invokeAsync(createPRs);
async1.getResult(MAX_WAIT);
async2.getResult(MAX_WAIT);
// close the cache in vm0 to stop the async puts.
vm0.invoke(closeCache);
// make sure we didn't get an exception
async0.getResult(MAX_WAIT);
}
use of org.apache.geode.test.dunit.AsyncInvocation in project geode by apache.
the class PersistentColocatedPartitionedRegionDUnitTest method testColocatedPRsRecoveryOnePRAtATime.
/**
* Testing what happens we we recreate colocated persistent PRs by creating one PR everywhere and
* then the other PR everywhere.
*/
@Test
public void testColocatedPRsRecoveryOnePRAtATime() throws Throwable {
Host host = Host.getHost(0);
VM vm0 = host.getVM(0);
VM vm1 = host.getVM(1);
VM vm2 = host.getVM(2);
SerializableRunnable createParentPR = new SerializableRunnable("createParentPR") {
public void run() {
Cache cache = getCache();
DiskStore ds = cache.findDiskStore("disk");
if (ds == null) {
ds = cache.createDiskStoreFactory().setDiskDirs(getDiskDirs()).create("disk");
}
AttributesFactory af = new AttributesFactory();
PartitionAttributesFactory paf = new PartitionAttributesFactory();
paf.setRedundantCopies(1);
af.setPartitionAttributes(paf.create());
af.setDataPolicy(DataPolicy.PERSISTENT_PARTITION);
af.setDiskStoreName("disk");
cache.createRegion(PR_REGION_NAME, af.create());
}
};
SerializableRunnable createChildPR = getCreateChildPRRunnable();
vm0.invoke(createParentPR);
vm1.invoke(createParentPR);
vm2.invoke(createParentPR);
vm0.invoke(createChildPR);
vm1.invoke(createChildPR);
vm2.invoke(createChildPR);
createData(vm0, 0, NUM_BUCKETS, "a");
createData(vm0, 0, NUM_BUCKETS, "b", "region2");
Set<Integer> vm0Buckets = getBucketList(vm0, PR_REGION_NAME);
assertEquals(vm0Buckets, getBucketList(vm0, "region2"));
Set<Integer> vm1Buckets = getBucketList(vm1, PR_REGION_NAME);
assertEquals(vm1Buckets, getBucketList(vm1, "region2"));
Set<Integer> vm2Buckets = getBucketList(vm2, PR_REGION_NAME);
assertEquals(vm2Buckets, getBucketList(vm2, "region2"));
Set<Integer> vm0PrimaryBuckets = getPrimaryBucketList(vm0, PR_REGION_NAME);
assertEquals(vm0PrimaryBuckets, getPrimaryBucketList(vm0, "region2"));
Set<Integer> vm1PrimaryBuckets = getPrimaryBucketList(vm1, PR_REGION_NAME);
assertEquals(vm1PrimaryBuckets, getPrimaryBucketList(vm1, "region2"));
Set<Integer> vm2PrimaryBuckets = getPrimaryBucketList(vm2, PR_REGION_NAME);
assertEquals(vm2PrimaryBuckets, getPrimaryBucketList(vm2, "region2"));
closeCache(vm0);
closeCache(vm1);
closeCache(vm2);
AsyncInvocation async0 = vm0.invokeAsync(createParentPR);
AsyncInvocation async1 = vm1.invokeAsync(createParentPR);
AsyncInvocation async2 = vm2.invokeAsync(createParentPR);
async0.getResult(MAX_WAIT);
async1.getResult(MAX_WAIT);
async2.getResult(MAX_WAIT);
vm0.invoke(createChildPR);
vm1.invoke(createChildPR);
vm2.invoke(createChildPR);
Wait.pause(4000);
assertEquals(vm0Buckets, getBucketList(vm0, PR_REGION_NAME));
assertEquals(vm0Buckets, getBucketList(vm0, "region2"));
assertEquals(vm1Buckets, getBucketList(vm1, PR_REGION_NAME));
assertEquals(vm1Buckets, getBucketList(vm1, "region2"));
assertEquals(vm2Buckets, getBucketList(vm2, PR_REGION_NAME));
assertEquals(vm2Buckets, getBucketList(vm2, "region2"));
// primary can differ
vm0PrimaryBuckets = getPrimaryBucketList(vm0, PR_REGION_NAME);
assertEquals(vm0PrimaryBuckets, getPrimaryBucketList(vm0, "region2"));
vm1PrimaryBuckets = getPrimaryBucketList(vm1, PR_REGION_NAME);
assertEquals(vm1PrimaryBuckets, getPrimaryBucketList(vm1, "region2"));
vm2PrimaryBuckets = getPrimaryBucketList(vm2, PR_REGION_NAME);
assertEquals(vm2PrimaryBuckets, getPrimaryBucketList(vm2, "region2"));
checkData(vm0, 0, NUM_BUCKETS, "a");
// region 2 didn't have persistent data, so it nothing should be recovered
checkData(vm0, 0, NUM_BUCKETS, null, "region2");
// Make sure can do a put in all of the buckets in vm2
createData(vm0, 0, NUM_BUCKETS, "c", "region2");
// Now all of those buckets should exist
checkData(vm0, 0, NUM_BUCKETS, "c", "region2");
// Now all the buckets should be restored in the appropriate places.
assertEquals(vm0Buckets, getBucketList(vm0, "region2"));
assertEquals(vm1Buckets, getBucketList(vm1, "region2"));
assertEquals(vm2Buckets, getBucketList(vm2, "region2"));
}
use of org.apache.geode.test.dunit.AsyncInvocation in project geode by apache.
the class PersistentColocatedPartitionedRegionDUnitTest method replaceOfflineMemberAndRestart.
/**
* Test for support issue 7870. 1. Run three members with redundancy 1 and recovery delay 0 2.
* Kill one of the members, to trigger replacement of buckets 3. Shutdown all members and restart.
*
* What was happening is that in the parent PR, we discarded our offline data in one member, but
* in the child PR the other members ended up waiting for the child bucket to be created in the
* member that discarded it's offline data.
*
* @throws Throwable
*/
public void replaceOfflineMemberAndRestart(SerializableRunnable createPRs) throws Throwable {
disconnectAllFromDS();
Host host = Host.getHost(0);
VM vm0 = host.getVM(0);
VM vm1 = host.getVM(1);
VM vm2 = host.getVM(2);
// Create the PR on three members
vm0.invoke(createPRs);
vm1.invoke(createPRs);
vm2.invoke(createPRs);
// Create some buckets.
createData(vm0, 0, NUM_BUCKETS, "a");
createData(vm0, 0, NUM_BUCKETS, "a", "region2");
// Close one of the members to trigger redundancy recovery.
closeCache(vm2);
// Wait until redundancy is recovered.
waitForRedundancyRecovery(vm0, 1, PR_REGION_NAME);
waitForRedundancyRecovery(vm0, 1, "region2");
createData(vm0, 0, NUM_BUCKETS, "b");
createData(vm0, 0, NUM_BUCKETS, "b", "region2");
IgnoredException expected = IgnoredException.addIgnoredException("PartitionOfflineException");
try {
// Close the remaining members.
vm0.invoke(new SerializableCallable() {
public Object call() throws Exception {
InternalDistributedSystem ds = (InternalDistributedSystem) getCache().getDistributedSystem();
AdminDistributedSystemImpl.shutDownAllMembers(ds.getDistributionManager(), 600000);
return null;
}
});
// Make sure that vm-1 is completely disconnected
// The shutdown all asynchronously finishes the disconnect after
// replying to the admin member.
vm1.invoke(new SerializableRunnable() {
public void run() {
basicGetSystem().disconnect();
}
});
// Recreate the members. Try to make sure that
// the member with the latest copy of the buckets
// is the one that decides to throw away it's copy
// by starting it last.
AsyncInvocation async0 = vm0.invokeAsync(createPRs);
AsyncInvocation async1 = vm1.invokeAsync(createPRs);
Wait.pause(2000);
AsyncInvocation async2 = vm2.invokeAsync(createPRs);
async0.getResult(MAX_WAIT);
async1.getResult(MAX_WAIT);
async2.getResult(MAX_WAIT);
checkData(vm0, 0, NUM_BUCKETS, "b");
checkData(vm0, 0, NUM_BUCKETS, "b", "region2");
waitForRedundancyRecovery(vm0, 1, PR_REGION_NAME);
waitForRedundancyRecovery(vm0, 1, "region2");
waitForRedundancyRecovery(vm1, 1, PR_REGION_NAME);
waitForRedundancyRecovery(vm1, 1, "region2");
waitForRedundancyRecovery(vm2, 1, PR_REGION_NAME);
waitForRedundancyRecovery(vm2, 1, "region2");
// Make sure we don't have any extra buckets after the restart
int totalBucketCount = getBucketList(vm0).size();
totalBucketCount += getBucketList(vm1).size();
totalBucketCount += getBucketList(vm2).size();
assertEquals(2 * NUM_BUCKETS, totalBucketCount);
totalBucketCount = getBucketList(vm0, "region2").size();
totalBucketCount += getBucketList(vm1, "region2").size();
totalBucketCount += getBucketList(vm2, "region2").size();
assertEquals(2 * NUM_BUCKETS, totalBucketCount);
} finally {
expected.remove();
}
}
use of org.apache.geode.test.dunit.AsyncInvocation in project geode by apache.
the class PersistentColocatedPartitionedRegionDUnitTest method regionGetWithOfflineChild.
/**
* Create a colocated pair of persistent regions and populate them with data. Shut down the
* servers and then restart them and check the data.
* <p>
* On the restart, try region operations ({@code get()}) on the parent region before or during
* persistent recovery. The {@code concurrentCheckData} argument determines whether the operation
* from the parent region occurs before or concurrent with the child region creation and recovery.
*
* @param createParentPR {@link SerializableRunnable} for creating the parent region on one member
* @param createChildPR {@link SerializableRunnable} for creating the child region on one member
* @param concurrentCheckData
* @throws Throwable
*/
public void regionGetWithOfflineChild(SerializableRunnable createParentPR, SerializableRunnable createChildPR, boolean concurrentCheckData) throws Throwable {
Host host = Host.getHost(0);
final VM vm0 = host.getVM(0);
VM vm1 = host.getVM(1);
VM vm2 = host.getVM(2);
// Create the PRs on two members
vm0.invoke(createParentPR);
vm1.invoke(createParentPR);
vm0.invoke(createChildPR);
vm1.invoke(createChildPR);
// Create some buckets.
createData(vm0, 0, NUM_BUCKETS, "a");
createData(vm0, 0, NUM_BUCKETS, "a", "region2");
// Close the members
closeCache(vm1);
closeCache(vm0);
SerializableRunnable checkDataOnParent = (new SerializableRunnable("checkDataOnParent") {
@Override
public void run() {
Cache cache = getCache();
Region region = cache.getRegion(PR_REGION_NAME);
for (int i = 0; i < NUM_BUCKETS; i++) {
assertEquals("For key " + i, "a", region.get(i));
}
}
});
try {
// Recreate the parent region. Try to make sure that
// the member with the latest copy of the buckets
// is the one that decides to throw away it's copy
// by starting it last.
AsyncInvocation async0 = vm0.invokeAsync(createParentPR);
AsyncInvocation async1 = vm1.invokeAsync(createParentPR);
async0.getResult(MAX_WAIT);
async1.getResult(MAX_WAIT);
// Now create the parent region on vm-2. vm-2 did not
// previously host the child region.
vm2.invoke(createParentPR);
AsyncInvocation async2 = null;
AsyncInvocation asyncCheck = null;
if (concurrentCheckData) {
// Recreate the child region.
async1 = vm1.invokeAsync(createChildPR);
async0 = vm0.invokeAsync(createChildPR);
async2 = vm2.invokeAsync(new SerializableRunnable("delay") {
@Override
public void run() throws InterruptedException {
Thread.sleep(100);
vm2.invoke(createChildPR);
}
});
asyncCheck = vm0.invokeAsync(checkDataOnParent);
} else {
vm0.invoke(checkDataOnParent);
}
async0.getResult(MAX_WAIT);
async1.getResult(MAX_WAIT);
async2.getResult(MAX_WAIT);
asyncCheck.getResult(MAX_WAIT);
// Validate the data
checkData(vm0, 0, NUM_BUCKETS, "a");
checkData(vm0, 0, NUM_BUCKETS, "a", "region2");
// Make sure we can actually use the buckets in the child region.
createData(vm0, 0, NUM_BUCKETS, "c", "region2");
} finally {
// Close the members
closeCache(vm1);
closeCache(vm0);
closeCache(vm2);
}
}
Aggregations