예제 #1
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void shouldRotateCountsStoreWhenRotatingLog() throws java.io.IOException
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        public virtual void ShouldRotateCountsStoreWhenRotatingLog()
        {
            // GIVEN
            GraphDatabaseAPI db = ( GraphDatabaseAPI )_dbBuilder.newGraphDatabase();

            // WHEN doing a transaction (actually two, the label-mini-tx also counts)
            using (Transaction tx = Db.beginTx())
            {
                Db.createNode(_b);
                tx.Success();
            }
            // and rotating the log (which implies flushing)
            CheckPoint(db);
            // and creating another node after it
            using (Transaction tx = Db.beginTx())
            {
                Db.createNode(_c);
                tx.Success();
            }

            // THEN
            assertTrue(_fs.fileExists(AlphaStoreFile()));
            assertTrue(_fs.fileExists(BetaStoreFile()));

//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
//ORIGINAL LINE: final org.neo4j.io.pagecache.PageCache pageCache = db.getDependencyResolver().resolveDependency(org.neo4j.io.pagecache.PageCache.class);
            PageCache pageCache = Db.DependencyResolver.resolveDependency(typeof(PageCache));

            using (Lifespan life = new Lifespan())
            {
                CountsTracker store = life.Add(CreateCountsTracker(pageCache));
                // NOTE since the rotation happens before the second transaction is committed we do not see those changes
                // in the stats
                // a transaction for creating the label and a transaction for the node
                assertEquals(BASE_TX_ID + 1 + 1, store.TxId());
                assertEquals(INITIAL_MINOR_VERSION, store.MinorVersion());
                // one for all nodes and one for the created "B" label
                assertEquals(1 + 1, store.TotalEntriesStored());
                assertEquals(1 + 1, AllRecords(store).Count);
            }

            // on the other hand the tracker should read the correct value by merging data on disk and data in memory
//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
//ORIGINAL LINE: final CountsTracker tracker = db.getDependencyResolver().resolveDependency(org.neo4j.kernel.impl.storageengine.impl.recordstorage.RecordStorageEngine.class).testAccessNeoStores().getCounts();
            CountsTracker tracker = Db.DependencyResolver.resolveDependency(typeof(RecordStorageEngine)).testAccessNeoStores().Counts;

            assertEquals(1 + 1, tracker.NodeCount(-1, newDoubleLongRegister()).readSecond());

            int labelId;

            using (Transaction tx = Db.beginTx())
            {
                KernelTransaction transaction = Db.DependencyResolver.resolveDependency(typeof(ThreadToStatementContextBridge)).getKernelTransactionBoundToThisThread(true);
                labelId = transaction.TokenRead().nodeLabel(_c.name());
            }
            assertEquals(1, tracker.NodeCount(labelId, newDoubleLongRegister()).readSecond());

            Db.shutdown();
        }
예제 #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 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));
        }
예제 #3
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);
            }
        }