use of org.jgroups.Message in project geode by apache.
the class StatRecorder method up.
@Override
public Object up(Event evt) {
switch(evt.getType()) {
case Event.MSG:
Message msg = (Message) evt.getArg();
processForMulticast(msg, INCOMING);
processForUnicast(msg, INCOMING);
filter(msg, INCOMING);
}
return up_prot.up(evt);
}
use of org.jgroups.Message in project geode by apache.
the class StatRecorderJUnitTest method testMulticastStats.
/**
* ensure that multicast events are recorded in DMStats
*/
@Test
public void testMulticastStats() throws Exception {
Message msg = mock(Message.class);
when(msg.getHeader(any(Short.class))).thenReturn(NakAckHeader2.createMessageHeader(1L));
when(msg.size()).thenReturn(150L);
Event evt = new Event(Event.MSG, msg);
recorder.up(evt);
assertTrue("mcastMessagesReceived = " + stats.mcastMessagesReceived, stats.mcastMessagesReceived == 1);
assertEquals(stats.mcastMessageBytesReceived, 150);
recorder.down(evt);
assertTrue("mcastMessagesSent = " + stats.mcastMessagesSent, stats.mcastMessagesSent == 1);
assertEquals(stats.mcastMessageBytesSent, 150);
msg = mock(Message.class);
when(msg.size()).thenReturn(150L);
when(msg.getHeader(any(Short.class))).thenReturn(NakAckHeader2.createXmitRequestHeader(null));
evt = new Event(Event.MSG, msg);
recorder.down(evt);
assertTrue("mcastRetransmitRequests = " + stats.mcastRetransmitRequests, stats.mcastRetransmitRequests == 1);
msg = mock(Message.class);
when(msg.size()).thenReturn(150L);
when(msg.getHeader(any(Short.class))).thenReturn(NakAckHeader2.createXmitResponseHeader());
evt = new Event(Event.MSG, msg);
recorder.down(evt);
assertTrue("mcastRetransmits = " + stats.mcastRetransmits, stats.mcastRetransmits == 1);
}
use of org.jgroups.Message in project geode by apache.
the class StatRecorderJUnitTest method recorderHandlesRejectedExecution.
@Test
public void recorderHandlesRejectedExecution() throws Exception {
Message msg = mock(Message.class);
when(msg.getHeader(any(Short.class))).thenReturn(Header.createDataHeader(1L, (short) 1, true));
when(msg.size()).thenReturn(150L);
// GEODE-1178, the TP protocol may throw a RejectedExecutionException & StatRecorder should
// retry
when(mockDownProtocol.down(any(Event.class))).thenThrow(new RejectedExecutionException());
// after the first down() throws an exception we want StatRecorder to retry, so
// we set the Manager to say no shutdown is in progress the first time and then say
// one IS in progress so we can break out of the StatRecorder exception handling loop
when(services.getCancelCriterion()).thenReturn(new Services().getCancelCriterion());
Manager manager = mock(Manager.class);
when(services.getManager()).thenReturn(manager);
when(manager.shutdownInProgress()).thenReturn(Boolean.FALSE, Boolean.TRUE);
verify(mockDownProtocol, never()).down(isA(Event.class));
Event evt = new Event(Event.MSG, msg);
recorder.down(evt);
verify(mockDownProtocol, times(2)).down(isA(Event.class));
}
use of org.jgroups.Message in project geode by apache.
the class JGroupsMessengerJUnitTest method doTestBigMessageIsFragmented.
public void doTestBigMessageIsFragmented(boolean mcastEnabled, boolean mcastMsg) throws Exception {
initMocks(mcastEnabled);
MessageHandler mh = mock(MessageHandler.class);
messenger.addHandler(JoinRequestMessage.class, mh);
InternalDistributedMember sender = messenger.getMemberID();
NetView v = new NetView(sender);
when(joinLeave.getView()).thenReturn(v);
messenger.installView(v);
JoinRequestMessage msg = new JoinRequestMessage(messenger.localAddress, sender, null, -1, 0);
if (mcastMsg) {
msg.setMulticast(true);
}
messenger.send(msg);
int sentMessages = (mcastEnabled && mcastMsg) ? interceptor.mcastSentDataMessages : interceptor.unicastSentDataMessages;
assertTrue("expected 1 message to be sent but found " + sentMessages, sentMessages == 1);
// send a big message and expect fragmentation
msg = new JoinRequestMessage(messenger.localAddress, sender, new byte[(int) (services.getConfig().getDistributionConfig().getUdpFragmentSize() * (1.5))], -1, 0);
// configure an incoming message handler for JoinRequestMessage
final DistributionMessage[] messageReceived = new DistributionMessage[1];
MessageHandler handler = new MessageHandler() {
@Override
public void processMessage(DistributionMessage m) {
messageReceived[0] = m;
}
};
messenger.addHandler(JoinRequestMessage.class, handler);
// configure the outgoing message interceptor
interceptor.unicastSentDataMessages = 0;
interceptor.collectMessages = true;
interceptor.collectedMessages.clear();
messenger.send(msg);
assertTrue("expected 2 messages to be sent but found " + interceptor.unicastSentDataMessages, interceptor.unicastSentDataMessages == 2);
List<Message> messages = new ArrayList<>(interceptor.collectedMessages);
UUID fakeMember = new UUID(50, 50);
short unicastHeaderId = ClassConfigurator.getProtocolId(UNICAST3.class);
int seqno = 1;
for (Message m : messages) {
m.setSrc(fakeMember);
UNICAST3.Header oldHeader = (UNICAST3.Header) m.getHeader(unicastHeaderId);
if (oldHeader == null)
continue;
UNICAST3.Header newHeader = UNICAST3.Header.createDataHeader(seqno, oldHeader.connId(), seqno == 1);
seqno += 1;
m.putHeader(unicastHeaderId, newHeader);
interceptor.up(new Event(Event.MSG, m));
}
Thread.sleep(5000);
System.out.println("received message = " + messageReceived[0]);
}
use of org.jgroups.Message in project geode by apache.
the class JGroupsMessengerJUnitTest method testReceiver.
@Test
public void testReceiver() throws Exception {
try {
DistributionStats.enableClockStats = true;
initMocks(false);
JGroupsReceiver receiver = (JGroupsReceiver) messenger.myChannel.getReceiver();
// a zero-length message is ignored
Message msg = new Message(new JGAddress(messenger.getMemberID()));
Object result = messenger.readJGMessage(msg);
assertNull(result);
// for code coverage we need to pump this message through the receiver
receiver.receive(msg);
// for more code coverage we need to actually set a buffer in the message
msg.setBuffer(new byte[0]);
result = messenger.readJGMessage(msg);
assertNull(result);
receiver.receive(msg);
// now create a view and a real distribution-message
InternalDistributedMember myAddress = messenger.getMemberID();
InternalDistributedMember other = createAddress(8888);
NetView v = new NetView(myAddress);
v.add(other);
when(joinLeave.getView()).thenReturn(v);
messenger.installView(v);
List<InternalDistributedMember> recipients = v.getMembers();
SerialAckedMessage dmsg = new SerialAckedMessage();
dmsg.setRecipients(recipients);
// a message is ignored during manager shutdown
msg = messenger.createJGMessage(dmsg, new JGAddress(other), Version.CURRENT_ORDINAL);
when(manager.shutdownInProgress()).thenReturn(Boolean.TRUE);
receiver.receive(msg);
verify(manager, never()).processMessage(isA(DistributionMessage.class));
assertTrue("There should be UDPDispatchRequestTime stats", services.getStatistics().getUDPDispatchRequestTime() > 0);
} finally {
DistributionStats.enableClockStats = false;
}
}
Aggregations