Search in sources :

Example 1 with ConnectExceptions

use of org.apache.geode.internal.tcp.ConnectExceptions in project geode by apache.

the class GMSMembershipManagerJUnitTest method testDirectChannelSendFailureDueToForcedDisconnect.

@Test
public void testDirectChannelSendFailureDueToForcedDisconnect() throws Exception {
    setUpDirectChannelMock();
    HighPriorityAckedMessage m = new HighPriorityAckedMessage();
    InternalDistributedMember[] recipients = new InternalDistributedMember[] { mockMembers[2], mockMembers[3] };
    m.setRecipients(Arrays.asList(recipients));
    Set<InternalDistributedMember> failures = manager.directChannelSend(recipients, m, null);
    manager.setShutdown();
    ConnectExceptions exception = new ConnectExceptions();
    exception.addFailure(recipients[0], new Exception("testing"));
    when(dc.send(any(GMSMembershipManager.class), any(mockMembers.getClass()), any(DistributionMessage.class), anyInt(), anyInt())).thenThrow(exception);
    Assertions.assertThatThrownBy(() -> {
        manager.directChannelSend(recipients, m, null);
    }).isInstanceOf(DistributedSystemDisconnectedException.class);
}
Also used : HighPriorityAckedMessage(org.apache.geode.distributed.internal.HighPriorityAckedMessage) InternalDistributedMember(org.apache.geode.distributed.internal.membership.InternalDistributedMember) ConnectExceptions(org.apache.geode.internal.tcp.ConnectExceptions) DistributionMessage(org.apache.geode.distributed.internal.DistributionMessage) DistributedSystemDisconnectedException(org.apache.geode.distributed.DistributedSystemDisconnectedException) Test(org.junit.Test) MembershipTest(org.apache.geode.test.junit.categories.MembershipTest) IntegrationTest(org.apache.geode.test.junit.categories.IntegrationTest)

Example 2 with ConnectExceptions

use of org.apache.geode.internal.tcp.ConnectExceptions in project geode by apache.

the class GMSMembershipManager method directChannelSend.

/**
   * Perform the grossness associated with sending a message over a DirectChannel
   *
   * @param destinations the list of destinations
   * @param content the message
   * @param theStats the statistics object to update
   * @return all recipients who did not receive the message (null if all received it)
   * @throws NotSerializableException if the message is not serializable
   */
protected Set<InternalDistributedMember> directChannelSend(InternalDistributedMember[] destinations, DistributionMessage content, DMStats theStats) throws NotSerializableException {
    boolean allDestinations;
    InternalDistributedMember[] keys;
    if (content.forAll()) {
        allDestinations = true;
        latestViewReadLock.lock();
        try {
            List<InternalDistributedMember> keySet = latestView.getMembers();
            keys = new InternalDistributedMember[keySet.size()];
            keys = keySet.toArray(keys);
        } finally {
            latestViewReadLock.unlock();
        }
    } else {
        allDestinations = false;
        keys = destinations;
    }
    int sentBytes;
    try {
        sentBytes = directChannel.send(this, keys, content, this.services.getConfig().getDistributionConfig().getAckWaitThreshold(), this.services.getConfig().getDistributionConfig().getAckSevereAlertThreshold());
        if (theStats != null) {
            theStats.incSentBytes(sentBytes);
        }
        if (sentBytes == 0) {
            if (services.getCancelCriterion().isCancelInProgress()) {
                throw new DistributedSystemDisconnectedException();
            }
        }
    } catch (DistributedSystemDisconnectedException ex) {
        if (services.getShutdownCause() != null) {
            throw new DistributedSystemDisconnectedException("DistributedSystem is shutting down", services.getShutdownCause());
        } else {
            // see bug 41416
            throw ex;
        }
    } catch (ConnectExceptions ex) {
        // Check if the connect exception is due to system shutting down.
        if (shutdownInProgress()) {
            if (services.getShutdownCause() != null) {
                throw new DistributedSystemDisconnectedException("DistributedSystem is shutting down", services.getShutdownCause());
            } else {
                throw new DistributedSystemDisconnectedException();
            }
        }
        if (allDestinations)
            return null;
        // We
        List<InternalDistributedMember> members = (List<InternalDistributedMember>) ex.getMembers();
        // need
        // to
        // return
        // this
        // list
        // of
        // failures
        // SANITY CHECK: If we fail to send a message to an existing member
        // of the view, we have a serious error (bug36202).
        // grab a recent view, excluding shunned
        NetView view = services.getJoinLeave().getView();
        // members
        // Iterate through members and causes in tandem :-(
        Iterator it_mem = members.iterator();
        Iterator it_causes = ex.getCauses().iterator();
        while (it_mem.hasNext()) {
            InternalDistributedMember member = (InternalDistributedMember) it_mem.next();
            Throwable th = (Throwable) it_causes.next();
            if (!view.contains(member) || (th instanceof ShunnedMemberException)) {
                continue;
            }
            logger.fatal(LocalizedMessage.create(LocalizedStrings.GroupMembershipService_FAILED_TO_SEND_MESSAGE_0_TO_MEMBER_1_VIEW_2, new Object[] { content, member, view }), th);
        // Assert.assertTrue(false, "messaging contract failure");
        }
        return new HashSet<>(members);
    }// catch ConnectionExceptions
     catch (ToDataException | CancelException e) {
        throw e;
    } catch (IOException e) {
        if (logger.isDebugEnabled()) {
            logger.debug("Membership: directChannelSend caught exception: {}", e.getMessage(), e);
        }
        if (e instanceof NotSerializableException) {
            throw (NotSerializableException) e;
        }
    } catch (RuntimeException | Error e) {
        if (logger.isDebugEnabled()) {
            logger.debug("Membership: directChannelSend caught exception: {}", e.getMessage(), e);
        }
        throw e;
    }
    return null;
}
Also used : ShunnedMemberException(org.apache.geode.distributed.internal.direct.ShunnedMemberException) DistributedSystemDisconnectedException(org.apache.geode.distributed.DistributedSystemDisconnectedException) ConnectExceptions(org.apache.geode.internal.tcp.ConnectExceptions) NetView(org.apache.geode.distributed.internal.membership.NetView) InternalGemFireError(org.apache.geode.InternalGemFireError) IOException(java.io.IOException) NotSerializableException(java.io.NotSerializableException) InternalDistributedMember(org.apache.geode.distributed.internal.membership.InternalDistributedMember) ToDataException(org.apache.geode.ToDataException) Iterator(java.util.Iterator) List(java.util.List) ArrayList(java.util.ArrayList) LinkedList(java.util.LinkedList) CancelException(org.apache.geode.CancelException)

