Search in sources :

Example 11 with ForcedDisconnectException

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());
}
Also used : ForcedDisconnectException(org.apache.geode.ForcedDisconnectException) Test(org.junit.Test) MembershipTest(org.apache.geode.test.junit.categories.MembershipTest) IntegrationTest(org.apache.geode.test.junit.categories.IntegrationTest)

Example 12 with ForcedDisconnectException

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;
        }
    }
}
Also used : JChannel(org.jgroups.JChannel) DistributedCacheOperation(org.apache.geode.internal.cache.DistributedCacheOperation) DistributedSystemDisconnectedException(org.apache.geode.distributed.DistributedSystemDisconnectedException) DistributionMessage(org.apache.geode.distributed.internal.DistributionMessage) JoinRequestMessage(org.apache.geode.distributed.internal.membership.gms.messages.JoinRequestMessage) LeaveRequestMessage(org.apache.geode.distributed.internal.membership.gms.messages.LeaveRequestMessage) InstallViewMessage(org.apache.geode.distributed.internal.membership.gms.messages.InstallViewMessage) JoinResponseMessage(org.apache.geode.distributed.internal.membership.gms.messages.JoinResponseMessage) SerialAckedMessage(org.apache.geode.distributed.internal.SerialAckedMessage) Message(org.jgroups.Message) InternalDistributedMember(org.apache.geode.distributed.internal.membership.InternalDistributedMember) ForcedDisconnectException(org.apache.geode.ForcedDisconnectException) DistributedSystemDisconnectedException(org.apache.geode.distributed.DistributedSystemDisconnectedException) SerializationException(org.apache.commons.lang.SerializationException) ForcedDisconnectException(org.apache.geode.ForcedDisconnectException) GemFireIOException(org.apache.geode.GemFireIOException) IOException(java.io.IOException) Test(org.junit.Test) MembershipTest(org.apache.geode.test.junit.categories.MembershipTest) IntegrationTest(org.apache.geode.test.junit.categories.IntegrationTest)

Example 13 with ForcedDisconnectException

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());
}
Also used : ForcedDisconnectException(org.apache.geode.ForcedDisconnectException) Test(org.junit.Test) MembershipTest(org.apache.geode.test.junit.categories.MembershipTest) IntegrationTest(org.apache.geode.test.junit.categories.IntegrationTest)

Example 14 with ForcedDisconnectException

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());
}
Also used : ForcedDisconnectException(org.apache.geode.ForcedDisconnectException) Test(org.junit.Test) MembershipTest(org.apache.geode.test.junit.categories.MembershipTest) IntegrationTest(org.apache.geode.test.junit.categories.IntegrationTest)

Example 15 with ForcedDisconnectException

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());
}
Also used : ForcedDisconnectException(org.apache.geode.ForcedDisconnectException) Test(org.junit.Test) MembershipTest(org.apache.geode.test.junit.categories.MembershipTest) IntegrationTest(org.apache.geode.test.junit.categories.IntegrationTest)

Aggregations

ForcedDisconnectException (org.apache.geode.ForcedDisconnectException)15 MembershipTest (org.apache.geode.test.junit.categories.MembershipTest)12 Test (org.junit.Test)12 IntegrationTest (org.apache.geode.test.junit.categories.IntegrationTest)11 IOException (java.io.IOException)4 DistributedSystemDisconnectedException (org.apache.geode.distributed.DistributedSystemDisconnectedException)3 InternalDistributedMember (org.apache.geode.distributed.internal.membership.InternalDistributedMember)3 HashSet (java.util.HashSet)2 CancelException (org.apache.geode.CancelException)2 GemFireConfigException (org.apache.geode.GemFireConfigException)2 GemFireIOException (org.apache.geode.GemFireIOException)2 SystemConnectException (org.apache.geode.SystemConnectException)2 DistributionMessage (org.apache.geode.distributed.internal.DistributionMessage)2 InternalLocator (org.apache.geode.distributed.internal.InternalLocator)2 JoinRequestMessage (org.apache.geode.distributed.internal.membership.gms.messages.JoinRequestMessage)2 JoinResponseMessage (org.apache.geode.distributed.internal.membership.gms.messages.JoinResponseMessage)2 MemberShunnedException (org.apache.geode.internal.tcp.MemberShunnedException)2 Message (org.jgroups.Message)2 Int2ObjectOpenHashMap (it.unimi.dsi.fastutil.ints.Int2ObjectOpenHashMap)1 File (java.io.File)1