Search in sources :

Example 36 with MessageBatch

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

the class MessageBatchTest method testReplaceDuplicates.

public void testReplaceDuplicates() {
    final Set<Integer> dupes = new HashSet<>(5);
    Predicate<Message> filter = (msg) -> {
        Integer num = msg.getObject();
        return dupes.add(num) == false;
    };
    MessageBatch batch = new MessageBatch(10);
    for (int j = 0; j < 2; j++) for (int i = 1; i <= 5; i++) batch.add(new Message(null, i));
    System.out.println(batch.map(print_numbers));
    assert batch.size() == 10;
    batch.replace(filter, null, true);
    assert batch.size() == 5;
    System.out.println(batch.map(print_numbers));
}
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 37 with MessageBatch

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

the class MessageBatchTest method testTransfer2.

public void testTransfer2() {
    MessageBatch other = new MessageBatch(3);
    List<Message> msgs = createMessages();
    msgs.forEach(other::add);
    int other_size = other.size();
    MessageBatch batch = new MessageBatch(5);
    msgs.forEach(batch::add);
    msgs.forEach(batch::add);
    System.out.println("batch = " + batch);
    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 38 with MessageBatch

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

the class MessageBatchTest method testIterationWithAddition.

public void testIterationWithAddition() {
    List<Message> msgs = createMessages();
    MessageBatch batch = new MessageBatch(msgs);
    int count = 0;
    for (Message ignored : batch) {
        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 39 with MessageBatch

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

the class MessageBatchTest method testCopyConstructor.

public void testCopyConstructor() {
    List<Message> msgs = createMessages();
    MessageBatch batch = new MessageBatch(msgs);
    System.out.println("batch = " + batch);
    assert batch.size() == msgs.size() : "batch: " + batch;
    remove(batch, 3, 6, 10);
    System.out.println("batch = " + batch);
    assert batch.size() == msgs.size() - 3 : "batch: " + batch;
}
Also used : MessageBatch(org.jgroups.util.MessageBatch) Message(org.jgroups.Message)

Example 40 with MessageBatch

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

the class MessageBatchTest method testReplace.

public void testReplace() {
    List<Message> msgs = createMessages();
    MessageBatch batch = new MessageBatch(msgs);
    final Message MSG = new Message();
    int index = 0;
    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)

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