//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes: //ORIGINAL LINE: @Test public void shouldClearPreviousChunks() public virtual void ShouldClearPreviousChunks() { // GIVEN System.Action <long[]> consumer = mock(typeof(System.Action)); //JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final': //ORIGINAL LINE: final java.util.concurrent.atomic.AtomicBoolean safeThreshold = new java.util.concurrent.atomic.AtomicBoolean(false); AtomicBoolean safeThreshold = new AtomicBoolean(false); DelayedBuffer <long> buffer = new DelayedBuffer <long>(singleton(0L), t => safeThreshold.get(), 10, consumer); // three chunks buffer.Offer(0); buffer.Maintenance(); buffer.Offer(1); buffer.Maintenance(); buffer.Offer(2); buffer.Maintenance(); // WHEN safeThreshold.set(true); buffer.Clear(); buffer.Maintenance(); // THEN verifyNoMoreInteractions(consumer); }
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes: //ORIGINAL LINE: @Test public void shouldClearCurrentChunk() public virtual void ShouldClearCurrentChunk() { // GIVEN System.Action <long[]> consumer = mock(typeof(System.Action)); DelayedBuffer <long> buffer = new DelayedBuffer <long>(singleton(0L), Predicates.alwaysTrue(), 10, consumer); buffer.Offer(0); buffer.Offer(1); buffer.Offer(2); // WHEN buffer.Clear(); buffer.Maintenance(); // THEN verifyNoMoreInteractions(consumer); }
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes: //ORIGINAL LINE: @Test public void shouldNotReleaseValuesUntilCrossedThreshold() public virtual void ShouldNotReleaseValuesUntilCrossedThreshold() { // GIVEN VerifyingConsumer consumer = new VerifyingConsumer(30); //JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final': //ORIGINAL LINE: final java.util.concurrent.atomic.AtomicLong txOpened = new java.util.concurrent.atomic.AtomicLong(); AtomicLong txOpened = new AtomicLong(); //JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final': //ORIGINAL LINE: final java.util.concurrent.atomic.AtomicLong txClosed = new java.util.concurrent.atomic.AtomicLong(); AtomicLong txClosed = new AtomicLong(); System.Func <long> chunkThreshold = txOpened.get; System.Predicate <long> safeThreshold = value => txClosed.get() >= value; DelayedBuffer <long> buffer = new DelayedBuffer <long>(chunkThreshold, safeThreshold, 100, consumer); // Transaction spans like these: // 1 |-1--------2-------3---| // 2 |4--5---------| // 3 |---------6----| // 4 |7--8-| // 5 |--------9-------10-| // 6 |--11----| // 7 |-12---13---14--| // TIME|1-2-3-4-5-6-7-8-9-a-b-c-d-e-f-g-h-i-j| // POI ^ ^ ^ ^ ^ ^ // A B C D E F // A txOpened.incrementAndGet(); // <-- TX 1 buffer.Offer(1); txOpened.incrementAndGet(); // <-- TX 2 buffer.Offer(4); buffer.Maintenance(); assertEquals(0, consumer.ChunksAccepted()); // B buffer.Offer(5); txOpened.incrementAndGet(); // <-- TX 3 txOpened.incrementAndGet(); // <-- TX 4 buffer.Offer(7); buffer.Maintenance(); assertEquals(0, consumer.ChunksAccepted()); // C txOpened.incrementAndGet(); // <-- TX 5 buffer.Offer(2); buffer.Offer(8); // TX 4 closes, but TXs with lower ids are still open buffer.Maintenance(); assertEquals(0, consumer.ChunksAccepted()); // D // TX 2 closes, but TXs with lower ids are still open buffer.Offer(6); txOpened.incrementAndGet(); // <-- TX 6 buffer.Offer(9); buffer.Offer(3); txOpened.incrementAndGet(); // <-- TX 7 buffer.Offer(11); // TX 3 closes, but TXs with lower ids are still open buffer.Offer(12); txClosed.set(4); // since 1-4 have now all closed buffer.Maintenance(); consumer.AssertHaveOnlySeen(1, 4, 5, 7); // E buffer.Offer(10); // TX 6 closes, but TXs with lower ids are still open buffer.Offer(13); txClosed.set(6); // since 1-6 have now all closed buffer.Maintenance(); consumer.AssertHaveOnlySeen(1, 2, 4, 5, 7, 8); // F buffer.Offer(14); txClosed.set(7); // since 1-7 have now all closed buffer.Maintenance(); consumer.AssertHaveOnlySeen(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14); }