use of org.apache.geode.test.dunit.AsyncInvocation in project geode by apache.
the class PersistentPartitionedRegionDUnitTest method testCrashDuringBucketCreation.
/**
* Test for bug 41336
*/
// GEODE-1738
@Category(FlakyTest.class)
@Test
public void testCrashDuringBucketCreation() throws Throwable {
Host host = Host.getHost(0);
VM vm0 = host.getVM(0);
VM vm1 = host.getVM(1);
vm0.invoke(new SerializableRunnable("Install observer") {
public void run() {
DistributionMessageObserver.setInstance(new DistributionMessageObserver() {
@Override
public void beforeSendMessage(DistributionManager dm, DistributionMessage msg) {
if (msg instanceof ManageBucketReplyMessage) {
Cache cache = getCache();
disconnectFromDS();
await().atMost(30, SECONDS).until(() -> {
return (cache == null || cache.isClosed());
});
LogWriterUtils.getLogWriter().info("Cache is confirmed closed");
}
}
});
}
});
createPR(vm0, 0);
createPR(vm1, 0);
createData(vm1, 0, 4, "a");
Set<Integer> vm1Buckets = getBucketList(vm1);
// Make sure the test hook ran
vm0.invoke(new SerializableRunnable("Check for no distributed system") {
public void run() {
assertEquals(null, GemFireCacheImpl.getInstance());
}
});
checkData(vm1, 0, 4, "a");
assertEquals(4, vm1Buckets.size());
createPR(vm0, 0);
checkData(vm0, 0, 4, "a");
assertEquals(vm1Buckets, getBucketList(vm1));
assertEquals(Collections.emptySet(), getBucketList(vm0));
closeCache(vm0);
closeCache(vm1);
AsyncInvocation async0 = createPRAsync(vm0, 0);
AsyncInvocation async1 = createPRAsync(vm1, 0);
async0.getResult();
async1.getResult();
checkData(vm0, 0, 4, "a");
assertEquals(vm1Buckets, getBucketList(vm1));
assertEquals(Collections.emptySet(), getBucketList(vm0));
}
use of org.apache.geode.test.dunit.AsyncInvocation in project geode by apache.
the class PersistentColocatedPartitionedRegionDUnitTest method testCrashDuringRedundancySatisfaction.
/**
* Test what happens when we crash in the middle of satisfying redundancy for a colocated bucket.
*
* @throws Throwable
*/
// This test method is disabled because it is failing
// periodically and causing cruise control failures
// See bug #46748
@Test
public void testCrashDuringRedundancySatisfaction() throws Throwable {
Host host = Host.getHost(0);
VM vm0 = host.getVM(0);
VM vm1 = host.getVM(1);
SerializableRunnable createPRs = new SerializableRunnable("region1") {
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);
// Workaround for 44414 - disable recovery delay so we shutdown
// vm1 at a predictable point.
paf.setRecoveryDelay(-1);
paf.setStartupRecoveryDelay(-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());
}
};
// Create the PR on vm0
vm0.invoke(createPRs);
// Create some buckets.
createData(vm0, 0, NUM_BUCKETS, "a");
createData(vm0, 0, NUM_BUCKETS, "a", "region2");
vm1.invoke(createPRs);
// We shouldn't have created any buckets in vm1 yet.
assertEquals(Collections.emptySet(), getBucketList(vm1));
// Add an observer that will disconnect before allowing the peer to
// GII a colocated bucket. This should leave the peer with only the parent
// bucket
vm0.invoke(new SerializableRunnable() {
public void run() {
DistributionMessageObserver.setInstance(new DistributionMessageObserver() {
@Override
public void beforeProcessMessage(DistributionManager dm, DistributionMessage message) {
if (message instanceof RequestImageMessage) {
if (((RequestImageMessage) message).regionPath.contains("region2")) {
DistributionMessageObserver.setInstance(null);
disconnectFromDS();
}
}
}
});
}
});
IgnoredException ex = IgnoredException.addIgnoredException("PartitionOfflineException", vm1);
try {
// as we satisfy redundancy with vm1.
try {
RebalanceResults rr = rebalance(vm1);
} catch (Exception expected) {
// disconnect
if (!(expected.getCause() instanceof PartitionOfflineException)) {
throw expected;
}
}
// Wait for vm0 to be closed by the callback
vm0.invoke(new SerializableCallable() {
public Object call() throws Exception {
Wait.waitForCriterion(new WaitCriterion() {
public boolean done() {
InternalDistributedSystem ds = basicGetSystem();
return ds == null || !ds.isConnected();
}
public String description() {
return "DS did not disconnect";
}
}, MAX_WAIT, 100, true);
return null;
}
});
// close the cache in vm1
SerializableCallable disconnectFromDS = new SerializableCallable() {
public Object call() throws Exception {
disconnectFromDS();
return null;
}
};
vm1.invoke(disconnectFromDS);
// Make sure vm0 is disconnected. This avoids a race where we
// may still in the process of disconnecting even though the our async listener
// found the system was disconnected
vm0.invoke(disconnectFromDS);
} finally {
ex.remove();
}
// Create the cache and PRs on both members
AsyncInvocation async0 = vm0.invokeAsync(createPRs);
AsyncInvocation async1 = vm1.invokeAsync(createPRs);
async0.getResult(MAX_WAIT);
async1.getResult(MAX_WAIT);
// Make sure the data was recovered correctly
checkData(vm0, 0, NUM_BUCKETS, "a");
// Workaround for bug 46748.
checkData(vm0, 0, NUM_BUCKETS, "a", "region2");
}
use of org.apache.geode.test.dunit.AsyncInvocation in project geode by apache.
the class PersistentColocatedPartitionedRegionDUnitTest method testMultipleColocatedChildPRsMissing.
/**
* Test that when there is more than one missing colocated child persistent PRs for a region all
* missing regions are logged in the warning.
*/
@Test
public void testMultipleColocatedChildPRsMissing() throws Throwable {
// millis
int loggerTestInterval = 4000;
int numChildPRs = 2;
Host host = Host.getHost(0);
VM vm0 = host.getVM(0);
VM vm1 = host.getVM(1);
vm0.invoke(new NumChildPRsSetter(numChildPRs));
vm1.invoke(new NumChildPRsSetter(numChildPRs));
vm0.invoke(createMultipleColocatedChildPRs);
vm1.invoke(createMultipleColocatedChildPRs);
createData(vm0, 0, NUM_BUCKETS, "a");
createData(vm0, 0, NUM_BUCKETS, "b", "region2");
createData(vm0, 0, NUM_BUCKETS, "c", "region2");
Set<Integer> vm0Buckets = getBucketList(vm0, PR_REGION_NAME);
assertFalse(vm0Buckets.isEmpty());
Set<Integer> vm1Buckets = getBucketList(vm1, PR_REGION_NAME);
assertFalse(vm1Buckets.isEmpty());
for (int i = 2; i < numChildPRs + 2; ++i) {
String childName = "region" + i;
assertEquals(vm0Buckets, getBucketList(vm0, childName));
assertEquals(vm1Buckets, getBucketList(vm1, childName));
}
closeCache(vm0);
closeCache(vm1);
vm0.invoke(new ColocationLoggerIntervalSetter(loggerTestInterval));
vm1.invoke(new ColocationLoggerIntervalSetter(loggerTestInterval));
vm0.invoke(new ExpectedNumLogMessageSetter(2));
vm1.invoke(new ExpectedNumLogMessageSetter(2));
Object logMsg = "";
AsyncInvocation async0 = vm0.invokeAsync(createPRsMissingChildRegionThread);
AsyncInvocation async1 = vm1.invokeAsync(createPRsMissingChildRegionThread);
logMsg = async1.get(MAX_WAIT, TimeUnit.MILLISECONDS);
async0.get(MAX_WAIT, TimeUnit.MILLISECONDS);
vm0.invoke(new ExpectedNumLogMessageResetter());
vm1.invoke(new ExpectedNumLogMessageResetter());
vm0.invoke(new ColocationLoggerIntervalResetter());
vm1.invoke(new ColocationLoggerIntervalResetter());
assertTrue("Expected missing colocated region warning on remote. Got message \"" + logMsg + "\"", logMsg.toString().matches(PATTERN_FOR_MISSING_CHILD_LOG));
}
use of org.apache.geode.test.dunit.AsyncInvocation in project geode by apache.
the class PersistentColocatedPartitionedRegionDUnitTest method rebalanceWithOfflineChildRegion.
/**
* Test for bug 43570. Rebalance a persistent parent PR before we recover the persistent child PR
* from disk.
*
* @throws Throwable
*/
public void rebalanceWithOfflineChildRegion(SerializableRunnable createParentPR, SerializableRunnable createChildPR) throws Throwable {
Host host = Host.getHost(0);
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);
// 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
// previous host the child region.
vm2.invoke(createParentPR);
// Rebalance the parent region.
// This should not move any buckets, because
// we haven't recovered the child region
RebalanceResults rebalanceResults = rebalance(vm2);
assertEquals(0, rebalanceResults.getTotalBucketTransfersCompleted());
// Recreate the child region.
async1 = vm1.invokeAsync(createChildPR);
async0 = vm0.invokeAsync(createChildPR);
AsyncInvocation async2 = vm2.invokeAsync(createChildPR);
async0.getResult(MAX_WAIT);
async1.getResult(MAX_WAIT);
async2.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");
}
use of org.apache.geode.test.dunit.AsyncInvocation in project geode by apache.
the class PersistentColocatedPartitionedRegionDUnitTest method testColocatedPRs.
/**
* Testing that we can colocate persistent PRs
*/
@Test
public void testColocatedPRs() throws Throwable {
Host host = Host.getHost(0);
VM vm0 = host.getVM(0);
VM vm1 = host.getVM(1);
VM vm2 = host.getVM(2);
SerializableRunnable createPRs = new SerializableRunnable("region1") {
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(0);
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());
paf.setColocatedWith("region2");
af.setPartitionAttributes(paf.create());
af.setDataPolicy(DataPolicy.PARTITION);
af.setDiskStoreName(null);
cache.createRegion("region3", af.create());
}
};
vm0.invoke(createPRs);
vm1.invoke(createPRs);
vm2.invoke(createPRs);
createData(vm0, 0, NUM_BUCKETS, "a");
createData(vm0, 0, NUM_BUCKETS, "b", "region2");
createData(vm0, 0, NUM_BUCKETS, "c", "region3");
Set<Integer> vm0Buckets = getBucketList(vm0, PR_REGION_NAME);
assertEquals(vm0Buckets, getBucketList(vm0, "region2"));
assertEquals(vm0Buckets, getBucketList(vm0, "region3"));
Set<Integer> vm1Buckets = getBucketList(vm1, PR_REGION_NAME);
assertEquals(vm1Buckets, getBucketList(vm1, "region2"));
assertEquals(vm1Buckets, getBucketList(vm1, "region3"));
Set<Integer> vm2Buckets = getBucketList(vm2, PR_REGION_NAME);
assertEquals(vm2Buckets, getBucketList(vm2, "region2"));
assertEquals(vm2Buckets, getBucketList(vm2, "region3"));
closeCache(vm0);
closeCache(vm1);
closeCache(vm2);
AsyncInvocation async0 = vm0.invokeAsync(createPRs);
AsyncInvocation async1 = vm1.invokeAsync(createPRs);
AsyncInvocation async2 = vm2.invokeAsync(createPRs);
async0.getResult(MAX_WAIT);
async1.getResult(MAX_WAIT);
async2.getResult(MAX_WAIT);
// The secondary buckets can be recovered asynchronously,
// so wait for them to come back.
waitForBuckets(vm0, vm0Buckets, PR_REGION_NAME);
waitForBuckets(vm0, vm0Buckets, "region2");
waitForBuckets(vm1, vm1Buckets, PR_REGION_NAME);
waitForBuckets(vm1, vm1Buckets, "region2");
checkData(vm0, 0, NUM_BUCKETS, "a");
checkData(vm0, 0, NUM_BUCKETS, "b", "region2");
// region 3 didn't have persistent data, so it nothing should be recovered
checkData(vm0, 0, NUM_BUCKETS, null, "region3");
// Make sure can do a put in all of the buckets in region 3
createData(vm0, 0, NUM_BUCKETS, "c", "region3");
// Now all of those buckets should exist.
checkData(vm0, 0, NUM_BUCKETS, "c", "region3");
// The region 3 buckets should be restored in the appropriate places.
assertEquals(vm0Buckets, getBucketList(vm0, "region3"));
assertEquals(vm1Buckets, getBucketList(vm1, "region3"));
assertEquals(vm2Buckets, getBucketList(vm2, "region3"));
}
Aggregations