use of org.jgroups.util.MessageBatch in project JGroups by belaban.
the class MessageBatchTest method testIterator7.
public void testIterator7() {
List<Message> msgs = createMessages();
MessageBatch batch = new MessageBatch(msgs);
int index = 0;
final Message MSG = new Message();
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++;
}
}
use of org.jgroups.util.MessageBatch in project JGroups by belaban.
the class MessageBatchTest method testCreationWithFilter2.
public void testCreationWithFilter2() {
List<Message> msgs = new ArrayList<>(20);
for (int i = 1; i <= 20; i++) {
Message msg = new Message(null, i);
if (i <= 10) {
msg.setFlag(Message.Flag.OOB);
if (i % 2 == 0)
msg.setTransientFlag(Message.TransientFlag.OOB_DELIVERED);
}
msgs.add(msg);
}
Predicate<Message> filter = msg -> msg != null && (!msg.isFlagSet(Message.Flag.OOB) || msg.setTransientFlagIfAbsent(Message.TransientFlag.OOB_DELIVERED));
MessageBatch batch = new MessageBatch(null, null, null, true, msgs, filter);
System.out.println("batch = " + batch.map(print_numbers));
assert batch.size() == 15;
for (Message msg : batch) {
int num = msg.getObject();
assert num > 10 || msg.isTransientFlagSet(Message.TransientFlag.OOB_DELIVERED);
}
}
use of org.jgroups.util.MessageBatch in project JGroups by belaban.
the class MessageBatchTest method testReplace3.
public void testReplace3() {
MessageBatch batch = new MessageBatch(1).add(new Message(null, "Bela")).add(new Message(null, "Michi")).add(new Message(null, "Nicole"));
System.out.println("batch = " + batch);
for (Message msg : batch) {
if ("Michi".equals(msg.getObject())) {
msg.setObject("Michelle");
// tests replacing the message with itself (with changed buffer though)
batch.replace(msg, msg);
}
}
Queue<String> names = new LinkedBlockingQueue<>(Arrays.asList("Bela", "Michelle", "Nicole"));
for (Message msg : batch) {
String expected = names.poll();
String name = msg.getObject();
System.out.println("found=" + name + ", expected=" + expected);
assert name.equals(expected) : "found=" + name + ", expected=" + expected;
}
}
use of org.jgroups.util.MessageBatch in project JGroups by belaban.
the class MessageBatchTest method testForEach.
public void testForEach() {
MessageBatch batch = new MessageBatch(10);
for (int i = 0; i < 10; i++) batch.add(new Message(a, i));
System.out.println("batch = " + batch);
assert batch.size() == 10;
batch.remove(msg -> {
// removes all msgs with even-numbered payloads
int num = msg.getObject();
return num % 2 == 0;
});
System.out.println("batch = " + batch);
assert batch.size() == 5;
}
use of org.jgroups.util.MessageBatch in project JGroups by belaban.
the class MessageBatchTest method testIterator2.
public void testIterator2() {
List<Message> msgs = createMessages();
MessageBatch batch = new MessageBatch(msgs);
int count = 0;
for (Message ignored : batch) count++;
assert count == msgs.size();
remove(batch, 3, 5, 10);
count = 0;
for (Message ignored : batch) count++;
assert count == msgs.size() - 3;
}
Aggregations