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);
}
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;
}
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());
}
Aggregations