use of org.jgroups.Message in project geode by apache.
the class GMSPingPonger method createJGMessage.
private Message createJGMessage(byte[] msgBytes, Address src, Address dest, short version) {
Message msg = new Message();
msg.setDest(dest);
msg.setSrc(src);
msg.setObject(msgBytes);
msg.setFlag(Message.Flag.NO_RELIABILITY);
msg.setFlag(Message.Flag.NO_FC);
msg.setFlag(Message.Flag.DONT_BUNDLE);
msg.setFlag(Message.Flag.OOB);
return msg;
}
use of org.jgroups.Message in project geode by apache.
the class InterceptUDP method handleMessage.
private void handleMessage(Message msg) {
if (collectMessages) {
collectedMessages.add(msg);
}
Object o = msg.getHeader(nakackHeaderId);
if (o != null) {
mcastSentDataMessages++;
} else {
o = msg.getHeader(unicastHeaderId);
if (o != null) {
UNICAST3.Header hdr = (UNICAST3.Header) o;
switch(hdr.type()) {
case UNICAST3.Header.DATA:
unicastSentDataMessages++;
Message response = new Message(uuid, msg.getDest(), null);
response.putHeader(unicastHeaderId, UNICAST3.Header.createAckHeader(hdr.seqno(), hdr.connId(), System.currentTimeMillis()));
up_prot.up(new Event(Event.MSG, response));
break;
}
}
}
}
use of org.jgroups.Message in project geode by apache.
the class JGroupsMessengerJUnitTest method doTestMessageDeliveredToHandler.
private void doTestMessageDeliveredToHandler(boolean mcast) throws Exception {
initMocks(mcast);
MessageHandler mh = mock(MessageHandler.class);
messenger.addHandler(JoinRequestMessage.class, mh);
InternalDistributedMember addr = messenger.getMemberID();
NetView v = new NetView(addr);
when(joinLeave.getView()).thenReturn(v);
InternalDistributedMember sender = createAddress(8888);
JoinRequestMessage msg = new JoinRequestMessage(messenger.localAddress, sender, null, -1, 0);
Message jmsg = messenger.createJGMessage(msg, messenger.jgAddress, Version.CURRENT_ORDINAL);
interceptor.up(new Event(Event.MSG, jmsg));
verify(mh, times(1)).processMessage(any(JoinRequestMessage.class));
LeaveRequestMessage lmsg = new LeaveRequestMessage(messenger.localAddress, sender, "testing");
when(joinLeave.getMemberID(any())).thenReturn(sender);
jmsg = messenger.createJGMessage(lmsg, messenger.jgAddress, Version.CURRENT_ORDINAL);
interceptor.up(new Event(Event.MSG, jmsg));
verify(manager).processMessage(any(LeaveRequestMessage.class));
}
use of org.jgroups.Message in project geode by apache.
the class JGroupsMessengerJUnitTest method testPingPong.
@Test
public void testPingPong() throws Exception {
initMocks(false);
GMSPingPonger pinger = messenger.getPingPonger();
InternalDistributedMember mbr = createAddress(8888);
JGAddress addr = new JGAddress(mbr);
Message pingMessage = pinger.createPingMessage(null, addr);
assertTrue(pinger.isPingMessage(pingMessage.getBuffer()));
assertFalse(pinger.isPongMessage(pingMessage.getBuffer()));
Message pongMessage = pinger.createPongMessage(null, addr);
assertTrue(pinger.isPongMessage(pongMessage.getBuffer()));
assertFalse(pinger.isPingMessage(pongMessage.getBuffer()));
interceptor.collectMessages = true;
pinger.sendPingMessage(messenger.myChannel, null, addr);
assertEquals("expected 1 message but found " + interceptor.collectedMessages, interceptor.collectedMessages.size(), 1);
pingMessage = interceptor.collectedMessages.get(0);
assertTrue(pinger.isPingMessage(pingMessage.getBuffer()));
interceptor.collectedMessages.clear();
pinger.sendPongMessage(messenger.myChannel, null, addr);
assertEquals("expected 1 message but found " + interceptor.collectedMessages, interceptor.collectedMessages.size(), 1);
pongMessage = interceptor.collectedMessages.get(0);
assertTrue(pinger.isPongMessage(pongMessage.getBuffer()));
interceptor.collectedMessages.clear();
JGroupsReceiver receiver = (JGroupsReceiver) messenger.myChannel.getReceiver();
long pongsReceived = messenger.pongsReceived.longValue();
receiver.receive(pongMessage);
assertEquals(pongsReceived + 1, messenger.pongsReceived.longValue());
receiver.receive(pingMessage);
assertEquals("expected 1 message but found " + interceptor.collectedMessages, interceptor.collectedMessages.size(), 1);
Message m = interceptor.collectedMessages.get(0);
assertTrue(pinger.isPongMessage(m.getBuffer()));
}
use of org.jgroups.Message in project geode by apache.
the class StatRecorderJUnitTest method testUnicastStats.
/**
* Ensure that unicast events are recorded in DMStats
*/
@Test
public void testUnicastStats() 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);
Event evt = new Event(Event.MSG, msg);
recorder.up(evt);
assertTrue("stats.ucastMessagesReceived =" + stats.ucastMessagesReceived, stats.ucastMessagesReceived == 1);
assertEquals(stats.ucastMessageBytesReceived, 150);
recorder.down(evt);
assertTrue("stats.ucastMessagesSent =" + stats.ucastMessagesSent, stats.ucastMessagesSent == 1);
assertEquals(stats.ucastMessageBytesSent, 150);
msg = mock(Message.class);
when(msg.getHeader(any(Short.class))).thenReturn(Header.createXmitReqHeader());
when(msg.size()).thenReturn(150L);
evt = new Event(Event.MSG, msg);
recorder.down(evt);
assertTrue("stats.ucastRetransmits =" + stats.ucastRetransmits, stats.ucastRetransmits == 1);
}
Aggregations