use of org.apache.geode.distributed.internal.membership.gms.messenger.JGroupsMessenger.JGroupsReceiver 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;
}
}
use of org.apache.geode.distributed.internal.membership.gms.messenger.JGroupsMessenger.JGroupsReceiver 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()));
}
Aggregations