use of org.apache.geode.distributed.internal.DistributionMessageObserver 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.DistributionMessageObserver 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.DistributionMessageObserver 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.DistributionMessageObserver 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());
}
});
}
}
use of org.apache.geode.distributed.internal.DistributionMessageObserver in project geode by apache.
the class PersistentRecoveryOrderDUnitTest method testFinishIncompleteInitializationNoSend.
@Test
public void testFinishIncompleteInitializationNoSend() throws Exception {
Host host = Host.getHost(0);
VM vm0 = host.getVM(0);
VM vm1 = host.getVM(1);
// Add a hook which will disconnect the DS before sending a prepare message
vm1.invoke(new SerializableRunnable() {
public void run() {
DistributionMessageObserver.setInstance(new DistributionMessageObserver() {
@Override
public void beforeSendMessage(DistributionManager dm, DistributionMessage message) {
if (message instanceof PrepareNewPersistentMemberMessage) {
DistributionMessageObserver.setInstance(null);
getSystem().disconnect();
}
}
@Override
public void afterProcessMessage(DistributionManager dm, DistributionMessage message) {
}
});
}
});
createPersistentRegion(vm0);
putAnEntry(vm0);
updateTheEntry(vm0);
try {
createPersistentRegion(vm1);
} catch (Exception e) {
if (!(e.getCause() instanceof DistributedSystemDisconnectedException)) {
throw e;
}
}
closeRegion(vm0);
// This wait for VM0 to come back
AsyncInvocation async1 = createPersistentRegionAsync(vm1);
waitForBlockedInitialization(vm1);
createPersistentRegion(vm0);
async1.getResult();
checkForEntry(vm1);
vm0.invoke(new SerializableRunnable("check for offline members") {
public void run() {
Cache cache = getCache();
DistributedRegion region = (DistributedRegion) cache.getRegion(REGION_NAME);
PersistentMembershipView view = region.getPersistenceAdvisor().getMembershipView();
DiskRegion dr = region.getDiskRegion();
assertEquals(Collections.emptySet(), dr.getOfflineMembers());
assertEquals(1, dr.getOnlineMembers().size());
}
});
}
Aggregations