예제 #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);
            }
        }
예제 #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));
            }
        }
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void shouldSeeCorrectPositionEvenBeforeEmptyingDataIntoChannel() throws Exception
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        public virtual void ShouldSeeCorrectPositionEvenBeforeEmptyingDataIntoChannel()
        {
            // GIVEN
//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
//ORIGINAL LINE: final java.io.File file = new java.io.File(directory.directory(), "file");
            File         file         = new File(Directory.directory(), "file");
            StoreChannel storeChannel = FileSystemRule.get().open(file, OpenMode.READ_WRITE);
            PhysicalLogVersionedStoreChannel      versionedStoreChannel = new PhysicalLogVersionedStoreChannel(storeChannel, 1, ( sbyte )-1);
            PositionAwarePhysicalFlushableChannel channel = new PositionAwarePhysicalFlushableChannel(versionedStoreChannel);
            LogPositionMarker positionMarker  = new LogPositionMarker();
            LogPosition       initialPosition = channel.GetCurrentPosition(positionMarker).newPosition();

            // WHEN
            channel.PutLong(67);
            channel.PutInt(1234);
            LogPosition positionAfterSomeData = channel.GetCurrentPosition(positionMarker).newPosition();

            // THEN
            assertEquals(12, positionAfterSomeData.ByteOffset - initialPosition.ByteOffset);
            channel.Dispose();
        }
예제 #4
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());
        }
예제 #5
0
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
//ORIGINAL LINE: public LogPositionMarker getCurrentPosition(LogPositionMarker positionMarker) throws java.io.IOException
        public override LogPositionMarker GetCurrentPosition(LogPositionMarker positionMarker)
        {
            positionMarker.Mark(Channel.Version, Position());
            return(positionMarker);
        }
//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
        }
예제 #7
0
 public override LogPositionMarker GetCurrentPosition(LogPositionMarker positionMarker)
 {
     positionMarker.Mark(0, Buffer.position());
     return(positionMarker);
 }
예제 #8
0
 public override LogPositionMarker GetCurrentPosition(LogPositionMarker positionMarker)
 {
     // Hmm, this would be for the writer.
     return(_writer.getCurrentPosition(positionMarker));
 }