use of org.jgroups.util.NonBlockingCreditMap in project JGroups by belaban.
the class NonBlockingCreditMapTest method setup.
@BeforeMethod
protected void setup() {
map = new NonBlockingCreditMap(MAX_CREDITS, MAX_QUEUE_SIZE, new ReentrantLock(true));
addAll();
}
use of org.jgroups.util.NonBlockingCreditMap in project JGroups by belaban.
the class NonBlockingCreditMapTest method testBlockingDecrement.
public void testBlockingDecrement() {
map = new NonBlockingCreditMap(MAX_CREDITS, 2500, new ReentrantLock(true));
addAll();
Message msg = new BytesMessage(null, new byte[8000]);
boolean rc = map.decrement(msg, msg.getLength(), 0);
assert rc && !map.isQueuing();
new Thread(() -> {
Util.sleep(2000);
System.out.println("\n-- replenishing 5000 credits");
Stream.of(a, b, c, d).forEach(c -> map.replenish(c, 5000));
}).start();
for (int i = 1; i <= 5; i++) {
msg = new BytesMessage(null, new byte[1000]);
System.out.printf("-- adding msg %d: ", i);
// message 5 should block, but replenish() should unblock it
rc = map.decrement(msg, msg.getLength(), 0);
System.out.printf("rc=%b\n", rc);
assert rc == i < 3;
}
assert !map.isQueuing();
assert map.getQueuedMessages() == 0;
}
Aggregations