/** * Add the specified gating sequences to this instance of the Disruptor. They will * safely and atomically added to the list of gating sequences. * * @param gatingSequences The sequences to add. */ public void addGatingSequences(Sequence... gatingSequences) { sequencer.addGatingSequences(gatingSequences); }
/** * Add the specified gating sequences to this instance of the Disruptor. They will safely and atomically added to the list of gating sequences. * * @param gatingSequences The sequences to add. */ public void addGatingSequences(Sequence... gatingSequences) { sequencer.addGatingSequences(gatingSequences); }
@Test(expected = InsufficientCapacityException.class) public void shouldThrowInsufficientCapacityExceptionWhenSequencerIsFull() throws Exception { sequencer.addGatingSequences(gatingSequence); for (int i = 0; i < BUFFER_SIZE; i++) { sequencer.next(); } sequencer.tryNext(); }
@Test public void shouldCalculateRemainingCapacity() throws Exception { sequencer.addGatingSequences(gatingSequence); assertThat(sequencer.remainingCapacity(), is((long) BUFFER_SIZE)); for (int i = 1; i < BUFFER_SIZE; i++) { sequencer.next(); assertThat(sequencer.remainingCapacity(), is((long) BUFFER_SIZE - i)); } }
@Test public void shouldHoldUpPublisherWhenBufferIsFull() throws InterruptedException { sequencer.addGatingSequences(gatingSequence); long sequence = sequencer.next(BUFFER_SIZE); sequencer.publish(sequence - (BUFFER_SIZE - 1), sequence); final CountDownLatch waitingLatch = new CountDownLatch(1); final CountDownLatch doneLatch = new CountDownLatch(1); final long expectedFullSequence = Sequencer.INITIAL_CURSOR_VALUE + sequencer.getBufferSize(); assertThat(sequencer.getCursor(), is(expectedFullSequence)); executor.submit( new Runnable() { @Override public void run() { waitingLatch.countDown(); long next = sequencer.next(); sequencer.publish(next); doneLatch.countDown(); } }); waitingLatch.await(); assertThat(sequencer.getCursor(), is(expectedFullSequence)); gatingSequence.set(Sequencer.INITIAL_CURSOR_VALUE + 1L); doneLatch.await(); assertThat(sequencer.getCursor(), is(expectedFullSequence + 1L)); }
@Test public void shouldTryNext() throws Exception { sequencer.addGatingSequences(gatingSequence); for (int i = 0; i < BUFFER_SIZE; i++) { sequencer.publish(sequencer.tryNext()); } try { sequencer.tryNext(); fail("Should of thrown: " + InsufficientCapacityException.class.getSimpleName()); } catch (InsufficientCapacityException e) { // No-op } }
@Test public void shouldIndicateNoAvailableCapacity() { sequencer.addGatingSequences(gatingSequence); long sequence = sequencer.next(BUFFER_SIZE); sequencer.publish(sequence - (BUFFER_SIZE - 1), sequence); assertFalse(sequencer.hasAvailableCapacity(1)); }
/** * Add the specified gating sequences to this instance of the Disruptor. They will * safely and atomically added to the list of gating sequences. * * @param gatingSequences The sequences to add. */ public void addGatingSequences(Sequence... gatingSequences) { sequencer.addGatingSequences(gatingSequences); }
@Test public void shouldIndicateHasAvailableCapacity() { sequencer.addGatingSequences(gatingSequence); assertTrue(sequencer.hasAvailableCapacity(1)); assertTrue(sequencer.hasAvailableCapacity(BUFFER_SIZE)); assertFalse(sequencer.hasAvailableCapacity(BUFFER_SIZE + 1)); sequencer.publish(sequencer.next()); assertTrue(sequencer.hasAvailableCapacity(BUFFER_SIZE - 1)); assertFalse(sequencer.hasAvailableCapacity(BUFFER_SIZE)); }
/** * Add the specified gating sequences to this instance of the Disruptor. They will * safely and atomically added to the list of gating sequences. * * @param gatingSequences The sequences to add. */ public void addGatingSequences(Sequence... gatingSequences) { sequencer.addGatingSequences(gatingSequences); }
/** * Add the specified gating sequences to this instance of the Disruptor. They will * safely and atomically added to the list of gating sequences. * * @param gatingSequences The sequences to add. */ public void addGatingSequences(Sequence... gatingSequences) { sequencer.addGatingSequences(gatingSequences); }
/** * Add the specified gating sequences to this instance of the Disruptor. They will * safely and atomically added to the list of gating sequences. * * @param gatingSequences The sequences to add. */ public void addGatingSequences(Sequence... gatingSequences) { sequencer.addGatingSequences(gatingSequences); }