Example #1
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void shouldCloseTransactionRegardlessOfWhetherOrNotItAppliedCorrectly() throws Exception
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        public virtual void ShouldCloseTransactionRegardlessOfWhetherOrNotItAppliedCorrectly()
        {
            // GIVEN
            TransactionIdStore  transactionIdStore = mock(typeof(TransactionIdStore));
            TransactionAppender appender           = new TestableTransactionAppender(transactionIdStore);
            long txId = 11;

            when(transactionIdStore.NextCommittingTransactionId()).thenReturn(txId);
            IOException   rootCause     = new IOException("Mock exception");
            StorageEngine storageEngine = mock(typeof(StorageEngine));

            doThrow(new IOException(rootCause)).when(storageEngine).apply(any(typeof(TransactionToApply)), any(typeof(TransactionApplicationMode)));
            TransactionCommitProcess commitProcess = new TransactionRepresentationCommitProcess(appender, storageEngine);
            TransactionToApply       transaction   = MockedTransaction();

            // WHEN
            try
            {
                commitProcess.Commit(transaction, _commitEvent, INTERNAL);
            }
            catch (TransactionFailureException e)
            {
                assertThat(e.Message, containsString("Could not apply the transaction to the store"));
                assertTrue(contains(e, rootCause.Message, rootCause.GetType()));
            }

            // THEN
            // we can't verify transactionCommitted since that's part of the TransactionAppender, which we have mocked
            verify(transactionIdStore, times(1)).transactionClosed(eq(txId), anyLong(), anyLong());
        }
 public DefaultRecoveryService(StorageEngine storageEngine, LogTailScanner logTailScanner, TransactionIdStore transactionIdStore, LogicalTransactionStore logicalTransactionStore, LogVersionRepository logVersionRepository, RecoveryStartInformationProvider.Monitor monitor)
 {
     this._storageEngine                    = storageEngine;
     this._transactionIdStore               = transactionIdStore;
     this._logicalTransactionStore          = logicalTransactionStore;
     this._logVersionRepository             = logVersionRepository;
     this._recoveryStartInformationProvider = new RecoveryStartInformationProvider(logTailScanner, monitor);
 }
Example #3
0
        public virtual long FindLastAppliedIndex()
        {
            DependencyResolver      dependencies       = _localDatabase.dataSource().DependencyResolver;
            TransactionIdStore      transactionIdStore = dependencies.ResolveDependency(typeof(TransactionIdStore), ONLY);
            LogicalTransactionStore transactionStore   = dependencies.ResolveDependency(typeof(LogicalTransactionStore), ONLY);

            return((new LastCommittedIndexFinder(transactionIdStore, transactionStore, _logProvider)).LastCommittedIndex);
        }
Example #4
0
        public TxPullRequestHandler(CatchupServerProtocol protocol, System.Func <StoreId> storeIdSupplier, System.Func <bool> databaseAvailable, System.Func <NeoStoreDataSource> dataSourceSupplier, Monitors monitors, LogProvider logProvider)
        {
            this._protocol          = protocol;
            this._storeIdSupplier   = storeIdSupplier;
            this._databaseAvailable = databaseAvailable;
            DependencyResolver dependencies = dataSourceSupplier().DependencyResolver;

            this._transactionIdStore      = dependencies.ResolveDependency(typeof(TransactionIdStore));
            this._logicalTransactionStore = dependencies.ResolveDependency(typeof(LogicalTransactionStore));
            this._monitor = monitors.NewMonitor(typeof(TxPullRequestsMonitor));
            this._log     = logProvider.getLog(this.GetType());
        }
Example #5
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void shouldIdentifyTransactionWithNetZeroChangesAsReadOnly()
        public virtual void ShouldIdentifyTransactionWithNetZeroChangesAsReadOnly()
        {
            // GIVEN a transaction that has seen some changes, where all those changes result in a net 0 change set
            // a good way of producing such state is to add a label to an existing node, and then remove it.
            GraphDatabaseAPI   db        = Dbr.GraphDatabaseAPI;
            TransactionIdStore txIdStore = Db.DependencyResolver.resolveDependency(typeof(TransactionIdStore));
            long startTxId = txIdStore.LastCommittedTransactionId;
            Node node      = CreateEmptyNode(db);

            using (Transaction tx = Db.beginTx())
            {
                node.AddLabel(TestLabels.LABEL_ONE);
                node.RemoveLabel(TestLabels.LABEL_ONE);
                tx.Success();
            }               // WHEN closing that transaction

            // THEN it should not have been committed
            assertEquals("Expected last txId to be what it started at + 2 (1 for the empty node, and one for the label)", startTxId + 2, txIdStore.LastCommittedTransactionId);
        }
