Пример #1
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void shouldBeNotifiedWhenNumberAvailable() throws Exception
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        public virtual void ShouldBeNotifiedWhenNumberAvailable()
        {
            // given
//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
//ORIGINAL LINE: final java.util.concurrent.Semaphore done = new java.util.concurrent.Semaphore(0);
            Semaphore done = new Semaphore(0);
//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
//ORIGINAL LINE: final org.neo4j.kernel.impl.util.OutOfOrderSequence sequence = new org.neo4j.kernel.impl.util.ArrayQueueOutOfOrderSequence(3, 5, EMPTY_META);
            OutOfOrderSequence sequence = new ArrayQueueOutOfOrderSequence(3, 5, _emptyMeta);

            Thread numberWaiter = new Thread(() =>
            {
                try
                {
                    sequence.Await(5, 60_000);
                }
                catch (Exception e) when(e is TimeoutException || e is InterruptedException)
                {
                    fail("Should not have thrown");
                }

                done.release();
            });

            numberWaiter.Start();

            assertFalse(done.tryAcquire(10, TimeUnit.MILLISECONDS));
            sequence.Offer(4, _emptyMeta);
            assertFalse(done.tryAcquire(10, TimeUnit.MILLISECONDS));
            sequence.Offer(5, _emptyMeta);
            assertTrue(done.tryAcquire(10_000, TimeUnit.MILLISECONDS));

            numberWaiter.Join();
        }
Пример #2
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void highestEverSeenTest()
        public virtual void HighestEverSeenTest()
        {
//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
//ORIGINAL LINE: final org.neo4j.kernel.impl.util.OutOfOrderSequence sequence = new org.neo4j.kernel.impl.util.ArrayQueueOutOfOrderSequence(0, 5, EMPTY_META);
            OutOfOrderSequence sequence = new ArrayQueueOutOfOrderSequence(0, 5, _emptyMeta);

            assertEquals(0L, sequence.HighestEverSeen());

            sequence.Offer(1L, _emptyMeta);
            assertEquals(1L, sequence.HighestEverSeen());

            sequence.Offer(42L, _emptyMeta);
            assertEquals(42L, sequence.HighestEverSeen());
        }
Пример #3
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void shouldExtendArrayIfNeedBe()
        public virtual void ShouldExtendArrayIfNeedBe()
        {
            // GIVEN
            OutOfOrderSequence sequence = new ArrayQueueOutOfOrderSequence(0L, 5, new long[1]);

            sequence.Offer(3L, new long[] { 0 });
            sequence.Offer(2L, new long[] { 1 });
            sequence.Offer(5L, new long[] { 2 });
            sequence.Offer(4L, new long[] { 3 });

            // WHEN offering a number that should result in extending the array
            sequence.Offer(6L, new long[] { 4 });
            // and WHEN offering the missing number to fill the gap
            sequence.Offer(1L, new long[] { 5 });

            // THEN the high number should be visible
            AssertGet(sequence, 6L, new long[] { 4 });
        }
