예제 #1
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test @Resources.Life(STARTED) public void shouldSupportTransactionsAppliedOutOfOrderOnRotation() throws Exception
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        public virtual void ShouldSupportTransactionsAppliedOutOfOrderOnRotation()
        {
            // given
//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
//ORIGINAL LINE: final CountsTracker tracker = resourceManager.managed(newTracker());
            CountsTracker tracker = ResourceManager.managed(NewTracker());

            using (Org.Neo4j.Kernel.Impl.Api.CountsAccessor_Updater tx = tracker.Apply(2).get())
            {
                tx.IncrementNodeCount(1, 1);
            }
            using (Org.Neo4j.Kernel.Impl.Api.CountsAccessor_Updater tx = tracker.Apply(4).get())
            {
                tx.IncrementNodeCount(1, 1);
            }

            // when
            Future <long> rotated = Threading.executeAndAwait(new Rotation(2), tracker, thread =>
            {
                switch (thread.State)
                {
                case BLOCKED:
                case WAITING:
                case TIMED_WAITING:
                case TERMINATED:
                    return(true);

                default:
                    return(false);
                }
            }, 10, SECONDS);

            using (Org.Neo4j.Kernel.Impl.Api.CountsAccessor_Updater tx = tracker.Apply(5).get())
            {
                tx.IncrementNodeCount(1, 1);
            }
            using (Org.Neo4j.Kernel.Impl.Api.CountsAccessor_Updater tx = tracker.Apply(3).get())
            {
                tx.IncrementNodeCount(1, 1);
            }

            // then
            assertEquals("rotated transaction", 4, rotated.get().longValue());
            assertEquals("stored transaction", 4, tracker.TxId());

            // the value in memory
            assertEquals("count", 4, tracker.NodeCount(1, Registers.newDoubleLongRegister()).readSecond());

            // the value in the store
            CountsVisitor visitor = mock(typeof(CountsVisitor));

            tracker.VisitFile(tracker.CurrentFile(), visitor);
            verify(visitor).visitNodeCount(1, 3);
            verifyNoMoreInteractions(visitor);

            assertEquals("final rotation", 5, tracker.Rotate(5));
        }
예제 #2
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test @Resources.Life(STARTED) public void shouldNotEndUpInBrokenStateAfterRotationFailure() throws Exception
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        public virtual void ShouldNotEndUpInBrokenStateAfterRotationFailure()
        {
            // GIVEN
            FakeClock         clock             = Clocks.fakeClock();
            CallTrackingClock callTrackingClock = new CallTrackingClock(clock);
            CountsTracker     tracker           = ResourceManager.managed(NewTracker(callTrackingClock, EmptyVersionContextSupplier.EMPTY));
            int labelId = 1;

            using (Org.Neo4j.Kernel.Impl.Api.CountsAccessor_Updater tx = tracker.Apply(2).get())
            {
                tx.IncrementNodeCount(labelId, 1);                           // now at 1
            }

            // WHEN
            System.Predicate <Thread> arrived  = thread => stackTraceContains(thread, all(classNameContains("Rotation"), methodIs("rotate")));
            Future <object>           rotation = Threading.executeAndAwait(t => t.rotate(4), tracker, arrived, 1, SECONDS);

            using (Org.Neo4j.Kernel.Impl.Api.CountsAccessor_Updater tx = tracker.Apply(3).get())
            {
                tx.IncrementNodeCount(labelId, 1);                           // now at 2
            }
            while (callTrackingClock.CallsToNanos() == 0)
            {
                Thread.Sleep(10);
            }
            clock.Forward(Config.defaults().get(GraphDatabaseSettings.counts_store_rotation_timeout).toMillis() * 2, MILLISECONDS);
            try
            {
                rotation.get();
                fail("Should've failed rotation due to timeout");
            }
            catch (ExecutionException e)
            {
                // good
                assertTrue(e.InnerException is RotationTimeoutException);
            }

            // THEN
            Org.Neo4j.Register.Register_DoubleLongRegister register = Registers.newDoubleLongRegister();
            tracker.Get(CountsKeyFactory.nodeKey(labelId), register);
            assertEquals(2, register.ReadSecond());

            // and WHEN later attempting rotation again
            using (Org.Neo4j.Kernel.Impl.Api.CountsAccessor_Updater tx = tracker.Apply(4).get())
            {
                tx.IncrementNodeCount(labelId, 1);                           // now at 3
            }
            tracker.Rotate(4);

            // THEN
            tracker.Get(CountsKeyFactory.nodeKey(labelId), register);
            assertEquals(3, register.ReadSecond());
        }
예제 #3
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void shouldUnMapThePrestateFileWhenTimingOutOnRotationAndAllowForShutdownInTheFailedRotationState() throws Throwable
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        public virtual void ShouldUnMapThePrestateFileWhenTimingOutOnRotationAndAllowForShutdownInTheFailedRotationState()
        {
            // Given
            _dbBuilder.newGraphDatabase().shutdown();
            CountsTracker store = CreateCountsTracker(_pageCache, Config.defaults(GraphDatabaseSettings.counts_store_rotation_timeout, "100ms"));

            using (Lifespan lifespan = new Lifespan(store))
            {
                using (Org.Neo4j.Kernel.Impl.Api.CountsAccessor_Updater updater = store.Apply(2).get())
                {
                    updater.IncrementNodeCount(0, 1);
                }

                try
                {
                    // when
                    store.Rotate(3);
                    fail("should have thrown");
                }
                catch (RotationTimeoutException)
                {
                    // good
                }
            }

            // and also no exceptions closing the page cache
            _pageCache.close();
        }
예제 #4
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void allowNonDirtyInMemoryDirtyVersionRead()
        public virtual void AllowNonDirtyInMemoryDirtyVersionRead()
        {
            int  labelId = 1;
            long lastClosedTransactionId = 15L;
            long writeTransactionId      = 13L;
            TransactionVersionContextSupplier versionContextSupplier = new TransactionVersionContextSupplier();

            versionContextSupplier.Init(() => lastClosedTransactionId);
            VersionContext versionContext = versionContextSupplier.VersionContext;

            using (Lifespan life = new Lifespan())
            {
                CountsTracker tracker = life.Add(NewTracker(versionContextSupplier));
                using (Org.Neo4j.Kernel.Impl.Api.CountsAccessor_Updater updater = tracker.Apply(writeTransactionId).get())
                {
                    updater.IncrementNodeCount(labelId, 1);
                }

                versionContext.InitRead();
                tracker.NodeCount(labelId, Registers.newDoubleLongRegister());
                assertFalse(versionContext.Dirty);
            }
        }