Search in sources :

Example 26 with MessageBatch

use of org.jgroups.util.MessageBatch in project JGroups by belaban.

the class MessageBatchTest method testTotalSize.

public void testTotalSize() {
    List<Message> msgs = createMessages();
    MessageBatch batch = new MessageBatch(msgs);
    long total_size = 0;
    for (Message msg : msgs) total_size += msg.size();
    System.out.println("total size=" + batch.totalSize());
    assert batch.totalSize() == total_size;
}
Also used : MessageBatch(org.jgroups.util.MessageBatch) Message(org.jgroups.Message)

Example 27 with MessageBatch

use of org.jgroups.util.MessageBatch in project JGroups by belaban.

the class MessageBatchTest method testStream.

public void testStream() {
    List<Message> msgs = createMessages();
    MessageBatch batch = new MessageBatch(msgs);
    long num_msgs = batch.stream().filter(msg -> msg.getHeader(UNICAST3_ID) != null).peek(msg -> System.out.printf("msg = %s, hdrs=%s\n", msg, msg.printHeaders())).count();
    System.out.println("num_msgs = " + num_msgs);
    assert num_msgs == 10;
    List<Message> list = batch.stream().collect(Collectors.toList());
    assert list.size() == batch.size();
    int total_size = batch.stream().map(Message::getLength).reduce(0, (l, r) -> l + r);
    assert total_size == 0;
    List<Long> msg_sizes = batch.stream().map(Message::size).collect(Collectors.toList());
    System.out.println("msg_sizes = " + msg_sizes);
    assert msg_sizes.size() == batch.stream().count();
}
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 28 with MessageBatch

use of org.jgroups.util.MessageBatch in project JGroups by belaban.

the class MessageBatchTest method testReplace2.

public void testReplace2() {
    List<Message> msgs = createMessages();
    MessageBatch batch = new MessageBatch(msgs);
    final Message MSG = new Message();
    batch.replace(MSG, null);
    // MSG was *not* found and therefore *not* nulled
    assert batch.size() == msgs.size();
    batch.replace(get(batch, 5), null);
    assert batch.size() == msgs.size() - 1;
}
Also used : MessageBatch(org.jgroups.util.MessageBatch) Message(org.jgroups.Message)

Example 29 with MessageBatch

use of org.jgroups.util.MessageBatch in project JGroups by belaban.

the class MessageBatchTest method testSize2.

public void testSize2() {
    List<Message> msgs = createMessages();
    MessageBatch batch = new MessageBatch(msgs);
    assert batch.size() == msgs.size();
    remove(batch, 2, 3, 10);
    assert batch.size() == msgs.size() - 3;
}
Also used : MessageBatch(org.jgroups.util.MessageBatch) Message(org.jgroups.Message)

Example 30 with MessageBatch

use of org.jgroups.util.MessageBatch in project JGroups by belaban.

the class MessageBatchTest method testIterator4.

public void testIterator4() {
    List<Message> msgs = createMessages();
    MessageBatch batch = new MessageBatch(msgs);
    for (Message msg : batch) {
        if (msg.getHeader(UNICAST3_ID) != null)
            batch.remove(msg);
    }
    System.out.println("batch = " + batch);
    assert batch.size() == 3;
}
Also used : MessageBatch(org.jgroups.util.MessageBatch) Message(org.jgroups.Message)

Aggregations

MessageBatch (org.jgroups.util.MessageBatch)46 Message (org.jgroups.Message)37 Util (org.jgroups.util.Util)6 LinkedBlockingQueue (java.util.concurrent.LinkedBlockingQueue)5 ClassConfigurator (org.jgroups.conf.ClassConfigurator)5 Test (org.testng.annotations.Test)5 ByteArrayInputStream (java.io.ByteArrayInputStream)4 ByteArrayOutputStream (java.io.ByteArrayOutputStream)4 DataInputStream (java.io.DataInputStream)4 DataOutputStream (java.io.DataOutputStream)4 java.util (java.util)4 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)4 BiFunction (java.util.function.BiFunction)4 Predicate (java.util.function.Predicate)4 Collectors (java.util.stream.Collectors)4 Address (org.jgroups.Address)4 Global (org.jgroups.Global)4 org.jgroups.protocols (org.jgroups.protocols)4 Collection (java.util.Collection)2 ConcurrentLinkedQueue (java.util.concurrent.ConcurrentLinkedQueue)2