use of org.apache.geode.distributed.internal.DistributionMessage in project geode by apache.
the class PersistentRecoveryOrderDUnitTest method testCrashDuringPreparePersistentId.
// GEODE-1703: fails assertion: Region not created within30000
@Category(FlakyTest.class)
@Test
public void testCrashDuringPreparePersistentId() 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 PrepareNewPersistentMemberMessage) {
DistributionMessageObserver.setInstance(null);
disconnectFromDS();
}
}
@Override
public void afterProcessMessage(DistributionManager dm, DistributionMessage message) {
}
});
}
});
createPersistentRegion(vm0);
putAnEntry(vm0);
updateTheEntry(vm0);
AsyncInvocation async1 = createPersistentRegionAsync(vm1);
// Wait for vm 1 to get stuck waiting for vm0, because vm0 has crashed
waitForBlockedInitialization(vm1);
// closeCache(vm0);
closeCache(vm1);
try {
async1.getResult();
fail("Should have seen a CacheClosedException");
} catch (AssertionError e) {
if (!CacheClosedException.class.isInstance(getRootCause(e))) {
throw e;
}
}
createPersistentRegion(vm0);
createPersistentRegion(vm1);
;
checkForEntry(vm0);
checkForEntry(vm1);
}
use of org.apache.geode.distributed.internal.DistributionMessage in project geode by apache.
the class BackupDUnitTest method testBackupWhileBucketIsMovedBackupAfterSendDestroy.
@Test
public void testBackupWhileBucketIsMovedBackupAfterSendDestroy() throws Throwable {
Host host = Host.getHost(0);
final VM vm0 = host.getVM(0);
VM vm1 = host.getVM(1);
final VM vm2 = host.getVM(2);
DistributionMessageObserver observer = new SerializableDistributionMessageObserver() {
private volatile boolean done;
private AtomicInteger count = new AtomicInteger();
private volatile int replyId = -0xBAD;
@Override
public void beforeSendMessage(DistributionManager dm, DistributionMessage msg) {
// The bucket move will send a destroy region message.
if (msg instanceof DestroyRegionOperation.DestroyRegionMessage && !done) {
this.replyId = msg.getProcessorId();
}
}
@Override
public void beforeProcessMessage(DistributionManager dm, DistributionMessage message) {
if (message instanceof ReplyMessage && replyId != -0xBAD && replyId == message.getProcessorId() && !done && // we need two replies
count.incrementAndGet() == 2) {
backup(vm2);
done = true;
}
}
};
backupWhileBucketIsMoved(observer);
}
use of org.apache.geode.distributed.internal.DistributionMessage in project geode by apache.
the class BackupDUnitTest method testBackupWhileBucketIsMovedBackupBeforeSendDestroy.
@Test
public void testBackupWhileBucketIsMovedBackupBeforeSendDestroy() throws Throwable {
Host host = Host.getHost(0);
final VM vm2 = host.getVM(2);
DistributionMessageObserver observer = new SerializableDistributionMessageObserver() {
private volatile boolean done;
private AtomicInteger count = new AtomicInteger();
private volatile int replyId = -0xBAD;
@Override
public void beforeSendMessage(DistributionManager dm, DistributionMessage msg) {
// The bucket move will send a destroy region message.
if (msg instanceof DestroyRegionOperation.DestroyRegionMessage && !done) {
backup(vm2);
done = true;
}
}
};
backupWhileBucketIsMoved(observer);
}
use of org.apache.geode.distributed.internal.DistributionMessage in project geode by apache.
the class InterruptsDUnitTest method testDRPutWithInterrupt.
/**
* A simple test case that we are actually persisting with a PR.
*
* @throws Throwable
*/
@Test
public void testDRPutWithInterrupt() throws Throwable {
Host host = Host.getHost(0);
final VM vm0 = host.getVM(0);
VM vm1 = host.getVM(1);
createRegion(vm0);
// put some data in vm0
createData(vm0, 0, 10, "a");
final SerializableCallable interruptTask = new SerializableCallable() {
@Override
public Object call() throws Exception {
puttingThread.interrupt();
return null;
}
};
vm1.invoke(new SerializableCallable() {
@Override
public Object call() throws Exception {
disconnectFromDS();
DistributionMessageObserver.setInstance(new DistributionMessageObserver() {
@Override
public void beforeProcessMessage(DistributionManager dm, DistributionMessage message) {
if (message instanceof UpdateMessage && ((UpdateMessage) message).regionPath.contains("region") && doInterrupt.compareAndSet(true, false)) {
vm0.invoke(interruptTask);
DistributionMessageObserver.setInstance(null);
}
}
});
return null;
}
});
createRegion(vm1);
SerializableCallable doPuts = new SerializableCallable() {
@Override
public Object call() throws Exception {
puttingThread = Thread.currentThread();
Region<Object, Object> region = getCache().getRegion("region");
long value = 0;
long end = System.nanoTime() + TimeUnit.MILLISECONDS.toNanos(MAX_WAIT);
while (!Thread.currentThread().isInterrupted()) {
region.put(0, value);
if (System.nanoTime() > end) {
fail("Did not get interrupted in 60 seconds");
}
}
return null;
}
};
AsyncInvocation async0 = vm0.invokeAsync(doPuts);
vm1.invoke(new SerializableCallable() {
@Override
public Object call() throws Exception {
doInterrupt.set(true);
return null;
}
});
// vm0.invoke(new SerializableCallable() {
//
// @Override
// public Object call() throws Exception {
// long end = System.nanoTime() + TimeUnit.SECONDS.toNanos(MAX_WAIT);
// while(puttingThread == null) {
// Thread.sleep(50);
// if(System.nanoTime() > end) {
// fail("Putting thread not set in 60 seconds");
// }
// }
//
// puttingThread.interrupt();
// return null;
// }
// });
async0.getResult();
Object value0 = checkCacheAndGetValue(vm0);
Object value1 = checkCacheAndGetValue(vm1);
assertEquals(value0, value1);
}
use of org.apache.geode.distributed.internal.DistributionMessage in project geode by apache.
the class NetSearchMessagingDUnitTest method testNetSearchFailoverFromReplicate.
/**
* Make sure that even if we start out by net searching replicates, we'll fall back to net
* searching normal members.
*/
@Test
public void testNetSearchFailoverFromReplicate() {
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);
// Install a listener to kill this member
// when we get the netsearch request
vm0.invoke(new SerializableRunnable("Install listener") {
public void run() {
DistributionMessageObserver ob = new DistributionMessageObserver() {
public void beforeProcessMessage(DistributionManager dm, DistributionMessage message) {
if (message instanceof NetSearchRequestMessage) {
disconnectFromDS();
}
}
};
DistributionMessageObserver.setInstance(ob);
}
});
createReplicate(vm0);
createNormal(vm1);
createNormal(vm2);
createEmpty(vm3);
// Test with a real value value
{
put(vm3, "a", "b");
long vm0Count = getReceivedMessages(vm0);
long vm1Count = getReceivedMessages(vm1);
long vm2Count = getReceivedMessages(vm2);
long vm3Count = getReceivedMessages(vm3);
assertEquals("b", get(vm3, "a"));
// Make sure we were disconnected in vm0
vm0.invoke(new SerializableRunnable("check disconnected") {
public void run() {
assertNull(GemFireCacheImpl.getInstance());
}
});
}
}
Aggregations