Search in sources :

Example 31 with MessageBatch

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

the class MessageBatchTest method testReplaceIf.

public void testReplaceIf() {
    List<Message> msgs = createMessages();
    MessageBatch batch = new MessageBatch(msgs);
    System.out.println("batch = " + batch);
    int size = batch.size();
    int removed = batch.replaceIf(msg -> msg.getHeader(UNICAST3_ID) != null, null, true);
    System.out.println("batch = " + batch);
    assert batch.size() == size - removed;
}
Also used : MessageBatch(org.jgroups.util.MessageBatch) Message(org.jgroups.Message)

Example 32 with MessageBatch

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

the class MessageBatchTest method testIterator5.

public void testIterator5() {
    List<Message> msgs = createMessages();
    MessageBatch batch = new MessageBatch(msgs);
    Iterator<Message> itr = batch.iterator();
    itr.remove();
    // didn't remove anything
    assert batch.size() == msgs.size();
    for (Iterator<Message> it = batch.iterator(); it.hasNext(); ) {
        Message msg = it.next();
        if (msg != null && msg.getHeader(UNICAST3_ID) != null)
            it.remove();
    }
    System.out.println("batch = " + batch);
    assert batch.size() == 3;
}
Also used : MessageBatch(org.jgroups.util.MessageBatch) Message(org.jgroups.Message)

Example 33 with MessageBatch

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

the class MessageBatchTest method testAddBatch2.

public void testAddBatch2() {
    MessageBatch other = new MessageBatch(3);
    List<Message> msgs = createMessages();
    msgs.forEach(other::add);
    int other_size = other.size();
    MessageBatch batch = new MessageBatch(5);
    batch.add(other);
    System.out.println("batch = " + batch);
    assert batch.size() == other_size;
    assert batch.capacity() >= other.capacity();
}
Also used : MessageBatch(org.jgroups.util.MessageBatch) Message(org.jgroups.Message)

Example 34 with MessageBatch

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

the class MessageBatchTest method testAddBatch.

public void testAddBatch() {
    MessageBatch batch = new MessageBatch(3), other = new MessageBatch(3);
    List<Message> msgs = createMessages();
    msgs.forEach(other::add);
    assert other.size() == msgs.size();
    batch.add(other);
    assert batch.size() == msgs.size() : "batch: " + batch;
    assert batch.size() == other.size();
}
Also used : MessageBatch(org.jgroups.util.MessageBatch) Message(org.jgroups.Message)

Example 35 with MessageBatch

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

the class MessageBatchTest method testSet.

public void testSet() {
    List<Message> msgs = createMessages();
    Message msg = msgs.get(5);
    MessageBatch batch = new MessageBatch(msgs);
    assert get(batch, 5) == msg;
    set(batch, 4, msg);
    assert get(batch, 4) == msg;
}
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