Search in sources :

Example 6 with Message

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

Example 7 with Message

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

Example 8 with Message

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));
}
Also used : Services(org.apache.geode.distributed.internal.membership.gms.Services) Message(org.jgroups.Message) Event(org.jgroups.Event) DistributionManager(org.apache.geode.distributed.internal.DistributionManager) Manager(org.apache.geode.distributed.internal.membership.gms.interfaces.Manager) RejectedExecutionException(java.util.concurrent.RejectedExecutionException) UnitTest(org.apache.geode.test.junit.categories.UnitTest) Test(org.junit.Test) MembershipTest(org.apache.geode.test.junit.categories.MembershipTest)

Example 9 with Message

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]);
}
Also used : MessageHandler(org.apache.geode.distributed.internal.membership.gms.interfaces.MessageHandler) 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) ArrayList(java.util.ArrayList) UNICAST3(org.jgroups.protocols.UNICAST3) InternalDistributedMember(org.apache.geode.distributed.internal.membership.InternalDistributedMember) DistributionMessage(org.apache.geode.distributed.internal.DistributionMessage) Event(org.jgroups.Event) UUID(org.jgroups.util.UUID) JoinRequestMessage(org.apache.geode.distributed.internal.membership.gms.messages.JoinRequestMessage)

Example 10 with Message

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

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