use of org.apache.geode.distributed.internal.DistributionManager in project geode by apache.
the class RemoteFetchEntryMessageTest method shouldBeMockable.
@Test
public void shouldBeMockable() throws Exception {
RemoteFetchEntryMessage mockRemoteFetchEntryMessage = mock(RemoteFetchEntryMessage.class);
DistributionManager mockDistributionManager = mock(DistributionManager.class);
LocalRegion mockLocalRegion = mock(LocalRegion.class);
long startTime = System.currentTimeMillis();
when(mockRemoteFetchEntryMessage.operateOnRegion(eq(mockDistributionManager), eq(mockLocalRegion), eq(startTime))).thenReturn(true);
assertThat(mockRemoteFetchEntryMessage.operateOnRegion(mockDistributionManager, mockLocalRegion, startTime)).isTrue();
}
use of org.apache.geode.distributed.internal.DistributionManager 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.distributed.internal.DistributionManager 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");
}
use of org.apache.geode.distributed.internal.DistributionManager in project geode by apache.
the class RemoveBucketMessageTest method shouldBeMockable.
@Test
public void shouldBeMockable() throws Exception {
RemoveBucketMessage mockRemoveBucketMessage = mock(RemoveBucketMessage.class);
DistributionManager mockDistributionManager = mock(DistributionManager.class);
PartitionedRegion mockPartitionedRegion = mock(PartitionedRegion.class);
long startTime = System.currentTimeMillis();
Object key = new Object();
when(mockRemoveBucketMessage.operateOnPartitionedRegion(eq(mockDistributionManager), eq(mockPartitionedRegion), eq(startTime))).thenReturn(true);
assertThat(mockRemoveBucketMessage.operateOnPartitionedRegion(mockDistributionManager, mockPartitionedRegion, startTime)).isTrue();
}
use of org.apache.geode.distributed.internal.DistributionManager in project geode by apache.
the class OutOfOffHeapMemoryDUnitTest method testSimpleOutOfOffHeapMemoryMemberDisconnects.
@Test
public void testSimpleOutOfOffHeapMemoryMemberDisconnects() {
final DistributedSystem system = getSystem();
final Cache cache = getCache();
final DistributionManager dm = (DistributionManager) ((InternalDistributedSystem) system).getDistributionManager();
Region<Object, Object> region = cache.createRegionFactory(getRegionShortcut()).setOffHeap(true).create(getRegionName());
OutOfOffHeapMemoryException ooohme;
try {
Object value = new byte[1024];
for (int i = 0; true; i++) {
region.put("key-" + i, value);
}
} catch (OutOfOffHeapMemoryException e) {
ooohme = e;
}
assertNotNull(ooohme);
with().pollInterval(100, TimeUnit.MILLISECONDS).await().atMost(10, TimeUnit.SECONDS).until(() -> cache.isClosed() && !system.isConnected() && dm.isClosed());
// wait for cache instance to be nulled out
with().pollInterval(100, TimeUnit.MILLISECONDS).await().atMost(10, TimeUnit.SECONDS).until(() -> GemFireCacheImpl.getInstance() == null && InternalDistributedSystem.getAnyInstance() == null);
assertNull(GemFireCacheImpl.getInstance());
// verify system was closed out due to OutOfOffHeapMemoryException
assertFalse(system.isConnected());
InternalDistributedSystem ids = (InternalDistributedSystem) system;
try {
ids.getDistributionManager();
fail("InternalDistributedSystem.getDistributionManager() should throw DistributedSystemDisconnectedException");
} catch (DistributedSystemDisconnectedException expected) {
assertRootCause(expected, OutOfOffHeapMemoryException.class);
}
// verify dm was closed out due to OutOfOffHeapMemoryException
assertTrue(dm.isClosed());
try {
dm.throwIfDistributionStopped();
fail("DistributionManager.throwIfDistributionStopped() should throw DistributedSystemDisconnectedException");
} catch (DistributedSystemDisconnectedException expected) {
assertRootCause(expected, OutOfOffHeapMemoryException.class);
}
// verify cache was closed out due to OutOfOffHeapMemoryException
assertTrue(cache.isClosed());
try {
cache.getCancelCriterion().checkCancelInProgress(null);
fail("GemFireCacheImpl.getCancelCriterion().checkCancelInProgress should throw DistributedSystemDisconnectedException");
} catch (DistributedSystemDisconnectedException expected) {
assertRootCause(expected, OutOfOffHeapMemoryException.class);
}
}
Aggregations