Example 3 with ConnectExceptions

use of org.apache.geode.internal.tcp.ConnectExceptions in project geode by apache.

the class GMSMembershipManagerJUnitTest method testDirectChannelSendFailureToOneRecipient.

@Test
public void testDirectChannelSendFailureToOneRecipient() throws Exception {
    setUpDirectChannelMock();
    HighPriorityAckedMessage m = new HighPriorityAckedMessage();
    InternalDistributedMember[] recipients = new InternalDistributedMember[] { mockMembers[2], mockMembers[3] };
    m.setRecipients(Arrays.asList(recipients));
    Set<InternalDistributedMember> failures = manager.directChannelSend(recipients, m, null);
    ConnectExceptions exception = new ConnectExceptions();
    exception.addFailure(recipients[0], new Exception("testing"));
    when(dc.send(any(GMSMembershipManager.class), any(mockMembers.getClass()), any(DistributionMessage.class), anyInt(), anyInt())).thenThrow(exception);
    failures = manager.directChannelSend(recipients, m, null);
    assertTrue(failures != null);
    assertEquals(1, failures.size());
    assertEquals(recipients[0], failures.iterator().next());
}
Also used : HighPriorityAckedMessage(org.apache.geode.distributed.internal.HighPriorityAckedMessage) InternalDistributedMember(org.apache.geode.distributed.internal.membership.InternalDistributedMember) ConnectExceptions(org.apache.geode.internal.tcp.ConnectExceptions) DistributionMessage(org.apache.geode.distributed.internal.DistributionMessage) DistributedSystemDisconnectedException(org.apache.geode.distributed.DistributedSystemDisconnectedException) Test(org.junit.Test) MembershipTest(org.apache.geode.test.junit.categories.MembershipTest) IntegrationTest(org.apache.geode.test.junit.categories.IntegrationTest)

Aggregations

DistributedSystemDisconnectedException (org.apache.geode.distributed.DistributedSystemDisconnectedException)3 InternalDistributedMember (org.apache.geode.distributed.internal.membership.InternalDistributedMember)3 ConnectExceptions (org.apache.geode.internal.tcp.ConnectExceptions)3 DistributionMessage (org.apache.geode.distributed.internal.DistributionMessage)2 HighPriorityAckedMessage (org.apache.geode.distributed.internal.HighPriorityAckedMessage)2 IntegrationTest (org.apache.geode.test.junit.categories.IntegrationTest)2 MembershipTest (org.apache.geode.test.junit.categories.MembershipTest)2 Test (org.junit.Test)2 IOException (java.io.IOException)1 NotSerializableException (java.io.NotSerializableException)1 ArrayList (java.util.ArrayList)1 Iterator (java.util.Iterator)1 LinkedList (java.util.LinkedList)1 List (java.util.List)1 CancelException (org.apache.geode.CancelException)1 InternalGemFireError (org.apache.geode.InternalGemFireError)1 ToDataException (org.apache.geode.ToDataException)1 ShunnedMemberException (org.apache.geode.distributed.internal.direct.ShunnedMemberException)1 NetView (org.apache.geode.distributed.internal.membership.NetView)1