Search in sources :

Example 1 with UNICAST3

use of org.jgroups.protocols.UNICAST3 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 2 with UNICAST3

use of org.jgroups.protocols.UNICAST3 in project JGroups by belaban.

the class BecomeServerTest method createChannel.

protected JChannel createChannel(String name) throws Exception {
    JChannel ch = new JChannel(new SHARED_LOOPBACK(), new PING(), new NAKACK2().setValue("become_server_queue_size", 10), new UNICAST3(), new GMS().setValue("print_local_addr", false).setValue("join_timeout", 500));
    ch.setName(name);
    return ch;
}
Also used : SHARED_LOOPBACK(org.jgroups.protocols.SHARED_LOOPBACK) NAKACK2(org.jgroups.protocols.pbcast.NAKACK2) JChannel(org.jgroups.JChannel) PING(org.jgroups.protocols.PING) GMS(org.jgroups.protocols.pbcast.GMS) UNICAST3(org.jgroups.protocols.UNICAST3)

Example 3 with UNICAST3

use of org.jgroups.protocols.UNICAST3 in project JGroups by belaban.

the class MessageBeforeConnectedTestHelper method sendUnicast.

/**
 * Sends a unicast message up UNICAST2
 */
public void sendUnicast(JChannel ch) throws Exception {
    final Message msg = new Message(ch.getAddress(), "hello-1").src(ch.getAddress());
    // Add a UNICAST2 header
    final UNICAST3 unicast = ch.getProtocolStack().findProtocol(UNICAST3.class);
    UnicastHeader3 hdr = UnicastHeader3.createDataHeader(1, (short) 1, true);
    msg.putHeader(unicast.getId(), hdr);
    new Thread() {

        public void run() {
            unicast.down(msg);
        }
    }.start();
}
Also used : Message(org.jgroups.Message) UNICAST3(org.jgroups.protocols.UNICAST3) UnicastHeader3(org.jgroups.protocols.UnicastHeader3)

Example 4 with UNICAST3

use of org.jgroups.protocols.UNICAST3 in project fabric8 by jboss-fuse.

the class TestBase method setUp.

@Before
public void setUp() throws Exception {
    for (int i = 0; i < NUM; i++) {
        Protocol ping = createPing();
        channels[i] = new JChannel(new TCP(), ping, new NAKACK2(), new UNICAST3(), new STABLE(), new GMS());
        channels[i].setName(Character.toString((char) ('A' + i)));
        channels[i].connect(CLUSTER_NAME);
        channels[i].setReceiver(receivers[i] = new MyReceiver());
    }
}
Also used : TCP(org.jgroups.protocols.TCP) NAKACK2(org.jgroups.protocols.pbcast.NAKACK2) JChannel(org.jgroups.JChannel) STABLE(org.jgroups.protocols.pbcast.STABLE) Protocol(org.jgroups.stack.Protocol) GMS(org.jgroups.protocols.pbcast.GMS) UNICAST3(org.jgroups.protocols.UNICAST3) Before(org.junit.Before)

Example 5 with UNICAST3

use of org.jgroups.protocols.UNICAST3 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)

Aggregations

UNICAST3 (org.jgroups.protocols.UNICAST3)11 GMS (org.jgroups.protocols.pbcast.GMS)8 NAKACK2 (org.jgroups.protocols.pbcast.NAKACK2)8 JChannel (org.jgroups.JChannel)6 SHARED_LOOPBACK (org.jgroups.protocols.SHARED_LOOPBACK)5 STABLE (org.jgroups.protocols.pbcast.STABLE)5 SHARED_LOOPBACK_PING (org.jgroups.protocols.SHARED_LOOPBACK_PING)4 Message (org.jgroups.Message)3 Protocol (org.jgroups.stack.Protocol)3 ArrayList (java.util.ArrayList)2 Event (org.jgroups.Event)2 DISCARD (org.jgroups.protocols.DISCARD)2 PING (org.jgroups.protocols.PING)2 TCP (org.jgroups.protocols.TCP)2 CountDownLatch (java.util.concurrent.CountDownLatch)1 DistributionMessage (org.apache.geode.distributed.internal.DistributionMessage)1 SerialAckedMessage (org.apache.geode.distributed.internal.SerialAckedMessage)1 InternalDistributedMember (org.apache.geode.distributed.internal.membership.InternalDistributedMember)1 NetView (org.apache.geode.distributed.internal.membership.NetView)1 MessageHandler (org.apache.geode.distributed.internal.membership.gms.interfaces.MessageHandler)1