Search in sources :

Example 1 with CallIdSequenceWithBackpressure

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());
}
Also used : CallIdSequenceWithBackpressure(com.hazelcast.spi.impl.operationservice.impl.CallIdSequence.CallIdSequenceWithBackpressure) TimeoutException(java.util.concurrent.TimeoutException) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test) ParallelTest(com.hazelcast.test.annotation.ParallelTest)

Example 2 with CallIdSequenceWithBackpressure

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());
}
Also used : CallIdSequenceWithBackpressure(com.hazelcast.spi.impl.operationservice.impl.CallIdSequence.CallIdSequenceWithBackpressure) CountDownLatch(java.util.concurrent.CountDownLatch) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test) ParallelTest(com.hazelcast.test.annotation.ParallelTest)

Example 3 with CallIdSequenceWithBackpressure

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());
}
Also used : CallIdSequenceWithBackpressure(com.hazelcast.spi.impl.operationservice.impl.CallIdSequence.CallIdSequenceWithBackpressure) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test) ParallelTest(com.hazelcast.test.annotation.ParallelTest)

Aggregations

CallIdSequenceWithBackpressure (com.hazelcast.spi.impl.operationservice.impl.CallIdSequence.CallIdSequenceWithBackpressure)3 ParallelTest (com.hazelcast.test.annotation.ParallelTest)3 QuickTest (com.hazelcast.test.annotation.QuickTest)3 Test (org.junit.Test)3 CountDownLatch (java.util.concurrent.CountDownLatch)1 TimeoutException (java.util.concurrent.TimeoutException)1