Search in sources :

Example 1 with JGroupsReceiver

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;
    }
}
Also used : DistributionMessage(org.apache.geode.distributed.internal.DistributionMessage) JoinRequestMessage(org.apache.geode.distributed.internal.membership.gms.messages.JoinRequestMessage) LeaveRequestMessage(org.apache.geode.distributed.internal.membership.gms.messages.LeaveRequestMessage) InstallViewMessage(org.apache.geode.distributed.internal.membership.gms.messages.InstallViewMessage) JoinResponseMessage(org.apache.geode.distributed.internal.membership.gms.messages.JoinResponseMessage) SerialAckedMessage(org.apache.geode.distributed.internal.SerialAckedMessage) Message(org.jgroups.Message) InternalDistributedMember(org.apache.geode.distributed.internal.membership.InternalDistributedMember) DistributionMessage(org.apache.geode.distributed.internal.DistributionMessage) JGroupsReceiver(org.apache.geode.distributed.internal.membership.gms.messenger.JGroupsMessenger.JGroupsReceiver) NetView(org.apache.geode.distributed.internal.membership.NetView) SerialAckedMessage(org.apache.geode.distributed.internal.SerialAckedMessage) Test(org.junit.Test) MembershipTest(org.apache.geode.test.junit.categories.MembershipTest) IntegrationTest(org.apache.geode.test.junit.categories.IntegrationTest)

Example 2 with JGroupsReceiver

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()));
}
Also used : InternalDistributedMember(org.apache.geode.distributed.internal.membership.InternalDistributedMember) DistributionMessage(org.apache.geode.distributed.internal.DistributionMessage) JoinRequestMessage(org.apache.geode.distributed.internal.membership.gms.messages.JoinRequestMessage) LeaveRequestMessage(org.apache.geode.distributed.internal.membership.gms.messages.LeaveRequestMessage) InstallViewMessage(org.apache.geode.distributed.internal.membership.gms.messages.InstallViewMessage) JoinResponseMessage(org.apache.geode.distributed.internal.membership.gms.messages.JoinResponseMessage) SerialAckedMessage(org.apache.geode.distributed.internal.SerialAckedMessage) Message(org.jgroups.Message) JGroupsReceiver(org.apache.geode.distributed.internal.membership.gms.messenger.JGroupsMessenger.JGroupsReceiver) Test(org.junit.Test) MembershipTest(org.apache.geode.test.junit.categories.MembershipTest) IntegrationTest(org.apache.geode.test.junit.categories.IntegrationTest)

Aggregations

DistributionMessage (org.apache.geode.distributed.internal.DistributionMessage)2 SerialAckedMessage (org.apache.geode.distributed.internal.SerialAckedMessage)2 InternalDistributedMember (org.apache.geode.distributed.internal.membership.InternalDistributedMember)2 InstallViewMessage (org.apache.geode.distributed.internal.membership.gms.messages.InstallViewMessage)2 JoinRequestMessage (org.apache.geode.distributed.internal.membership.gms.messages.JoinRequestMessage)2 JoinResponseMessage (org.apache.geode.distributed.internal.membership.gms.messages.JoinResponseMessage)2 LeaveRequestMessage (org.apache.geode.distributed.internal.membership.gms.messages.LeaveRequestMessage)2 JGroupsReceiver (org.apache.geode.distributed.internal.membership.gms.messenger.JGroupsMessenger.JGroupsReceiver)2 IntegrationTest (org.apache.geode.test.junit.categories.IntegrationTest)2 MembershipTest (org.apache.geode.test.junit.categories.MembershipTest)2 Message (org.jgroups.Message)2 Test (org.junit.Test)2 NetView (org.apache.geode.distributed.internal.membership.NetView)1