//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void shouldNotCallTransactionClosedOnFailedAppendedTransaction() throws Exception
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        public virtual void ShouldNotCallTransactionClosedOnFailedAppendedTransaction()
        {
            // GIVEN
            long   txId           = 3;
            string failureMessage = "Forces a failure";
            FlushablePositionAwareChannel channel = spy(new PositionAwarePhysicalFlushableChannel(mock(typeof(PhysicalLogVersionedStoreChannel))));
            IOException failure = new IOException(failureMessage);

            when(channel.PutInt(anyInt())).thenThrow(failure);
            when(_logFile.Writer).thenReturn(channel);
            when(_transactionIdStore.nextCommittingTransactionId()).thenReturn(txId);
            Mockito.reset(_databaseHealth);
            TransactionAppender appender = Life.add(CreateTransactionAppender());

            // WHEN
            TransactionRepresentation transaction = mock(typeof(TransactionRepresentation));

            when(transaction.AdditionalHeader()).thenReturn(new sbyte[0]);
            try
            {
                appender.Append(new TransactionToApply(transaction), _logAppendEvent);
                fail("Expected append to fail. Something is wrong with the test itself");
            }
            catch (IOException e)
            {
                // THEN
                assertSame(failure, e);
                verify(_transactionIdStore, times(1)).nextCommittingTransactionId();
                verify(_transactionIdStore, never()).transactionClosed(eq(txId), anyLong(), anyLong());
                verify(_databaseHealth).panic(failure);
            }
        }
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void shouldAppendSingleTransaction() throws Exception
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        public virtual void ShouldAppendSingleTransaction()
        {
            // GIVEN
            when(_logFile.Writer).thenReturn(_channel);
            long txId = 15;

            when(_transactionIdStore.nextCommittingTransactionId()).thenReturn(txId);
            TransactionAppender appender = Life.add(CreateTransactionAppender());

            // WHEN
            TransactionRepresentation transaction = transaction(SingleCreateNodeCommand(0), new sbyte[] { 1, 2, 5 }, 2, 1, 12345, 4545, 12345 + 10);

            appender.Append(new TransactionToApply(transaction), _logAppendEvent);

            // THEN
//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
//ORIGINAL LINE: final org.neo4j.kernel.impl.transaction.log.entry.LogEntryReader<ReadableLogChannel> logEntryReader = new org.neo4j.kernel.impl.transaction.log.entry.VersionAwareLogEntryReader<>();
            LogEntryReader <ReadableLogChannel> logEntryReader = new VersionAwareLogEntryReader <ReadableLogChannel>();

            using (PhysicalTransactionCursor <ReadableLogChannel> reader = new PhysicalTransactionCursor <ReadableLogChannel>(_channel, logEntryReader))
            {
                reader.Next();
                TransactionRepresentation tx = reader.Get().TransactionRepresentation;
                assertArrayEquals(transaction.AdditionalHeader(), tx.AdditionalHeader());
                assertEquals(transaction.MasterId, tx.MasterId);
                assertEquals(transaction.AuthorId, tx.AuthorId);
                assertEquals(transaction.TimeStarted, tx.TimeStarted);
                assertEquals(transaction.TimeCommitted, tx.TimeCommitted);
                assertEquals(transaction.LatestCommittedTxWhenStarted, tx.LatestCommittedTxWhenStarted);
            }
        }
Exemplo n.º 3
0
 public override TransactionCommitProcess Create(TransactionAppender appender, StorageEngine storageEngine, Config config)
 {
     if (config.Get(GraphDatabaseSettings.read_only))
     {
         return(new ReadOnlyTransactionCommitProcess());
     }
     return(( TransactionCommitProcess )newProxyInstance(typeof(TransactionCommitProcess).ClassLoader, new Type[] { typeof(TransactionCommitProcess) }, _commitProcessDelegate));
 }
Exemplo n.º 4
0
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
//ORIGINAL LINE: private void addATransactionAndRewind(org.neo4j.kernel.lifecycle.LifeSupport life, org.neo4j.kernel.impl.transaction.log.files.LogFiles logFiles, TransactionMetadataCache positionCache, TransactionIdStore transactionIdStore, byte[] additionalHeader, int masterId, int authorId, long timeStarted, long latestCommittedTxWhenStarted, long timeCommitted) throws java.io.IOException
        private void AddATransactionAndRewind(LifeSupport life, LogFiles logFiles, TransactionMetadataCache positionCache, TransactionIdStore transactionIdStore, sbyte[] additionalHeader, int masterId, int authorId, long timeStarted, long latestCommittedTxWhenStarted, long timeCommitted)
        {
            TransactionAppender appender = life.Add(new BatchingTransactionAppender(logFiles, NO_ROTATION, positionCache, transactionIdStore, BYPASS, _databaseHealth));
            PhysicalTransactionRepresentation transaction = new PhysicalTransactionRepresentation(SingleCreateNodeCommand());

            transaction.SetHeader(additionalHeader, masterId, authorId, timeStarted, latestCommittedTxWhenStarted, timeCommitted, -1);
            appender.Append(new TransactionToApply(transaction), Org.Neo4j.Kernel.impl.transaction.tracing.LogAppendEvent_Fields.Null);
        }
