use of com.hazelcast.spi.impl.operationservice.impl.CallIdSequence.CallIdSequenceWithBackpressure in project hazelcast by hazelcast.
the class CallIdSequenceWithBackpressureTest method next_whenNoCapacity_thenBlockTillTimeout.
@Test
public void next_whenNoCapacity_thenBlockTillTimeout() {
sequence = new CallIdSequenceWithBackpressure(1, 2000);
// first invocation consumes the available call ID
nextCallId(sequence, false);
long oldLastCallId = sequence.getLastCallId();
try {
sequence.next(false);
fail();
} catch (TimeoutException e) {
// expected
}
assertEquals(oldLastCallId, sequence.getLastCallId());
}
use of com.hazelcast.spi.impl.operationservice.impl.CallIdSequence.CallIdSequenceWithBackpressure in project hazelcast by hazelcast.
the class CallIdSequenceWithBackpressureTest method next_whenNoCapacity_thenBlockTillCapacity.
@Test
public void next_whenNoCapacity_thenBlockTillCapacity() throws InterruptedException {
sequence = new CallIdSequenceWithBackpressure(1, 60000);
final long oldLastCallId = sequence.getLastCallId();
final CountDownLatch nextCalledLatch = new CountDownLatch(1);
spawn(new Runnable() {
@Override
public void run() {
DummyBackupAwareOperation op = new DummyBackupAwareOperation();
long callId = nextCallId(sequence, op.isUrgent());
setCallId(op, callId);
nextCalledLatch.countDown();
sleepSeconds(3);
sequence.complete();
}
});
nextCalledLatch.await();
long result = nextCallId(sequence, false);
assertEquals(oldLastCallId + 2, result);
assertEquals(oldLastCallId + 2, sequence.getLastCallId());
}
use of com.hazelcast.spi.impl.operationservice.impl.CallIdSequence.CallIdSequenceWithBackpressure in project hazelcast by hazelcast.
the class CallIdSequenceWithBackpressureTest method when_overCapacityButPriorityItem_then_noBackpressure.
@Test
public void when_overCapacityButPriorityItem_then_noBackpressure() {
final CallIdSequenceWithBackpressure sequence = new CallIdSequenceWithBackpressure(1, 60000);
// occupy the single call ID slot
nextCallId(sequence, true);
long oldLastCallId = sequence.getLastCallId();
long result = nextCallId(sequence, true);
assertEquals(oldLastCallId + 1, result);
assertEquals(oldLastCallId + 1, sequence.getLastCallId());
}
Aggregations