use of org.jgroups.util.MessageBatch in project JGroups by belaban.
the class MessageBatchTest method testIterator.
public void testIterator() {
List<Message> msgs = createMessages();
MessageBatch batch = new MessageBatch(msgs);
int index = 0, count = 0;
for (Message msg : batch) {
Message tmp = msgs.get(index++);
count++;
assert msg == tmp;
}
assert count == msgs.size();
}
use of org.jgroups.util.MessageBatch in project JGroups by belaban.
the class MessageBatchTest method testAddBatchNoResizeOK.
public void testAddBatchNoResizeOK() {
MessageBatch batch = new MessageBatch(16);
List<Message> msgs = createMessages();
MessageBatch other = new MessageBatch(3);
msgs.forEach(other::add);
assert other.size() == msgs.size();
assert batch.isEmpty();
int added = batch.add(other, false);
assert added == other.size();
assert batch.size() == msgs.size() && batch.capacity() == 16;
assert other.size() == msgs.size();
}
use of org.jgroups.util.MessageBatch in project JGroups by belaban.
the class MessageBatchTest method testAddBatchNoResizeFail.
public void testAddBatchNoResizeFail() {
MessageBatch batch = new MessageBatch(3);
List<Message> msgs = createMessages();
MessageBatch other = new MessageBatch(3);
msgs.forEach(other::add);
assert other.size() == msgs.size();
assert batch.isEmpty();
int added = batch.add(other, false);
assert added == batch.size();
assert batch.size() == 3 && batch.capacity() == 3;
assert other.size() == msgs.size();
}
use of org.jgroups.util.MessageBatch in project JGroups by belaban.
the class RefcountedNioMessageTest method testUnicastRefcounting.
public void testUnicastRefcounting() throws Exception {
try (JChannel a = new JChannel(Util.getTestStack()).name("A");
JChannel b = new JChannel(Util.getTestStack()).name("B")) {
UNICAST3 u = b.getProtocolStack().findProtocol(UNICAST3.class);
u.setAckThreshold(1);
a.connect("testUnicastRefcounting");
b.connect("testUnicastRefcounting");
Util.waitUntilAllChannelsHaveSameView(10000, 500, a, b);
Address dest = b.getAddress();
// populate a fixed pool of POOL_SIZE elements
for (int i = 0; i < POOL_SIZE; i++) pool.put(DIRECT ? ByteBuffer.allocateDirect(MSG_SIZE) : ByteBuffer.allocate(MSG_SIZE));
final AtomicInteger received = new AtomicInteger();
Receiver r = new Receiver() {
@Override
public void receive(Message msg) {
received.incrementAndGet();
}
@Override
public void receive(MessageBatch batch) {
received.addAndGet(batch.size());
}
};
b.setReceiver(r);
Sender[] senders = new Sender[NUM_SENDERS];
for (int i = 0; i < senders.length; i++) {
senders[i] = new Sender(a, pool, dest);
new Thread(senders[i], "sender-" + (i + i)).start();
}
Util.waitUntil(30000, 500, () -> received.get() == NUM_MSGS * NUM_SENDERS, () -> String.format("received=%d (expected=%d)", received.get(), NUM_MSGS * NUM_SENDERS));
assert MSGS.size() == NUM_MSGS * NUM_SENDERS;
assert MSGS.stream().allMatch(m -> m instanceof RefcountedNioMessage);
Util.waitUntil(10000, 500, () -> MSGS.stream().allMatch(m -> ((RefcountedNioMessage) m).getRefcount() == 0));
assert MSGS.stream().allMatch(m -> ((RefcountedNioMessage) m).getRefcount() == 0);
System.out.printf("\n*** pool size: %d, %d msgs\n", pool.size(), MSGS.size());
assert pool.size() == POOL_SIZE;
}
}
use of org.jgroups.util.MessageBatch in project JGroups by belaban.
the class MessageBatchDrainTest2 method drain.
protected void drain(int num) {
if (adders.getAndIncrement() == 0) {
num_removers.increment();
int cnt = 0, removed_msgs, total_removed = 0;
final MessageBatch delivery_batch = new MessageBatch(num);
do {
delivery_batch.reset();
removed_msgs = _transfer(delivery_batch);
if (removed_msgs > 0) {
total_removed += removed_msgs;
removed.add(removed_msgs);
}
cnt++;
// LockSupport.parkNanos(4_000);
} while (adders.decrementAndGet() != 0);
avg_remove_loops.add(cnt);
avg_removed.add(total_removed);
}
}
Aggregations