Search in sources :

Example 31 with Message

use of org.jgroups.Message in project JGroups by belaban.

the class MessageBatchTest method testAddNoResize.

public void testAddNoResize() {
    MessageBatch batch = new MessageBatch(3);
    List<Message> msgs = createMessages();
    for (int i = 0; i < 3; i++) batch.add(msgs.get(i));
    assert batch.size() == 3;
    assert batch.capacity() == 3;
    int added = batch.add(msgs.get(3), false);
    assert added == 0 && batch.size() == 3 && batch.capacity() == 3;
}
Also used : MessageBatch(org.jgroups.util.MessageBatch) Message(org.jgroups.Message)

Example 32 with Message

use of org.jgroups.Message in project JGroups by belaban.

the class MessageBatchTest method testIterator7.

public void testIterator7() {
    List<Message> msgs = createMessages();
    MessageBatch batch = new MessageBatch(msgs);
    int index = 0;
    final Message MSG = new Message();
    for (Message msg : batch) {
        if (index % 2 == 0)
            batch.replace(msg, MSG);
        index++;
    }
    index = 0;
    for (Message msg : batch) {
        // every even index has MSG
        assert index % 2 != 0 || msg == MSG;
        index++;
    }
}
Also used : MessageBatch(org.jgroups.util.MessageBatch) Message(org.jgroups.Message)

Example 33 with Message

use of org.jgroups.Message in project JGroups by belaban.

the class MessageBatchTest method testCreationWithFilter2.

public void testCreationWithFilter2() {
    List<Message> msgs = new ArrayList<>(20);
    for (int i = 1; i <= 20; i++) {
        Message msg = new Message(null, i);
        if (i <= 10) {
            msg.setFlag(Message.Flag.OOB);
            if (i % 2 == 0)
                msg.setTransientFlag(Message.TransientFlag.OOB_DELIVERED);
        }
        msgs.add(msg);
    }
    Predicate<Message> filter = msg -> msg != null && (!msg.isFlagSet(Message.Flag.OOB) || msg.setTransientFlagIfAbsent(Message.TransientFlag.OOB_DELIVERED));
    MessageBatch batch = new MessageBatch(null, null, null, true, msgs, filter);
    System.out.println("batch = " + batch.map(print_numbers));
    assert batch.size() == 15;
    for (Message msg : batch) {
        int num = msg.getObject();
        assert num > 10 || msg.isTransientFlagSet(Message.TransientFlag.OOB_DELIVERED);
    }
}
Also used : MessageBatch(org.jgroups.util.MessageBatch) DataInputStream(java.io.DataInputStream) java.util(java.util) Util(org.jgroups.util.Util) ByteArrayOutputStream(java.io.ByteArrayOutputStream) Predicate(java.util.function.Predicate) BiFunction(java.util.function.BiFunction) Test(org.testng.annotations.Test) LinkedBlockingQueue(java.util.concurrent.LinkedBlockingQueue) Collectors(java.util.stream.Collectors) Message(org.jgroups.Message) ByteArrayInputStream(java.io.ByteArrayInputStream) DataOutputStream(java.io.DataOutputStream) Global(org.jgroups.Global) ClassConfigurator(org.jgroups.conf.ClassConfigurator) Address(org.jgroups.Address) org.jgroups.protocols(org.jgroups.protocols) MessageBatch(org.jgroups.util.MessageBatch) Message(org.jgroups.Message)

Example 34 with Message

use of org.jgroups.Message in project JGroups by belaban.

the class MessageBatchTest method testReplace3.

public void testReplace3() {
    MessageBatch batch = new MessageBatch(1).add(new Message(null, "Bela")).add(new Message(null, "Michi")).add(new Message(null, "Nicole"));
    System.out.println("batch = " + batch);
    for (Message msg : batch) {
        if ("Michi".equals(msg.getObject())) {
            msg.setObject("Michelle");
            // tests replacing the message with itself (with changed buffer though)
            batch.replace(msg, msg);
        }
    }
    Queue<String> names = new LinkedBlockingQueue<>(Arrays.asList("Bela", "Michelle", "Nicole"));
    for (Message msg : batch) {
        String expected = names.poll();
        String name = msg.getObject();
        System.out.println("found=" + name + ", expected=" + expected);
        assert name.equals(expected) : "found=" + name + ", expected=" + expected;
    }
}
Also used : MessageBatch(org.jgroups.util.MessageBatch) Message(org.jgroups.Message) LinkedBlockingQueue(java.util.concurrent.LinkedBlockingQueue)

Example 35 with Message

use of org.jgroups.Message in project JGroups by belaban.

the class MessageBatchTest method testForEach.

public void testForEach() {
    MessageBatch batch = new MessageBatch(10);
    for (int i = 0; i < 10; i++) batch.add(new Message(a, i));
    System.out.println("batch = " + batch);
    assert batch.size() == 10;
    batch.remove(msg -> {
        // removes all msgs with even-numbered payloads
        int num = msg.getObject();
        return num % 2 == 0;
    });
    System.out.println("batch = " + batch);
    assert batch.size() == 5;
}
Also used : MessageBatch(org.jgroups.util.MessageBatch) Message(org.jgroups.Message)

Aggregations

Message (org.jgroups.Message)246 Address (org.jgroups.Address)50 MessageBatch (org.jgroups.util.MessageBatch)37 BytesMessage (org.jgroups.BytesMessage)31 NioMessage (org.jgroups.NioMessage)14 ObjectMessage (org.jgroups.ObjectMessage)14 EmptyMessage (org.jgroups.EmptyMessage)12 Test (org.testng.annotations.Test)12 Event (org.jgroups.Event)11 ToaHeader (org.jgroups.protocols.tom.ToaHeader)11 Test (org.junit.Test)11 IOException (java.io.IOException)8 JChannel (org.jgroups.JChannel)8 MessageID (org.jgroups.protocols.tom.MessageID)8 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 TimeoutException (java.util.concurrent.TimeoutException)6 Collectors (java.util.stream.Collectors)6 MembershipTest (org.apache.geode.test.junit.categories.MembershipTest)6