use of org.apache.geode.distributed.internal.DistributionMessageObserver 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.DistributionMessageObserver 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.DistributionMessageObserver 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());
}
});
}
use of org.apache.geode.distributed.internal.DistributionMessageObserver in project geode by apache.
the class PartitionedRegionQueryDUnitTest method testRebalanceDuringQueryEvaluation.
/**
* Test of bug 43102. 1. Buckets are created on several nodes 2. A query is started 3. While the
* query is executing, several buckets are moved.
*/
@Test
public void testRebalanceDuringQueryEvaluation() {
Host host = Host.getHost(0);
VM vm0 = host.getVM(0);
VM vm1 = host.getVM(1);
VM vm2 = host.getVM(2);
createAccessor(vm0);
createPR(vm1);
createBuckets(vm1);
createPR(vm2);
// Add a listener that will trigger a rebalance
// as soon as the query arrives on this node.
vm1.invoke(new SerializableRunnable("add listener") {
public void run() {
DistributionMessageObserver.setInstance(new DistributionMessageObserver() {
@Override
public void beforeProcessMessage(DistributionManager dm, DistributionMessage message) {
if (message instanceof QueryMessage) {
RebalanceOperation rebalance = getCache().getResourceManager().createRebalanceFactory().start();
// wait for the rebalance
try {
rebalanceResults.compareAndSet(null, rebalance.getResults());
} catch (CancellationException e) {
// ignore
} catch (InterruptedException e) {
// ignore
}
}
}
});
}
});
executeQuery(vm0);
vm1.invoke(new SerializableRunnable("check rebalance happened") {
public void run() {
assertNotNull(rebalanceResults.get());
assertEquals(5, rebalanceResults.get().getTotalBucketTransfersCompleted());
}
});
}
use of org.apache.geode.distributed.internal.DistributionMessageObserver in project geode by apache.
the class Bug41733DUnitTest method testCrashAfterBucketCreation.
/**
* Test the we can handle a member departing after creating a bucket on the remote node but before
* we choose a primary
*/
@Test
public void testCrashAfterBucketCreation() 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 beforeProcessMessage(DistributionManager dm, DistributionMessage message) {
if (message instanceof ManageBucketReplyMessage) {
disconnectFromDS();
}
}
});
}
});
createPR(vm0, 0);
// Create a couple of buckets in VM0. This will make sure
// the next bucket we create will be created in VM 1.
putData(vm0, 0, 2, "a");
createPR(vm1, 0);
// Trigger a bucket creation in VM1, which should cause vm0 to close it's cache.
try {
putData(vm0, 3, 4, "a");
fail("should have received a cache closed exception");
} catch (RMIException e) {
if (!(e.getCause() instanceof DistributedSystemDisconnectedException)) {
throw e;
}
}
assertEquals(Collections.singleton(3), getBucketList(vm1));
// This shouldn't hang, because the bucket creation should finish,.
putData(vm1, 3, 4, "a");
}
Aggregations