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