Beispiel #1
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void shouldBeAbleToSkipBadLogEntries() throws Exception
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        public virtual void ShouldBeAbleToSkipBadLogEntries()
        {
            // GIVEN
            AcceptingInvalidLogEntryHandler invalidLogEntryHandler = new AcceptingInvalidLogEntryHandler();
            VersionAwareLogEntryReader <ReadableClosablePositionAwareChannel> reader = new VersionAwareLogEntryReader <ReadableClosablePositionAwareChannel>(new RecordStorageCommandReaderFactory(), invalidLogEntryHandler);
            InMemoryClosableChannel channel = new InMemoryClosableChannel(1_000);
            LogEntryWriter          writer  = new LogEntryWriter(channel.Writer());
            long startTime  = currentTimeMillis();
            long commitTime = startTime + 10;

            writer.WriteStartEntry(1, 2, startTime, 3, new sbyte[0]);

            // Write command ...
            int posBefore = channel.WriterPosition();

            writer.Serialize(singletonList(new Command.NodeCommand(new NodeRecord(1), (new NodeRecord(1)).initialize(true, 1, false, 2, 0))));
            int posAfter = channel.WriterPosition();

            // ... which then gets overwritten with invalid data
            channel.PositionWriter(posBefore);
            while (channel.WriterPosition() < posAfter)
            {
                channel.Put(unchecked (( sbyte )0xFF));
            }

            writer.WriteCommitEntry(4, commitTime);
            long secondStartTime = startTime + 100;

            writer.WriteStartEntry(1, 2, secondStartTime, 4, new sbyte[0]);

            // WHEN
            LogEntryStart  readStartEntry       = reader.ReadLogEntry(channel.Reader()).@as();
            LogEntryCommit readCommitEntry      = reader.ReadLogEntry(channel.Reader()).@as();
            LogEntryStart  readSecondStartEntry = reader.ReadLogEntry(channel.Reader()).@as();

            // THEN
            assertEquals(1, readStartEntry.MasterId);
            assertEquals(2, readStartEntry.LocalId);
            assertEquals(startTime, readStartEntry.TimeWritten);

            assertEquals(4, readCommitEntry.TxId);
            assertEquals(commitTime, readCommitEntry.TimeWritten);

            assertEquals(posAfter - posBefore, invalidLogEntryHandler.BytesSkippedConflict);
            assertEquals(posAfter - posBefore, invalidLogEntryHandler.InvalidEntryCalls);

            assertEquals(1, readSecondStartEntry.MasterId);
            assertEquals(2, readSecondStartEntry.LocalId);
            assertEquals(secondStartTime, readSecondStartEntry.TimeWritten);
        }
Beispiel #2
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void shouldBeAbleToSkipBadVersionAndTypeBytesInBetweenLogEntries() throws Exception
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        public virtual void ShouldBeAbleToSkipBadVersionAndTypeBytesInBetweenLogEntries()
        {
            // GIVEN
            AcceptingInvalidLogEntryHandler invalidLogEntryHandler = new AcceptingInvalidLogEntryHandler();
            VersionAwareLogEntryReader <ReadableClosablePositionAwareChannel> reader = new VersionAwareLogEntryReader <ReadableClosablePositionAwareChannel>(new RecordStorageCommandReaderFactory(), invalidLogEntryHandler);
            InMemoryClosableChannel channel = new InMemoryClosableChannel(1_000);
            LogEntryWriter          writer  = new LogEntryWriter(channel.Writer());
            long startTime  = currentTimeMillis();
            long commitTime = startTime + 10;

            writer.WriteStartEntry(1, 2, startTime, 3, new sbyte[0]);
            writer.WriteCommitEntry(4, commitTime);
            channel.Put(( sbyte )127);
            channel.Put(( sbyte )126);
            channel.Put(( sbyte )125);
            long secondStartTime = startTime + 100;

            writer.WriteStartEntry(1, 2, secondStartTime, 4, new sbyte[0]);

            // WHEN
            LogEntryStart  readStartEntry       = reader.ReadLogEntry(channel.Reader()).@as();
            LogEntryCommit readCommitEntry      = reader.ReadLogEntry(channel.Reader()).@as();
            LogEntryStart  readSecondStartEntry = reader.ReadLogEntry(channel.Reader()).@as();

            // THEN
            assertEquals(1, readStartEntry.MasterId);
            assertEquals(2, readStartEntry.LocalId);
            assertEquals(startTime, readStartEntry.TimeWritten);

            assertEquals(4, readCommitEntry.TxId);
            assertEquals(commitTime, readCommitEntry.TimeWritten);

            assertEquals(3, invalidLogEntryHandler.BytesSkippedConflict);
            assertEquals(3, invalidLogEntryHandler.InvalidEntryCalls);

            assertEquals(1, readSecondStartEntry.MasterId);
            assertEquals(2, readSecondStartEntry.LocalId);
            assertEquals(secondStartTime, readSecondStartEntry.TimeWritten);
        }
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
//ORIGINAL LINE: public boolean visit(org.neo4j.storageengine.api.StorageCommand command) throws java.io.IOException
        public override bool Visit(StorageCommand command)
        {
            LogEntryWriter.WriteLogEntryHeader(COMMAND, _channel);
            command.Serialize(_channel);
            return(false);
        }