use of org.apache.geode.distributed.internal.DistributionMessage 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.distributed.internal.DistributionMessage in project geode by apache.
the class InterruptClientServerDUnitTest method testClientPutWithInterrupt.
/**
* A simple test case that we are actually persisting with a PR.
*
* @throws Throwable
*/
@Test
public void testClientPutWithInterrupt() throws Throwable {
IgnoredException.addIgnoredException("InterruptedException");
Host host = Host.getHost(0);
final VM vm0 = host.getVM(0);
VM vm1 = host.getVM(1);
final VM vm2 = host.getVM(2);
int port = AvailablePortHelper.getRandomAvailableTCPPort();
createRegionAndServer(vm0, port);
// 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)) {
vm2.invoke(interruptTask);
DistributionMessageObserver.setInstance(null);
}
}
});
return null;
}
});
createRegion(vm1);
createClientRegion(vm2, port);
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 = vm2.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 testNetSearchFailoverFromOneReplicateToAnother.
@Test
public void testNetSearchFailoverFromOneReplicateToAnother() {
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);
createReplicate(vm1);
createEmpty(vm3);
// Test with a real value value
{
put(vm3, "a", "b");
boolean disconnected = false;
while (!disconnected) {
assertEquals("b", get(vm3, "a"));
// Make sure we were disconnected in vm0
disconnected = (Boolean) vm0.invoke(new SerializableCallable("check disconnected") {
public Object call() {
return GemFireCacheImpl.getInstance() == null;
}
});
}
}
}
use of org.apache.geode.distributed.internal.DistributionMessage in project geode by apache.
the class ClientsWithVersioningRetryDUnitTest method testRetryPutAll.
/**
* Test that we can successfully retry a distributed put all and get the version information. bug
* #45059
*/
@Test
public void testRetryPutAll() {
Host host = Host.getHost(0);
final VM vm0 = host.getVM(0);
final VM vm1 = host.getVM(1);
final VM vm2 = host.getVM(2);
final VM vm3 = host.getVM(3);
createServerRegion(vm0, RegionShortcut.PARTITION_REDUNDANT_PERSISTENT);
vm0.invoke(new SerializableRunnable() {
@Override
public void run() {
// Make sure the bucket 0 is primary in this member.
Region region = getCache().getRegion("region");
region.put(0, "value");
// Add a listener to close vm1 when we send a distributed put all operation
// this will cause a retry after we have applied the original put all to
// the cache, causing a retry
DistributionMessageObserver.setInstance(new DistributionMessageObserver() {
@Override
public void beforeSendMessage(DistributionManager dm, DistributionMessage msg) {
if (msg instanceof DistributedPutAllOperation.PutAllMessage) {
DistributionMessageObserver.setInstance(null);
disconnectFromDS(vm1);
}
}
});
}
});
int port1 = createServerRegion(vm1, RegionShortcut.PARTITION_REDUNDANT_PERSISTENT);
int port2 = createServerRegion(vm2, RegionShortcut.PARTITION_REDUNDANT_PERSISTENT);
createClientRegion(vm3, port1, port2);
// This will be a put all to bucket 0
// Here's the expected sequence
// client->vm1 (accessor0)
// vm1->vm0
// vm0 will kill vm1
// vm0->vm2
// client will retry the putall
vm3.invoke(new SerializableCallable() {
public Object call() throws Exception {
Region region = getCache().getRegion("region");
Map map = new HashMap();
map.put(0, "a");
map.put(113, "b");
region.putAll(map);
RegionEntry entry = ((LocalRegion) region).getRegionEntry(0);
assertNotNull(entry);
assertNotNull(entry.getVersionStamp());
assertEquals(2, entry.getVersionStamp().getEntryVersion());
return null;
}
});
// Verify the observer was triggered
vm0.invoke(new SerializableRunnable() {
@Override
public void run() {
// if the observer was triggered, it would have cleared itself
assertNull(DistributionMessageObserver.getInstance());
}
});
// Make sure vm1 did in fact shut down
vm1.invoke(new SerializableRunnable() {
@Override
public void run() {
GemFireCacheImpl cache = GemFireCacheImpl.getInstance();
assertTrue(cache == null || cache.isClosed());
}
});
}
use of org.apache.geode.distributed.internal.DistributionMessage in project geode by apache.
the class ClientsWithVersioningRetryDUnitTest method testRetryPutAllInAccessor.
/**
* Test that we can successfully retry a distributed putAll on an accessor and get the version
* information. bug #48205
*/
@Test
public void testRetryPutAllInAccessor() {
Host host = Host.getHost(0);
final VM vm0 = host.getVM(0);
final VM vm1 = host.getVM(1);
final VM vm2 = host.getVM(2);
final VM vm3 = host.getVM(3);
LogWriterUtils.getLogWriter().info("creating region in vm0");
createRegionInPeer(vm0, RegionShortcut.PARTITION_REDUNDANT_PERSISTENT);
vm0.invoke(new SerializableRunnable() {
@Override
public void run() {
// Make sure the bucket 0 is primary in this member.
Region region = getCache().getRegion("region");
region.put(0, "value");
}
});
LogWriterUtils.getLogWriter().info("creating region in vm1");
createRegionInPeer(vm1, RegionShortcut.PARTITION_REDUNDANT_PERSISTENT);
LogWriterUtils.getLogWriter().info("creating region in vm2");
createRegionInPeer(vm2, RegionShortcut.PARTITION_REDUNDANT_PERSISTENT);
LogWriterUtils.getLogWriter().info("creating region in vm3");
createRegionInPeer(vm3, RegionShortcut.PARTITION_PROXY);
expectedExceptions.add(IgnoredException.addIgnoredException("RuntimeException", vm2));
vm2.invoke(new SerializableRunnable("install message listener to ignore update") {
public void run() {
// Add a listener to close vm2 when we send a distributed put all operation
// this will cause a retry after we have applied the original put all to
// the cache, causing a retry
DistributionMessageObserver.setInstance(new DistributionMessageObserver() {
@Override
public void beforeProcessMessage(DistributionManager dm, DistributionMessage msg) {
if (msg instanceof DistributedPutAllOperation.PutAllMessage) {
DistributionMessageObserver.setInstance(null);
// give vm1 time to process the message that we're ignoring
Wait.pause(5000);
disconnectFromDS(vm0);
// because vm0 has been shut down
throw new RuntimeException("test code is ignoring message: " + msg);
}
}
});
}
});
// This will be a put all to bucket 0
// Here's the expected sequence
// accessor->vm0 (primary)
// vm0->vm1, vm2
// vm2 will ignore the message & kill vm0
// accessor->vm2 or vm1
// version tag is recovered and put in the event & cache
vm3.invoke(new SerializableCallable("perform putAll in accessor") {
public Object call() throws Exception {
Region region = getCache().getRegion("region");
Map map = new HashMap();
map.put(0, "a");
map.put(113, "b");
region.putAll(map);
return null;
}
});
// verify that the version is correct
vm1.invoke(new SerializableRunnable("verify vm1") {
@Override
public void run() {
// if the observer was triggered, it would have cleared itself
assertNull(DistributionMessageObserver.getInstance());
Region region = getCache().getRegion("region");
VersionTag tag = ((LocalRegion) region).getVersionTag(0);
assertEquals(2, tag.getEntryVersion());
}
});
// Verify the observer was triggered and the version is correct
vm2.invoke(new SerializableRunnable("verify vm2") {
@Override
public void run() {
// if the observer was triggered, it would have cleared itself
assertNull(DistributionMessageObserver.getInstance());
Region region = getCache().getRegion("region");
VersionTag tag = ((LocalRegion) region).getVersionTag(0);
assertEquals(2, tag.getEntryVersion());
}
});
// Make sure vm1 did in fact shut down
vm0.invoke(new SerializableRunnable() {
@Override
public void run() {
GemFireCacheImpl cache = GemFireCacheImpl.getInstance();
assertTrue(cache == null || cache.isClosed());
}
});
}
Aggregations