Search in sources :

Example 11 with MessageBatch

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

the class MessageBatchTest method testRemove.

public void testRemove() {
    List<Message> msgs = createMessages();
    MessageBatch batch = new MessageBatch(msgs);
    int prev_size = batch.size();
    remove(batch, 1, 4);
    System.out.println("batch = " + batch);
    assert batch.size() == prev_size - 2;
    batch.clear();
    System.out.println("batch = " + batch);
    assert batch.isEmpty();
    msgs.forEach(batch::add);
    System.out.println("batch = " + batch);
    assert batch.size() == prev_size;
    assert batch.capacity() == prev_size;
}
Also used : MessageBatch(org.jgroups.util.MessageBatch) Message(org.jgroups.Message)

Example 12 with MessageBatch

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

the class MessageBatchTest method testGetMatchingMessages.

public void testGetMatchingMessages() {
    List<Message> msgs = createMessages();
    MessageBatch batch = new MessageBatch(msgs);
    Collection<Message> matching = batch.getMatchingMessages(UDP_ID, false);
    assert matching.size() == batch.size();
    assert batch.size() == msgs.size();
    matching = batch.getMatchingMessages(FD_ID, true);
    assert matching.size() == 1;
    assert batch.size() == msgs.size() - 1;
    int size = batch.size();
    matching = batch.getMatchingMessages(UDP_ID, true);
    assert matching.size() == size;
    assert batch.isEmpty();
}
Also used : MessageBatch(org.jgroups.util.MessageBatch) Message(org.jgroups.Message)

Example 13 with MessageBatch

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

the class MessageBatchTest method testIterator8.

public void testIterator8() {
    List<Message> msgs = createMessages();
    MessageBatch batch = new MessageBatch(msgs);
    int index = 0;
    for (Iterator<Message> it = batch.iterator(); it.hasNext(); ) {
        it.next();
        if (index == 1 || index == 2 || index == 3 || index == 10 || index == msgs.size() - 1)
            it.remove();
        index++;
    }
    System.out.println("batch = " + batch);
    int count = 0;
    for (Message ignored : batch) count++;
    assert count == msgs.size() - 5;
}
Also used : MessageBatch(org.jgroups.util.MessageBatch) Message(org.jgroups.Message)

Example 14 with MessageBatch

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

the class MessageBatchTest method testIsEmpty2.

public void testIsEmpty2() {
    List<Message> msgs = createMessages();
    MessageBatch batch = new MessageBatch(msgs);
    batch.add(new Message());
    assert !batch.isEmpty();
    batch.clear();
    assert batch.isEmpty();
    msgs.forEach(batch::add);
    System.out.println("batch = " + batch);
    for (Iterator<Message> it = batch.iterator(); it.hasNext(); ) {
        it.next();
        it.remove();
    }
    System.out.println("batch = " + batch);
    assert batch.isEmpty();
}
Also used : MessageBatch(org.jgroups.util.MessageBatch) Message(org.jgroups.Message)

Example 15 with MessageBatch

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

the class MessageBatchTest method testIterator3.

/**
 * Test removal via iterator
 */
public void testIterator3() {
    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