//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 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));
            }
        }
Exemple #3
0
//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());
                }
            }
        }
Exemple #4
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();
                }
            }
        }
Exemple #5
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 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());
        }
//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
        }