Esempio 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);
            }
        }
Esempio 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));
            }
        }
Esempio n. 3
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());
        }
//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
        }