use of org.apache.geode.ForcedDisconnectException in project geode by apache.
the class JGroupsMessengerJUnitTest method testChannelClosedOnEmergencyClose.
@Test
public void testChannelClosedOnEmergencyClose() throws Exception {
initMocks(false);
doCallRealMethod().when(services).setShutdownCause(any(ForcedDisconnectException.class));
doCallRealMethod().when(services).getShutdownCause();
doCallRealMethod().when(services).emergencyClose();
doReturn(false).when(services).isShutdownDueToForcedDisconnect();
doReturn(false).when(services).isAutoReconnectEnabled();
doReturn(false).when(manager).isReconnectingDS();
services.setShutdownCause(new ForcedDisconnectException("Test Forced Disconnect"));
assertTrue(messenger.myChannel.isConnected());
messenger.emergencyClose();
assertFalse(messenger.myChannel.isConnected());
}
use of org.apache.geode.ForcedDisconnectException in project geode by apache.
the class JGroupsMessengerJUnitTest method testJChannelErrorDuringDisconnect.
@Test
public void testJChannelErrorDuringDisconnect() throws Exception {
for (int i = 0; i < 4; i++) {
System.out.println("loop #" + i);
boolean enableMcast = (i % 2 == 1);
initMocks(enableMcast);
JChannel mockChannel = mock(JChannel.class);
when(mockChannel.isConnected()).thenReturn(true);
Exception ex, shutdownCause;
if (i < 2) {
ex = new RuntimeException("");
shutdownCause = new RuntimeException("shutdownCause");
} else {
shutdownCause = new ForcedDisconnectException("");
ex = new RuntimeException("", shutdownCause);
}
doThrow(ex).when(mockChannel).send(any(Message.class));
JChannel realChannel = messenger.myChannel;
messenger.myChannel = mockChannel;
when(services.getShutdownCause()).thenReturn(shutdownCause);
try {
InternalDistributedMember mbr = createAddress(8888);
DistributedCacheOperation.CacheOperationMessage msg = mock(DistributedCacheOperation.CacheOperationMessage.class);
when(msg.getRecipients()).thenReturn(new InternalDistributedMember[] { mbr });
when(msg.getMulticast()).thenReturn(enableMcast);
when(msg.getProcessorId()).thenReturn(1234);
when(msg.getDSFID()).thenReturn((int) DataSerializableFixedID.PUT_ALL_MESSAGE);
try {
messenger.send(msg);
fail("expected a failure");
} catch (DistributedSystemDisconnectedException e) {
// the ultimate cause should be the shutdownCause returned
// by Services.getShutdownCause()
Throwable cause = e;
while (cause.getCause() != null) {
cause = cause.getCause();
}
assertTrue(cause != e);
assertTrue(cause == shutdownCause);
}
verify(mockChannel).send(isA(Message.class));
} finally {
messenger.myChannel = realChannel;
}
}
}
use of org.apache.geode.ForcedDisconnectException in project geode by apache.
the class JGroupsMessengerJUnitTest method testChannelClosedAfterEmergencyCloseNotForcedDisconnectWithAutoReconnect.
@Test
public void testChannelClosedAfterEmergencyCloseNotForcedDisconnectWithAutoReconnect() throws Exception {
initMocks(false);
doCallRealMethod().when(services).setShutdownCause(any(ForcedDisconnectException.class));
doCallRealMethod().when(services).getShutdownCause();
doCallRealMethod().when(services).emergencyClose();
doReturn(false).when(services).isShutdownDueToForcedDisconnect();
doReturn(true).when(services).isAutoReconnectEnabled();
doReturn(false).when(manager).isReconnectingDS();
services.setShutdownCause(new ForcedDisconnectException("Test Forced Disconnect"));
assertTrue(messenger.myChannel.isConnected());
messenger.emergencyClose();
assertFalse(messenger.myChannel.isConnected());
}
use of org.apache.geode.ForcedDisconnectException in project geode by apache.
the class JGroupsMessengerJUnitTest method testChannelClosedOnStop.
@Test
public void testChannelClosedOnStop() throws Exception {
initMocks(false);
doCallRealMethod().when(services).setShutdownCause(any(ForcedDisconnectException.class));
doCallRealMethod().when(services).getShutdownCause();
doCallRealMethod().when(services).emergencyClose();
doReturn(false).when(services).isShutdownDueToForcedDisconnect();
doReturn(false).when(services).isAutoReconnectEnabled();
doReturn(false).when(manager).isReconnectingDS();
services.setShutdownCause(new ForcedDisconnectException("Test Forced Disconnect"));
assertTrue(messenger.myChannel.isConnected());
messenger.stop();
assertFalse(messenger.myChannel.isConnected());
}
use of org.apache.geode.ForcedDisconnectException in project geode by apache.
the class JGroupsMessengerJUnitTest method testChannelStillConnectedAfteremergencyWhileReconnectingDS.
@Test
public void testChannelStillConnectedAfteremergencyWhileReconnectingDS() throws Exception {
initMocks(false);
doCallRealMethod().when(services).setShutdownCause(any(ForcedDisconnectException.class));
doCallRealMethod().when(services).getShutdownCause();
doCallRealMethod().when(services).emergencyClose();
doReturn(false).when(services).isShutdownDueToForcedDisconnect();
doReturn(false).when(services).isAutoReconnectEnabled();
doReturn(true).when(manager).isReconnectingDS();
services.setShutdownCause(new ForcedDisconnectException("Test Forced Disconnect"));
assertTrue(messenger.myChannel.isConnected());
messenger.emergencyClose();
assertTrue(messenger.myChannel.isConnected());
}
Aggregations