Example #6
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void shouldUpdateTransactionIdStoreCorrectly() throws Throwable
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        public virtual void ShouldUpdateTransactionIdStoreCorrectly()
        {
            // Given
            TransactionIdStore store1 = mock(typeof(TransactionIdStore));
            TransactionIdStore store2 = mock(typeof(TransactionIdStore));

//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @SuppressWarnings("unchecked") System.Func<org.neo4j.kernel.impl.transaction.log.TransactionIdStore> supplier = mock(System.Func.class);
            System.Func <TransactionIdStore> supplier = mock(typeof(System.Func));
            when(supplier()).thenReturn(store1, store2);

            doAnswer(invocation =>
            {
                (( HighAvailabilityMemberListener )invocation.getArgument(0)).slaveIsAvailable(new HighAvailabilityMemberChangeEvent(null, null, _serverId, null)
                                                                                               );
                return(null);
            }).when(_machine).addHighAvailabilityMemberListener(any(typeof(HighAvailabilityMemberListener)));

            doAnswer(invocation =>
            {
                (( HighAvailabilityMemberListener )invocation.getArgument(0)).instanceStops(new HighAvailabilityMemberChangeEvent(null, null, _serverId, null)
                                                                                            );
                return(null);
            }).when(_machine).removeHighAvailabilityMemberListener(any(typeof(HighAvailabilityMemberListener)));

            UpdatePullingTransactionObligationFulfiller fulfiller = new UpdatePullingTransactionObligationFulfiller(_updatePuller, _machine, _serverId, supplier);

            // When
            fulfiller.Start();
            fulfiller.Fulfill(1);
            fulfiller.Stop();
            fulfiller.Fulfill(2);
            fulfiller.Start();
            fulfiller.Fulfill(3);
            fulfiller.Stop();
            fulfiller.Fulfill(4);

            // Then
            verify(store1, times(1)).LastClosedTransactionId;
            verify(store2, times(1)).LastClosedTransactionId;
        }
Example #7
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void updatePullerTriggerPageTransactionTracking()
		 public virtual void UpdatePullerTriggerPageTransactionTracking()
		 {
			  HighlyAvailableGraphDatabase slave = _cluster.AnySlave;
			  TransactionIdStore slaveTransactionIdStore = slave.DependencyResolver.resolveDependency( typeof( TransactionIdStore ) );
			  assertEquals( 5, slaveTransactionIdStore.LastClosedTransactionId );

			  ByzantineLongSupplier byzantineIdSupplier = _contextSupplier.ByzantineIdSupplier;
			  byzantineIdSupplier.UseWrongTxId();
			  try
			  {
					  using ( Transaction ignored = slave.BeginTx() )
					  {
						slave.Execute( "match (n) return n" );
					  }
			  }
			  catch ( QueryExecutionException executionException )
			  {
					assertEquals( "Unable to get clean data snapshot for query 'match (n) return n' after 5 attempts.", executionException.Message );
			  }
			  byzantineIdSupplier.UseCorrectTxId();
			  slave.Execute( "match (n) return n" ).close();
		 }
Example #8
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void shouldDetectNoChangesInCommitsAlsoForTheIndexes()
        public virtual void ShouldDetectNoChangesInCommitsAlsoForTheIndexes()
        {
            // GIVEN a transaction that has seen some changes, where all those changes result in a net 0 change set
            // a good way of producing such state is to add a label to an existing node, and then remove it.
            GraphDatabaseAPI   db        = Dbr.GraphDatabaseAPI;
            TransactionIdStore txIdStore = Db.DependencyResolver.resolveDependency(typeof(TransactionIdStore));
            long         startTxId       = txIdStore.LastCommittedTransactionId;
            Node         node            = CreateEmptyNode(db);
            Index <Node> index           = CreateNodeIndex(db);

            using (Transaction tx = Db.beginTx())
            {
                node.AddLabel(TestLabels.LABEL_ONE);
                node.RemoveLabel(TestLabels.LABEL_ONE);
                index.Add(node, "key", "value");
                index.Remove(node, "key", "value");
                tx.Success();
            }               // WHEN closing that transaction

            // THEN it should not have been committed
            assertEquals("Expected last txId to be what it started at + 3 " + "(1 for the empty node, 1 for index, and one for the label)", startTxId + 3, txIdStore.LastCommittedTransactionId);
        }