Пример #4
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void shouldKeepItsCoolWhenMultipleThreadsAreHammeringIt() throws Throwable
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        public virtual void ShouldKeepItsCoolWhenMultipleThreadsAreHammeringIt()
        {
            // An interesting note is that during tests the call to sequence#offer made no difference
            // in performance, so there seems to be no visible penalty in using ArrayQueueOutOfOrderSequence.

            // GIVEN a sequence with intentionally low starting queue size
            System.Func <long, long[]> metaFunction = number => new long[] { number + 2, number * 2 };
//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
//ORIGINAL LINE: final java.util.concurrent.atomic.AtomicLong numberSource = new java.util.concurrent.atomic.AtomicLong();
            AtomicLong numberSource = new AtomicLong();
//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
//ORIGINAL LINE: final org.neo4j.kernel.impl.util.OutOfOrderSequence sequence = new org.neo4j.kernel.impl.util.ArrayQueueOutOfOrderSequence(numberSource.get(), 5, metaFunction.apply(numberSource.get()));
            OutOfOrderSequence sequence = new ArrayQueueOutOfOrderSequence(numberSource.get(), 5, metaFunction(numberSource.get()));
//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
//ORIGINAL LINE: final org.neo4j.test.Race race = new org.neo4j.test.Race().withEndCondition(() -> numberSource.get() > 10_000_000);
            Race race         = (new Race()).withEndCondition(() => numberSource.get() > 10_000_000);
            int  offerThreads = max(2, Runtime.Runtime.availableProcessors() - 1);

            race.AddContestants(offerThreads, () =>
            {
                long number = numberSource.incrementAndGet();
                sequence.Offer(number, metaFunction(number));
            });
            ThreadStart verifier = () =>
            {
                long[] highest      = sequence.Get();
                long[] expectedMeta = metaFunction(highest[0]);
                assertArrayEquals(expectedMeta, copyOfRange(highest, 1, highest.Length));
            };

            race.AddContestant(verifier);
            race.Go();

            // THEN
            verifier.run();
        }
Пример #5
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void shouldExposeGapFreeSequenceSingleThreaded()
        public virtual void ShouldExposeGapFreeSequenceSingleThreaded()
        {
            // GIVEN
            OutOfOrderSequence sequence = new ArrayQueueOutOfOrderSequence(0L, 10, new long[1]);

            // WHEN/THEN
            sequence.Offer(1, new long[] { 1 });
            AssertGet(sequence, 1, new long[] { 1 });

            sequence.Offer(2, new long[] { 2 });
            AssertGet(sequence, 2, new long[] { 2 });

            sequence.Offer(4, new long[] { 3 });
            AssertGet(sequence, 2, new long[] { 2 });

            sequence.Offer(3, new long[] { 4 });
            AssertGet(sequence, 4, new long[] { 3 });

            sequence.Offer(5, new long[] { 5 });
            AssertGet(sequence, 5, new long[] { 5 });

            // AND WHEN/THEN
            sequence.Offer(10, new long[] { 6 });
            sequence.Offer(11, new long[] { 7 });
            sequence.Offer(8, new long[] { 8 });
            sequence.Offer(9, new long[] { 9 });
            sequence.Offer(7, new long[] { 10 });
            AssertGet(sequence, 5, new long[] { 5 });
            sequence.Offer(6, new long[] { 11 });
            AssertGet(sequence, 11L, new long[] { 7 });
        }
Пример #6
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void shouldDealWithThisScenario()
        public virtual void ShouldDealWithThisScenario()
        {
            // GIVEN
            OutOfOrderSequence sequence = new ArrayQueueOutOfOrderSequence(0, 5, new long[1]);

            assertTrue(sequence.Offer(1, new long[] { 0 }));
            assertFalse(sequence.Offer(3, new long[] { 0 }));
            assertFalse(sequence.Offer(4, new long[] { 0 }));
            assertTrue(sequence.Offer(2, new long[] { 0 }));
            assertFalse(sequence.Offer(6, new long[] { 0 }));
            assertTrue(sequence.Offer(5, new long[] { 0 }));
            // leave out 7
            assertFalse(sequence.Offer(8, new long[] { 0 }));
            assertFalse(sequence.Offer(9, new long[] { 0 }));
            assertFalse(sequence.Offer(10, new long[] { 0 }));
            assertFalse(sequence.Offer(11, new long[] { 0 }));
            // putting 12 should need extending the backing queue array
            assertFalse(sequence.Offer(12, new long[] { 0 }));
            assertFalse(sequence.Offer(13, new long[] { 0 }));
            assertFalse(sequence.Offer(14, new long[] { 0 }));

            // WHEN finally offering nr 7
            assertTrue(sequence.Offer(7, new long[] { 0 }));

            // THEN the number should jump to 14
            AssertGet(sequence, 14, new long[] { 0 });
        }