Search in sources :

Example 21 with Message

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;
}
Also used : Message(org.jgroups.Message)

Example 22 with Message

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;
            }
        }
    }
}
Also used : Message(org.jgroups.Message) Event(org.jgroups.Event) UNICAST3(org.jgroups.protocols.UNICAST3)

Example 23 with Message

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));
}
Also used : LeaveRequestMessage(org.apache.geode.distributed.internal.membership.gms.messages.LeaveRequestMessage) MessageHandler(org.apache.geode.distributed.internal.membership.gms.interfaces.MessageHandler) 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) NetView(org.apache.geode.distributed.internal.membership.NetView) Event(org.jgroups.Event) JoinRequestMessage(org.apache.geode.distributed.internal.membership.gms.messages.JoinRequestMessage)

Example 24 with Message

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

Example 25 with Message

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);
}
Also used : Message(org.jgroups.Message) Event(org.jgroups.Event) UnitTest(org.apache.geode.test.junit.categories.UnitTest) Test(org.junit.Test) MembershipTest(org.apache.geode.test.junit.categories.MembershipTest)

Aggregations

Message (org.jgroups.Message)26 Test (org.junit.Test)11 DistributionMessage (org.apache.geode.distributed.internal.DistributionMessage)7 JoinRequestMessage (org.apache.geode.distributed.internal.membership.gms.messages.JoinRequestMessage)7 JoinResponseMessage (org.apache.geode.distributed.internal.membership.gms.messages.JoinResponseMessage)7 Event (org.jgroups.Event)7 IOException (java.io.IOException)6 MembershipTest (org.apache.geode.test.junit.categories.MembershipTest)6 SerialAckedMessage (org.apache.geode.distributed.internal.SerialAckedMessage)5 InternalDistributedMember (org.apache.geode.distributed.internal.membership.InternalDistributedMember)5 InstallViewMessage (org.apache.geode.distributed.internal.membership.gms.messages.InstallViewMessage)5 LeaveRequestMessage (org.apache.geode.distributed.internal.membership.gms.messages.LeaveRequestMessage)5 CancellationException (java.util.concurrent.CancellationException)4 ExecutionException (java.util.concurrent.ExecutionException)4 TimeoutException (java.util.concurrent.TimeoutException)4 NetView (org.apache.geode.distributed.internal.membership.NetView)4 RequestOptions (org.jgroups.blocks.RequestOptions)3 CommandDispatcherException (org.wildfly.clustering.dispatcher.CommandDispatcherException)3 InvocationTargetException (java.lang.reflect.InvocationTargetException)2 UnknownHostException (java.net.UnknownHostException)2