Example #9
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void shouldSuccessfullyCommitTransactionWithNoCommands() throws Exception
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        public virtual void ShouldSuccessfullyCommitTransactionWithNoCommands()
        {
            // GIVEN
            long txId            = 11;
            long commitTimestamp = DateTimeHelper.CurrentUnixTimeMillis();
            TransactionIdStore  transactionIdStore = mock(typeof(TransactionIdStore));
            TransactionAppender appender           = new TestableTransactionAppender(transactionIdStore);

            when(transactionIdStore.NextCommittingTransactionId()).thenReturn(txId);

            StorageEngine storageEngine = mock(typeof(StorageEngine));

            TransactionCommitProcess          commitProcess = new TransactionRepresentationCommitProcess(appender, storageEngine);
            PhysicalTransactionRepresentation noCommandTx   = new PhysicalTransactionRepresentation(Collections.emptyList());

            noCommandTx.SetHeader(new sbyte[0], -1, -1, -1, -1, -1, -1);

            // WHEN

            commitProcess.Commit(new TransactionToApply(noCommandTx), _commitEvent, INTERNAL);

            verify(transactionIdStore).transactionCommitted(txId, FakeCommitment.CHECKSUM, FakeCommitment.TIMESTAMP);
        }
Example #10
0
        public DefaultMasterImplSPI(GraphDatabaseAPI graphDb, FileSystemAbstraction fileSystemAbstraction, Monitors monitors, TokenHolders tokenHolders, IdGeneratorFactory idGeneratorFactory, TransactionCommitProcess transactionCommitProcess, CheckPointer checkPointer, TransactionIdStore transactionIdStore, LogicalTransactionStore logicalTransactionStore, NeoStoreDataSource neoStoreDataSource, LogProvider logProvider)
        {
            this._graphDb                  = graphDb;
            this._fileSystem               = fileSystemAbstraction;
            this._tokenHolders             = tokenHolders;
            this._idGeneratorFactory       = idGeneratorFactory;
            this._transactionCommitProcess = transactionCommitProcess;
            this._checkPointer             = checkPointer;
            this._neoStoreDataSource       = neoStoreDataSource;
            this._databaseDirectory        = graphDb.DatabaseLayout().databaseDirectory();
            this._txChecksumLookup         = new TransactionChecksumLookup(transactionIdStore, logicalTransactionStore);
            this._responsePacker           = new ResponsePacker(logicalTransactionStore, transactionIdStore, graphDb.storeId);
            this._monitors                 = monitors;
//JAVA TO C# CONVERTER WARNING: The .NET Type.FullName property will not always yield results identical to the Java Class.getName method:
            monitors.AddMonitorListener(new LoggingStoreCopyServerMonitor(logProvider.GetLog(typeof(StoreCopyServer))), typeof(StoreCopyServer).FullName);
        }
Example #11
0
 public override void Stop()
 {
     this._txIdStore = null;
 }
Example #12
0
 public override void Start()
 {
     this._txIdStore = _txIdStoreSupplier.get();
 }
Example #13
0
        private TestVersionContext TestCursorContext()
        {
            TransactionIdStore transactionIdStore = TransactionIdStore;

            return(new TestVersionContext(this, transactionIdStore.getLastClosedTransactionId));
        }
Example #14
0
 public TransactionChecksumLookup(TransactionIdStore transactionIdStore, LogicalTransactionStore logicalTransactionStore)
 {
     this._transactionIdStore      = transactionIdStore;
     this._logicalTransactionStore = logicalTransactionStore;
     this._upgradeTransaction      = transactionIdStore.UpgradeTransaction;
 }
Example #15
0
        private static long LastCommittedTxId(GraphDatabaseAPI db)
        {
            TransactionIdStore txIdStore = Db.DependencyResolver.resolveDependency(typeof(TransactionIdStore));

            return(txIdStore.LastCommittedTransactionId);
        }