Search in sources :

Example 1 with MessageBatch

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

the class MessageBatchTest method testIteratorOnEmptyBatch.

public void testIteratorOnEmptyBatch() {
    MessageBatch batch = new MessageBatch(3);
    int count = 0;
    for (Message ignored : batch) count++;
    assert count == 0;
}
Also used : MessageBatch(org.jgroups.util.MessageBatch) Message(org.jgroups.Message)

Example 2 with MessageBatch

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

the class MessageBatchTest method testRemoveWithFilter.

public void testRemoveWithFilter() {
    Predicate<Message> filter = msg -> msg != null && msg.isTransientFlagSet(Message.TransientFlag.OOB_DELIVERED);
    MessageBatch batch = new MessageBatch(10);
    for (int i = 1; i <= 10; i++) {
        Message msg = new Message(null, i);
        if (i % 2 == 0)
            msg.setTransientFlag(Message.TransientFlag.OOB_DELIVERED);
        batch.add(msg);
    }
    System.out.println("batch = " + batch);
    assert batch.size() == 10;
    batch.remove(filter);
    System.out.println("batch = " + batch);
    assert batch.size() == 5;
    for (int i = 0; i < 5; i++) batch.add(new Message(null, i).setTransientFlag(Message.TransientFlag.OOB_DELIVERED));
    System.out.println("batch = " + batch);
    batch.replace(filter, null, false);
    assert batch.size() == 9;
}
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 3 with MessageBatch

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

the class MessageBatchTest method testTransfer.

public void testTransfer() {
    MessageBatch other = new MessageBatch(3);
    List<Message> msgs = createMessages();
    msgs.forEach(other::add);
    int other_size = other.size();
    MessageBatch batch = new MessageBatch(5);
    int num = batch.transferFrom(other, true);
    assert num == other_size;
    assert batch.size() == other_size;
    assert other.isEmpty();
}
Also used : MessageBatch(org.jgroups.util.MessageBatch) Message(org.jgroups.Message)

Example 4 with MessageBatch

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

the class MessageBatchTest method testIterationWithAddition2.

public void testIterationWithAddition2() {
    List<Message> msgs = createMessages();
    MessageBatch batch = new MessageBatch(msgs);
    int count = 0;
    for (Iterator<Message> it = batch.iterator(); it.hasNext(); ) {
        it.next();
        count++;
        if (count % 2 == 0)
            batch.add(new Message());
    }
    System.out.println("batch = " + batch);
    assert count == msgs.size() : "the added messages should *not* have been included";
}
Also used : MessageBatch(org.jgroups.util.MessageBatch) Message(org.jgroups.Message)

Example 5 with MessageBatch

use of org.jgroups.util.MessageBatch 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)

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