//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes: //ORIGINAL LINE: @Test public void shouldKernelPanicIfNotAbleToWriteACheckPoint() throws Throwable //JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#: public virtual void ShouldKernelPanicIfNotAbleToWriteACheckPoint() { // Given IOException ioex = new IOException("boom!"); FlushablePositionAwareChannel channel = mock(typeof(FlushablePositionAwareChannel), RETURNS_MOCKS); when(channel.Put(anyByte())).thenReturn(channel); when(channel.PutLong(anyLong())).thenThrow(ioex); when(channel.Put(anyByte())).thenThrow(ioex); when(_logFile.Writer).thenReturn(channel); BatchingTransactionAppender appender = Life.add(CreateTransactionAppender()); // When try { appender.CheckPoint(new LogPosition(0L, 0L), LogCheckPointEvent.NULL); fail("should have thrown "); } catch (IOException ex) { assertEquals(ioex, ex); } // Then verify(_databaseHealth, times(1)).panic(ioex); }
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes: //ORIGINAL LINE: @Test public void shouldWriteSomeDataIntoTheLog() throws Exception //JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#: public virtual void ShouldWriteSomeDataIntoTheLog() { // GIVEN string name = "log"; FileSystemAbstraction fs = _fileSystemRule.get(); LogFiles logFiles = LogFilesBuilder.builder(_directory.databaseLayout(), fs).withTransactionIdStore(_transactionIdStore).withLogVersionRepository(_logVersionRepository).build(); _life.start(); _life.add(logFiles); // WHEN FlushablePositionAwareChannel writer = logFiles.LogFile.Writer; LogPositionMarker positionMarker = new LogPositionMarker(); writer.GetCurrentPosition(positionMarker); int intValue = 45; long longValue = 4854587; writer.PutInt(intValue); writer.PutLong(longValue); writer.PrepareForFlush().flush(); // THEN using (ReadableClosableChannel reader = logFiles.LogFile.getReader(positionMarker.NewPosition())) { assertEquals(intValue, reader.Int); assertEquals(longValue, reader.Long); } }
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#: //ORIGINAL LINE: private void appendCorruptedTransaction() throws java.io.IOException private void AppendCorruptedTransaction() { FlushablePositionAwareChannel channel = _logFile.Writer; TransactionLogWriter writer = new TransactionLogWriter(new CorruptedLogEntryWriter(channel)); writer.Append(Tx(_random.intBetween(100, 1000)), ++_txId); }
//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 WARNING: Method 'throws' clauses are not available in C#: //ORIGINAL LINE: private static void appendCheckpoint(org.neo4j.kernel.impl.transaction.log.files.LogFiles logFiles, org.neo4j.kernel.recovery.LogTailScanner tailScanner) throws java.io.IOException private static void AppendCheckpoint(LogFiles logFiles, LogTailScanner tailScanner) { using (Lifespan lifespan = new Lifespan(logFiles)) { FlushablePositionAwareChannel writer = logFiles.LogFile.Writer; TransactionLogWriter transactionLogWriter = new TransactionLogWriter(new LogEntryWriter(writer)); transactionLogWriter.CheckPoint(tailScanner.TailInformation.lastCheckPoint.LogPosition); writer.PrepareForFlush().flush(); } }
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes: //ORIGINAL LINE: @Before public void before() throws java.io.IOException //JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#: public virtual void Before() { _lastCommittedTxId = new AtomicLong(BASE_TX_ID); _logVersionRepository = new SimpleLogVersionRepository(); _logFiles = LogFilesBuilder.builder(_directory.databaseLayout(), _fs).withLogVersionRepository(_logVersionRepository).withTransactionIdStore(new SimpleTransactionIdStore()).build(); _life.add(_logFiles); _logFile = _logFiles.LogFile; _writer = _logFile.Writer; _transactionLogWriter = new TransactionLogWriter(new LogEntryWriter(_writer)); _monitor = new VerifyingMonitor(); }
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#: //ORIGINAL LINE: private void writeTransactions(int transactionCount, int minTransactionSize, int maxTransactionSize) throws java.io.IOException private void WriteTransactions(int transactionCount, int minTransactionSize, int maxTransactionSize) { FlushablePositionAwareChannel channel = _logFile.Writer; TransactionLogWriter writer = new TransactionLogWriter(new LogEntryWriter(channel)); for (int i = 0; i < transactionCount; i++) { writer.Append(Tx(_random.intBetween(minTransactionSize, maxTransactionSize)), ++_txId); } channel.PrepareForFlush().flush(); // Don't close the channel, LogFile owns it }
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#: //ORIGINAL LINE: private void addRandomBytesToLastLogFile(System.Func<sbyte> byteSource) throws java.io.IOException private void AddRandomBytesToLastLogFile(System.Func <sbyte> byteSource) { using (Lifespan lifespan = new Lifespan()) { LogFile transactionLogFile = _logFiles.LogFile; lifespan.Add(_logFiles); FlushablePositionAwareChannel logFileWriter = transactionLogFile.Writer; for (int i = 0; i < 10; i++) { logFileWriter.Put(byteSource()); } } }
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#: //ORIGINAL LINE: private void generateTransactionLogFiles(org.neo4j.kernel.impl.transaction.log.files.LogFiles logFiles) throws java.io.IOException private void GenerateTransactionLogFiles(LogFiles logFiles) { LogFile logFile = logFiles.LogFile; FlushablePositionAwareChannel writer = logFile.Writer; for (sbyte i = 0; i < 107; i++) { writer.Put(i); writer.PrepareForFlush(); if (logFile.RotationNeeded()) { logFile.Rotate(); } } }
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes: //ORIGINAL LINE: @Test public void shouldReadOlderLogs() throws Exception //JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#: public virtual void ShouldReadOlderLogs() { // GIVEN FileSystemAbstraction fs = _fileSystemRule.get(); LogFiles logFiles = LogFilesBuilder.builder(_directory.databaseLayout(), fs).withTransactionIdStore(_transactionIdStore).withLogVersionRepository(_logVersionRepository).build(); _life.start(); _life.add(logFiles); // WHEN LogFile logFile = logFiles.LogFile; FlushablePositionAwareChannel writer = logFile.Writer; LogPositionMarker positionMarker = new LogPositionMarker(); writer.GetCurrentPosition(positionMarker); LogPosition position1 = positionMarker.NewPosition(); int intValue = 45; long longValue = 4854587; sbyte[] someBytes = someBytes(40); writer.PutInt(intValue); writer.PutLong(longValue); writer.Put(someBytes, someBytes.Length); writer.PrepareForFlush().flush(); writer.GetCurrentPosition(positionMarker); LogPosition position2 = positionMarker.NewPosition(); long longValue2 = 123456789L; writer.PutLong(longValue2); writer.Put(someBytes, someBytes.Length); writer.PrepareForFlush().flush(); // THEN using (ReadableClosableChannel reader = logFile.GetReader(position1)) { assertEquals(intValue, reader.Int); assertEquals(longValue, reader.Long); assertArrayEquals(someBytes, ReadBytes(reader, 40)); } using (ReadableClosableChannel reader = logFile.GetReader(position2)) { assertEquals(longValue2, reader.Long); assertArrayEquals(someBytes, ReadBytes(reader, 40)); } }
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#: //ORIGINAL LINE: private void addCorruptedCommandsToLastLogFile() throws java.io.IOException private void AddCorruptedCommandsToLastLogFile() { PositiveLogFilesBasedLogVersionRepository versionRepository = new PositiveLogFilesBasedLogVersionRepository(_logFiles); LogFiles internalLogFiles = LogFilesBuilder.builder(_directory.databaseLayout(), _fileSystemRule).withLogVersionRepository(versionRepository).withTransactionIdStore(new SimpleTransactionIdStore()).build(); using (Lifespan lifespan = new Lifespan(internalLogFiles)) { LogFile transactionLogFile = internalLogFiles.LogFile; FlushablePositionAwareChannel channel = transactionLogFile.Writer; TransactionLogWriter writer = new TransactionLogWriter(new CorruptedLogEntryWriter(channel)); ICollection <StorageCommand> commands = new List <StorageCommand>(); commands.Add(new Command.PropertyCommand(new PropertyRecord(1), new PropertyRecord(2))); commands.Add(new Command.NodeCommand(new NodeRecord(2), new NodeRecord(3))); PhysicalTransactionRepresentation transaction = new PhysicalTransactionRepresentation(commands); writer.Append(transaction, 1000); } }
//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 shouldBeAbleToWriteACheckPoint() throws Throwable //JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#: public virtual void ShouldBeAbleToWriteACheckPoint() { // Given FlushablePositionAwareChannel channel = mock(typeof(FlushablePositionAwareChannel), RETURNS_MOCKS); Flushable flushable = mock(typeof(Flushable)); when(channel.PrepareForFlush()).thenReturn(flushable); when(channel.PutLong(anyLong())).thenReturn(channel); when(_logFile.Writer).thenReturn(channel); BatchingTransactionAppender appender = Life.add(CreateTransactionAppender()); // When appender.CheckPoint(new LogPosition(1L, 2L), LogCheckPointEvent.NULL); // Then verify(channel, times(1)).putLong(1L); verify(channel, times(1)).putLong(2L); verify(channel, times(1)).prepareForFlush(); verify(flushable, times(1)).flush(); verify(_databaseHealth, never()).panic(any()); }
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#: //ORIGINAL LINE: private void appendCheckpoint(org.neo4j.kernel.impl.transaction.log.entry.LogEntryVersion logVersion) throws java.io.IOException private void AppendCheckpoint(LogEntryVersion logVersion) { PageCache pageCache = _pageCacheRule.getPageCache(_fs); VersionAwareLogEntryReader <ReadableClosablePositionAwareChannel> logEntryReader = new VersionAwareLogEntryReader <ReadableClosablePositionAwareChannel>(); LogFiles logFiles = LogFilesBuilder.activeFilesBuilder(_storeDirectory.databaseLayout(), _fs, pageCache).withLogEntryReader(logEntryReader).build(); LogTailScanner tailScanner = new LogTailScanner(logFiles, logEntryReader, new Monitors()); LogTailScanner.LogTailInformation tailInformation = tailScanner.TailInformation; using (Lifespan lifespan = new Lifespan(logFiles)) { FlushablePositionAwareChannel channel = logFiles.LogFile.Writer; LogPosition logPosition = tailInformation.LastCheckPoint.LogPosition; // Fake record channel.Put(logVersion.byteCode()).put(CHECK_POINT).putLong(logPosition.LogVersion).putLong(logPosition.ByteOffset); channel.PrepareForFlush().flush(); } }
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes: //ORIGINAL LINE: @Test public void shouldVisitLogFile() throws Exception //JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#: public virtual void ShouldVisitLogFile() { // GIVEN string name = "log"; FileSystemAbstraction fs = _fileSystemRule.get(); LogFiles logFiles = LogFilesBuilder.builder(_directory.databaseLayout(), fs).withTransactionIdStore(_transactionIdStore).withLogVersionRepository(_logVersionRepository).build(); _life.start(); _life.add(logFiles); LogFile logFile = logFiles.LogFile; FlushablePositionAwareChannel writer = logFile.Writer; LogPositionMarker mark = new LogPositionMarker(); writer.GetCurrentPosition(mark); for (int i = 0; i < 5; i++) { writer.Put(( sbyte )i); } writer.PrepareForFlush(); // WHEN/THEN //JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final': //ORIGINAL LINE: final java.util.concurrent.atomic.AtomicBoolean called = new java.util.concurrent.atomic.AtomicBoolean(); AtomicBoolean called = new AtomicBoolean(); logFile.Accept(channel => { for (int i = 0; i < 5; i++) { assertEquals(( sbyte )i, channel.get()); } called.set(true); return(true); }, mark.NewPosition()); assertTrue(called.get()); }
private LogCreator LogFile(params Entry[] entries) { return((logVersion, positions) => { try { AtomicLong lastTxId = new AtomicLong(); _logVersionRepository.CurrentLogVersion = logVersion; LifeSupport logFileLife = new LifeSupport(); logFileLife.start(); logFileLife.add(_logFiles); LogFile logFile = _logFiles.LogFile; try { FlushablePositionAwareChannel writeChannel = logFile.Writer; LogPositionMarker positionMarker = new LogPositionMarker(); LogEntryWriter writer = new LogEntryWriter(writeChannel); foreach (Entry entry in entries) { LogPosition currentPosition = writeChannel.getCurrentPosition(positionMarker).newPosition(); positions.put(entry, currentPosition); if (entry is StartEntry) { writer.writeStartEntry(0, 0, 0, 0, new sbyte[0]); } else if (entry is CommitEntry) { CommitEntry commitEntry = ( CommitEntry )entry; writer.writeCommitEntry(commitEntry.TxId, 0); lastTxId.set(commitEntry.TxId); } else if (entry is CheckPointEntry) { CheckPointEntry checkPointEntry = ( CheckPointEntry )entry; Entry target = checkPointEntry.WithPositionOfEntry; LogPosition logPosition = target != null?positions.get(target) : currentPosition; Debug.Assert(logPosition != null, "No registered log position for " + target); writer.writeCheckPointEntry(logPosition); } else if (entry is PositionEntry) { // Don't write anything, this entry is just for registering a position so that // another CheckPointEntry can refer to it } else { throw new System.ArgumentException("Unknown entry " + entry); } } } finally { logFileLife.shutdown(); } } catch (IOException e) { throw new UncheckedIOException(e); } }); }
public override void Start() { this._writer = _logFile.Writer; this._indexCommandDetector = new IndexCommandDetector(); this._transactionLogWriter = new TransactionLogWriter(new LogEntryWriter(_writer)); }
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes: //ORIGINAL LINE: @Test public void shouldNotSeeEmptyLogFileWhenReadingTransactionStream() throws Exception //JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#: public virtual void ShouldNotSeeEmptyLogFileWhenReadingTransactionStream() { // GIVEN LogVersionRepository logVersionRepository = new SimpleLogVersionRepository(); LogFiles logFiles = LogFilesBuilder.builder(_directory.databaseLayout(), _fileSystemRule.get()).withLogVersionRepository(logVersionRepository).withTransactionIdStore(new SimpleTransactionIdStore()).build(); _life.add(logFiles); LogFile logFile = logFiles.LogFile; FlushablePositionAwareChannel writer = logFile.Writer; LogPositionMarker startPosition = new LogPositionMarker(); writer.GetCurrentPosition(startPosition); // WHEN AtomicBoolean end = new AtomicBoolean(); sbyte[] dataChunk = new sbyte[100]; // one thread constantly writing to and rotating the channel AtomicInteger rotations = new AtomicInteger(); System.Threading.CountdownEvent startSignal = new System.Threading.CountdownEvent(1); Future <Void> writeFuture = _t2.execute(ignored => { ThreadLocalRandom random = ThreadLocalRandom.current(); startSignal.Signal(); while (!end.get()) { writer.Put(dataChunk, random.Next(1, dataChunk.Length)); if (logFile.RotationNeeded()) { logFile.Rotate(); // Let's just close the gap to the reader so that it gets closer to the "hot zone" // where the rotation happens. writer.GetCurrentPosition(startPosition); rotations.incrementAndGet(); } } return(null); }); assertTrue(startSignal.await(10, SECONDS)); // one thread reading through the channel long maxEndTime = currentTimeMillis() + _limitTime; int reads = 0; try { for ( ; currentTimeMillis() < maxEndTime && reads < LIMIT_READS && rotations.get() < LIMIT_ROTATIONS; reads++) { using (ReadableLogChannel reader = logFile.GetReader(startPosition.NewPosition())) { Deplete(reader); } } } finally { end.set(true); writeFuture.get(); } // THEN simply getting here means this was successful }