use of org.apache.geode.internal.cache.InitialImageOperation.RequestImageMessage in project geode by apache.
the class PersistentRecoveryOrderDUnitTest method testMissingEntryOnDisk.
@Test
public void testMissingEntryOnDisk() throws Exception {
Host host = Host.getHost(0);
VM vm0 = host.getVM(0);
VM vm1 = host.getVM(1);
// Add a hook which will perform some updates while the region is initializing
vm0.invoke(new SerializableRunnable() {
public void run() {
DistributionMessageObserver.setInstance(new DistributionMessageObserver() {
@Override
public void beforeProcessMessage(DistributionManager dm, DistributionMessage message) {
if (message instanceof RequestImageMessage) {
Cache cache = getCache();
Region region = cache.getRegion(REGION_NAME);
if (region == null) {
LogWriterUtils.getLogWriter().severe("removing listener for PersistentRecoveryOrderDUnitTest because region was not found: " + REGION_NAME);
Object old = DistributionMessageObserver.setInstance(null);
if (old != this) {
LogWriterUtils.getLogWriter().severe("removed listener was not the invoked listener", new Exception("stack trace"));
}
return;
}
region.put("A", "B");
region.destroy("A");
region.put("A", "C");
}
}
@Override
public void afterProcessMessage(DistributionManager dm, DistributionMessage message) {
}
});
}
});
createPersistentRegion(vm0);
createPersistentRegion(vm1);
checkForEntry(vm1);
closeRegion(vm0);
closeRegion(vm1);
// This should work
createPersistentRegion(vm1);
checkForEntry(vm1);
}
use of org.apache.geode.internal.cache.InitialImageOperation.RequestImageMessage in project geode by apache.
the class PersistentRecoveryOrderDUnitTest method testCrashDuringGII.
/**
* Test to make sure that if if a member crashes while a GII is in progress, we wait for the
* member to come back for starting.
*/
@Test
public void testCrashDuringGII() throws Exception {
Host host = Host.getHost(0);
VM vm0 = host.getVM(0);
VM vm1 = host.getVM(1);
LogWriterUtils.getLogWriter().info("Creating region in VM0");
createPersistentRegion(vm0);
LogWriterUtils.getLogWriter().info("Creating region in VM1");
createPersistentRegion(vm1);
putAnEntry(vm0);
LogWriterUtils.getLogWriter().info("closing region in vm0");
closeRegion(vm0);
updateTheEntry(vm1);
LogWriterUtils.getLogWriter().info("closing region in vm1");
closeRegion(vm1);
// This ought to wait for VM1 to come back
LogWriterUtils.getLogWriter().info("Creating region in VM0");
AsyncInvocation future = createPersistentRegionAsync(vm0);
waitForBlockedInitialization(vm0);
assertTrue(future.isAlive());
// Add a hook which will disconnect from the distributed
// system when the initial image message shows up.
vm1.invoke(new SerializableRunnable() {
public void run() {
sawRequestImageMessage.set(false);
DistributionMessageObserver.setInstance(new DistributionMessageObserver() {
@Override
public void beforeProcessMessage(DistributionManager dm, DistributionMessage message) {
if (message instanceof RequestImageMessage) {
DistributionMessageObserver.setInstance(null);
disconnectFromDS();
synchronized (sawRequestImageMessage) {
sawRequestImageMessage.set(true);
sawRequestImageMessage.notifyAll();
}
}
}
@Override
public void afterProcessMessage(DistributionManager dm, DistributionMessage message) {
}
});
}
});
createPersistentRegion(vm1);
vm1.invoke(new SerializableRunnable() {
public void run() {
synchronized (sawRequestImageMessage) {
try {
while (!sawRequestImageMessage.get()) {
sawRequestImageMessage.wait();
}
} catch (InterruptedException ex) {
}
}
}
});
waitForBlockedInitialization(vm0);
assertTrue(future.isAlive());
// Now create the region again. The initialization should
// work (the observer was cleared when we disconnected from the DS.
createPersistentRegion(vm1);
;
future.join(MAX_WAIT);
if (future.isAlive()) {
fail("Region not created within" + MAX_WAIT);
}
if (future.exceptionOccurred()) {
throw new Exception(future.getException());
}
checkForEntry(vm0);
checkForEntry(vm1);
checkForRecoveryStat(vm1, true);
checkForRecoveryStat(vm0, false);
}
use of org.apache.geode.internal.cache.InitialImageOperation.RequestImageMessage in project geode by apache.
the class PersistentPartitionedRegionDUnitTest method testCrashDuringBucketGII2.
/**
* Another test for bug 41436. If the GII source crashes before the GII is complete, we need to
* make sure that later we can recover redundancy.
*
* In this test case, we bring the GII down before we bring the source back up, to make sure the
* source still discovers that the GII target is no longer hosting the bucket.
*
* @throws InterruptedException
*/
@Test
public void testCrashDuringBucketGII2() throws InterruptedException {
IgnoredException.addIgnoredException("PartitionOfflineException");
Host host = Host.getHost(0);
VM vm0 = host.getVM(0);
final VM vm1 = host.getVM(1);
VM vm2 = host.getVM(2);
createPR(vm0, 1);
createData(vm0, 0, 1, "value");
// Add an observer which will close the cache when the GII starts
vm0.invoke(new SerializableRunnable("Set crashing observer") {
public void run() {
DistributionMessageObserver.setInstance(new DistributionMessageObserver() {
@Override
public void beforeProcessMessage(DistributionManager dm, DistributionMessage message) {
if (message instanceof RequestImageMessage) {
RequestImageMessage rim = (RequestImageMessage) message;
if (rim.regionPath.contains("_0")) {
DistributionMessageObserver.setInstance(null);
getCache().close();
}
}
}
});
}
});
createPR(vm1, 1);
// Make sure vm1 didn't create the bucket
assertEquals(Collections.emptySet(), getBucketList(vm1));
closeCache(vm1);
AsyncInvocation async0 = createPRAsync(vm0, 1, 0, 113);
async0.join(500);
// vm0 should get stuck waiting for vm1 to recover from disk,
// because vm0 thinks vm1 has the bucket
assertTrue(async0.isAlive());
createPR(vm1, 1, 0);
// Make sure vm0 recovers the bucket
assertEquals(Collections.singleton(0), getBucketList(vm0));
// vm1 should satisfy redundancy for the bucket as well
WaitCriterion ev = new WaitCriterion() {
public boolean done() {
return (Collections.singleton(0).equals(getBucketList(vm1)));
}
public String description() {
return null;
}
};
Wait.waitForCriterion(ev, 30 * 1000, 200, true);
assertEquals(Collections.singleton(0), getBucketList(vm1));
}
use of org.apache.geode.internal.cache.InitialImageOperation.RequestImageMessage in project geode by apache.
the class PersistentPartitionedRegionDUnitTest method testBug42226.
/**
* Test for bug 4226. 1. Member A has the bucket 2. Member B starts creating the bucket. It tells
* member A that it hosts the bucket 3. Member A crashes 4. Member B destroys the bucket and
* throws a partition offline exception, because it wasn't able to complete initialization. 5.
* Member A recovers, and gets stuck waiting for member B.
*
* @throws Throwable
*/
// GEODE-1208: time sensitive, multiple non-thread-safe test hooks,
@Category(FlakyTest.class)
// async actions
@Test
public void testBug42226() throws Exception {
Host host = Host.getHost(0);
VM vm0 = host.getVM(0);
VM vm1 = host.getVM(1);
// Add a hook which will disconnect from the distributed
// system when the initial image message shows up.
vm0.invoke(new SerializableRunnable() {
public void run() {
DistributionMessageObserver.setInstance(new DistributionMessageObserver() {
@Override
public void beforeProcessMessage(DistributionManager dm, DistributionMessage message) {
if (message instanceof RequestImageMessage) {
RequestImageMessage rim = (RequestImageMessage) message;
// Don't disconnect until we see a bucket
if (rim.regionPath.contains("_B_")) {
DistributionMessageObserver.setInstance(null);
disconnectFromDS();
}
}
}
@Override
public void afterProcessMessage(DistributionManager dm, DistributionMessage message) {
}
});
}
});
LogWriterUtils.getLogWriter().info("Creating region in VM0");
createPR(vm0, 1, 0, 1);
// Make sure we create a bucket
createData(vm0, 0, 1, "a");
// This should recover redundancy, which should cause vm0 to disconnect
IgnoredException ex = IgnoredException.addIgnoredException("PartitionOfflineException");
try {
LogWriterUtils.getLogWriter().info("Creating region in VM1");
createPR(vm1, 1, 0, 1);
// Make sure get a partition offline exception
try {
createData(vm1, 0, 1, "a");
} catch (RMIException e) {
// We expect a PartitionOfflineException
if (!(e.getCause() instanceof PartitionOfflineException)) {
throw e;
}
}
} finally {
ex.remove();
}
// Make sure vm0 is really disconnected (avoids a race with the observer).
vm0.invoke(new SerializableRunnable() {
public void run() {
disconnectFromDS();
}
});
// This should recreate the bucket
AsyncInvocation async1 = createPRAsync(vm0, 1, 0, 1);
async1.getResult(MAX_WAIT);
checkData(vm1, 0, 1, "a");
}
Aggregations