Ejemplo n.º 1
0
//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);
            }
        }
Ejemplo n.º 2
0
//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));
            }
        }
Ejemplo n.º 3
0
//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 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
        }
Ejemplo n.º 5
0
//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();
                }
            }
        }
Ejemplo n.º 6
0
//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 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());
        }
Ejemplo n.º 8
0
//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());
        }