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));
}
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();
}
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";
}
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;
}
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++;
}
}
Aggregations