//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); } }
//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); }
//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")); } }