Exemplo n.º 5
0
 public CheckPointerImpl(TransactionIdStore transactionIdStore, CheckPointThreshold threshold, StorageEngine storageEngine, LogPruning logPruning, TransactionAppender appender, DatabaseHealth databaseHealth, LogProvider logProvider, CheckPointTracer tracer, IOLimiter ioLimiter, StoreCopyCheckPointMutex mutex)
 {
     this._appender           = appender;
     this._transactionIdStore = transactionIdStore;
     this._threshold          = threshold;
     this._storageEngine      = storageEngine;
     this._logPruning         = logPruning;
     this._databaseHealth     = databaseHealth;
     this._ioLimiter          = ioLimiter;
     this._msgLog             = logProvider.GetLog(typeof(CheckPointerImpl));
     this._tracer             = tracer;
     this._mutex = mutex;
 }
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void shouldKeepTransactionsIntactWhenConcurrentlyRotationAndAppending() throws Throwable
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        public virtual void ShouldKeepTransactionsIntactWhenConcurrentlyRotationAndAppending()
        {
            // GIVEN
            LogVersionRepository logVersionRepository = new SimpleLogVersionRepository();
            LogFiles             logFiles             = LogFilesBuilder.builder(_directory.databaseLayout(), _fileSystemRule.get()).withLogVersionRepository(logVersionRepository).withRotationThreshold(ByteUnit.mebiBytes(1)).withTransactionIdStore(new SimpleTransactionIdStore()).build();

            _life.add(logFiles);
//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
//ORIGINAL LINE: final java.util.concurrent.atomic.AtomicBoolean end = new java.util.concurrent.atomic.AtomicBoolean();
            AtomicBoolean            end           = new AtomicBoolean();
            AllTheMonitoring         monitoring    = new AllTheMonitoring(end, 100);
            TransactionIdStore       txIdStore     = new SimpleTransactionIdStore();
            TransactionMetadataCache metadataCache = new TransactionMetadataCache();

            monitoring.LogFile = logFiles.LogFile;
            DatabaseHealth health   = new DatabaseHealth(mock(typeof(DatabasePanicEventGenerator)), NullLog.Instance);
            LogRotation    rotation = new LogRotationImpl(monitoring, logFiles, health);
//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
//ORIGINAL LINE: final TransactionAppender appender = life.add(new BatchingTransactionAppender(logFiles, rotation, metadataCache, txIdStore, BYPASS, health));
            TransactionAppender appender = _life.add(new BatchingTransactionAppender(logFiles, rotation, metadataCache, txIdStore, BYPASS, health));

            // WHEN
            Race race = new Race();

            for (int i = 0; i < 10; i++)
            {
                race.AddContestant(() =>
                {
                    while (!end.get())
                    {
                        try
                        {
                            appender.Append(new TransactionToApply(SillyTransaction(1_000)), NULL);
                        }
                        catch (Exception e)
                        {
                            e.printStackTrace(System.out);
                            end.set(true);
                            fail(e.Message);
                        }
                    }
                });
            }
            race.AddContestant(EndAfterMax(10, SECONDS, end));
            race.Go();

            // THEN
            assertTrue(monitoring.NumberOfRotations() > 0);
        }
Exemplo n.º 7
0
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
//ORIGINAL LINE: public System.Nullable<long> call() throws Exception
        public override long?Call()
        {
            long lastCommittedTransactionId;

            using (FileSystemAbstraction fileSystem = new DefaultFileSystemAbstraction(), Lifespan life = new Lifespan())
            {
                TransactionIdStore       transactionIdStore       = new SimpleTransactionIdStore();
                TransactionMetadataCache transactionMetadataCache = new TransactionMetadataCache();
                LogFiles logFiles = life.Add(CreateLogFiles(transactionIdStore, fileSystem));

                TransactionAppender transactionAppender = life.Add(CreateBatchingTransactionAppender(transactionIdStore, transactionMetadataCache, logFiles));

                ExecutorService executorService = Executors.newFixedThreadPool(_threads);
                try
                {
//JAVA TO C# CONVERTER WARNING: Java wildcard generics have no direct equivalent in .NET:
//ORIGINAL LINE: java.util.concurrent.Future<?>[] handlers = new java.util.concurrent.Future[threads];
                    Future <object>[] handlers = new Future[_threads];
                    for (int i = 0; i < _threads; i++)
                    {
                        TransactionRepresentationFactory factory = new TransactionRepresentationFactory();
                        Worker task = new Worker(transactionAppender, factory, _condition);
                        handlers[i] = executorService.submit(task);
                    }

                    // wait for all the workers to complete
//JAVA TO C# CONVERTER WARNING: Java wildcard generics have no direct equivalent in .NET:
//ORIGINAL LINE: for (java.util.concurrent.Future<?> handle : handlers)
                    foreach (Future <object> handle in handlers)
                    {
                        handle.get();
                    }
                }
                finally
                {
                    executorService.shutdown();
                }

                lastCommittedTransactionId = transactionIdStore.LastCommittedTransactionId;
            }

            return(lastCommittedTransactionId);
        }
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void shouldNotCallTransactionClosedOnFailedForceLogToDisk() throws Exception
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        public virtual void ShouldNotCallTransactionClosedOnFailedForceLogToDisk()
        {
            // GIVEN
            long   txId           = 3;
            string failureMessage = "Forces a failure";
            FlushablePositionAwareChannel channel = spy(new InMemoryClosableChannel());
            IOException failure = new IOException(failureMessage);
//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
//ORIGINAL LINE: final java.io.Flushable flushable = mock(java.io.Flushable.class);
            Flushable flushable = mock(typeof(Flushable));

            doAnswer(invocation =>
            {
                invocation.callRealMethod();
                return(flushable);
            }).when(channel).prepareForFlush();
            doThrow(failure).when(flushable).flush();
            when(_logFile.Writer).thenReturn(channel);
            TransactionMetadataCache metadataCache      = new TransactionMetadataCache();
            TransactionIdStore       transactionIdStore = mock(typeof(TransactionIdStore));

            when(transactionIdStore.NextCommittingTransactionId()).thenReturn(txId);
            Mockito.reset(_databaseHealth);
            TransactionAppender appender = Life.add(new BatchingTransactionAppender(_logFiles, NO_ROTATION, metadataCache, transactionIdStore, BYPASS, _databaseHealth));

            // WHEN
            TransactionRepresentation transaction = mock(typeof(TransactionRepresentation));

            when(transaction.AdditionalHeader()).thenReturn(new sbyte[0]);
            try
            {
                appender.Append(new TransactionToApply(transaction), _logAppendEvent);
                fail("Expected append to fail. Something is wrong with the test itself");
            }
            catch (IOException e)
            {
                // THEN
                assertSame(failure, e);
                verify(transactionIdStore, times(1)).nextCommittingTransactionId();
                verify(transactionIdStore, never()).transactionClosed(eq(txId), anyLong(), anyLong());
                verify(_databaseHealth).panic(failure);
            }
        }
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void shouldAppendCommittedTransactions() throws Exception
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        public virtual void ShouldAppendCommittedTransactions()
        {
            // GIVEN
            when(_logFile.Writer).thenReturn(_channel);
            long nextTxId = 15;

            when(_transactionIdStore.nextCommittingTransactionId()).thenReturn(nextTxId);
            TransactionAppender appender = Life.add(new BatchingTransactionAppender(_logFiles, NO_ROTATION, _positionCache, _transactionIdStore, BYPASS, _databaseHealth));

            // WHEN
//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
//ORIGINAL LINE: final byte[] additionalHeader = new byte[]{1, 2, 5};
            sbyte[]    additionalHeader             = new sbyte[] { 1, 2, 5 };
            const int  masterId                     = 2;
            int        authorId                     = 1;
            const long timeStarted                  = 12345;
            long       latestCommittedTxWhenStarted = nextTxId - 5;
            long       timeCommitted                = timeStarted + 10;
            PhysicalTransactionRepresentation transactionRepresentation = new PhysicalTransactionRepresentation(SingleCreateNodeCommand(0));

            transactionRepresentation.SetHeader(additionalHeader, masterId, authorId, timeStarted, latestCommittedTxWhenStarted, timeCommitted, -1);

            LogEntryStart  start  = new LogEntryStart(0, 0, 0L, latestCommittedTxWhenStarted, null, LogPosition.UNSPECIFIED);
            LogEntryCommit commit = new LogEntryCommit(nextTxId, 0L);
            CommittedTransactionRepresentation transaction = new CommittedTransactionRepresentation(start, transactionRepresentation, commit);

            appender.Append(new TransactionToApply(transactionRepresentation, transaction.CommitEntry.TxId), _logAppendEvent);

            // THEN
            LogEntryReader <ReadableLogChannel> logEntryReader = new VersionAwareLogEntryReader <ReadableLogChannel>();

            using (PhysicalTransactionCursor <ReadableLogChannel> reader = new PhysicalTransactionCursor <ReadableLogChannel>(_channel, logEntryReader))
            {
                reader.Next();
                TransactionRepresentation result = reader.Get().TransactionRepresentation;
                assertArrayEquals(additionalHeader, result.AdditionalHeader());
                assertEquals(masterId, result.MasterId);
                assertEquals(authorId, result.AuthorId);
                assertEquals(timeStarted, result.TimeStarted);
                assertEquals(timeCommitted, result.TimeCommitted);
                assertEquals(latestCommittedTxWhenStarted, result.LatestCommittedTxWhenStarted);
            }
        }
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void shouldAppendBatchOfTransactions() throws Exception
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        public virtual void ShouldAppendBatchOfTransactions()
        {
            // GIVEN
            when(_logFile.Writer).thenReturn(_channel);
            TransactionAppender appender = Life.add(CreateTransactionAppender());

            when(_transactionIdStore.nextCommittingTransactionId()).thenReturn(2L, 3L, 4L);
            TransactionToApply batch = BatchOf(Transaction(SingleCreateNodeCommand(0), new sbyte[0], 0, 0, 0, 1, 0), Transaction(SingleCreateNodeCommand(1), new sbyte[0], 0, 0, 0, 1, 0), Transaction(SingleCreateNodeCommand(2), new sbyte[0], 0, 0, 0, 1, 0));

            // WHEN
            appender.Append(batch, _logAppendEvent);

            // THEN
            TransactionToApply tx = batch;

            assertEquals(2L, tx.TransactionId());
            tx = tx.Next();
            assertEquals(3L, tx.TransactionId());
            tx = tx.Next();
            assertEquals(4L, tx.TransactionId());
            assertNull(tx.Next());
        }
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void shouldNotAppendCommittedTransactionsWhenTooFarAhead()
        public virtual void ShouldNotAppendCommittedTransactionsWhenTooFarAhead()
        {
            // GIVEN
            InMemoryClosableChannel channel = new InMemoryClosableChannel();

            when(_logFile.Writer).thenReturn(channel);
            TransactionAppender appender = Life.add(CreateTransactionAppender());

            // WHEN
//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
//ORIGINAL LINE: final byte[] additionalHeader = new byte[]{1, 2, 5};
            sbyte[]    additionalHeader             = new sbyte[] { 1, 2, 5 };
            const int  masterId                     = 2;
            int        authorId                     = 1;
            const long timeStarted                  = 12345;
            long       latestCommittedTxWhenStarted = 4545;
            long       timeCommitted                = timeStarted + 10;
            PhysicalTransactionRepresentation transactionRepresentation = new PhysicalTransactionRepresentation(SingleCreateNodeCommand(0));

            transactionRepresentation.SetHeader(additionalHeader, masterId, authorId, timeStarted, latestCommittedTxWhenStarted, timeCommitted, -1);

            when(_transactionIdStore.LastCommittedTransactionId).thenReturn(latestCommittedTxWhenStarted);

            LogEntryStart  start  = new LogEntryStart(0, 0, 0L, latestCommittedTxWhenStarted, null, LogPosition.UNSPECIFIED);
            LogEntryCommit commit = new LogEntryCommit(latestCommittedTxWhenStarted + 2, 0L);
            CommittedTransactionRepresentation transaction = new CommittedTransactionRepresentation(start, transactionRepresentation, commit);

            try
            {
                appender.Append(new TransactionToApply(transaction.TransactionRepresentation, transaction.CommitEntry.TxId), _logAppendEvent);
                fail("should have thrown");
            }
            catch (Exception e)
            {
                assertThat(e.Message, containsString("to be applied, but appending it ended up generating an"));
            }
        }
Exemplo n.º 12
0
 public TransactionRepresentationCommitProcess(TransactionAppender appender, StorageEngine storageEngine)
 {
     this._appender      = appender;
     this._storageEngine = storageEngine;
 }
Exemplo n.º 13
0
 /// <summary>
 /// Called by the DataSourceManager during start.
 /// </summary>
 public virtual void RegisterCommitProcessDependencies(TransactionAppender appender, StorageEngine applier)
 {
     _localCommit = new TransactionRepresentationCommitProcess(appender, applier);
 }
Exemplo n.º 14
0
 internal StubTransactionCommitProcess(TransactionAppender appender, StorageEngine storageEngine) : base(appender, storageEngine)
 {
 }
Exemplo n.º 15
0
 internal Worker(TransactionAppender transactionAppender, TransactionRepresentationFactory factory, System.Func <bool> condition)
 {
     this._transactionAppender = transactionAppender;
     this._factory             = factory;
     this._condition           = condition;
 }