//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void shouldParserStartEntry() throws java.io.IOException
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        public virtual void ShouldParserStartEntry()
        {
            // given
//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
//ORIGINAL LINE: final LogEntryStart start = new LogEntryStart(version, 1, 2, 3, 4, new byte[]{5}, position);
            LogEntryStart start = new LogEntryStart(_version, 1, 2, 3, 4, new sbyte[] { 5 }, _position);
//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
//ORIGINAL LINE: final org.neo4j.kernel.impl.transaction.log.InMemoryClosableChannel channel = new org.neo4j.kernel.impl.transaction.log.InMemoryClosableChannel();
            InMemoryClosableChannel channel = new InMemoryClosableChannel();

            channel.PutInt(start.MasterId);
            channel.PutInt(start.LocalId);
            channel.PutLong(start.TimeWritten);
            channel.PutLong(start.LastCommittedTxWhenTransactionStarted);
            channel.PutInt(start.AdditionalHeader.Length);
            channel.Put(start.AdditionalHeader, start.AdditionalHeader.Length);

            channel.GetCurrentPosition(_marker);

            // when
//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
//ORIGINAL LINE: final LogEntryParser parser = version.entryParser(LogEntryByteCodes.TX_START);
            LogEntryParser parser = _version.entryParser(LogEntryByteCodes.TxStart);
//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
//ORIGINAL LINE: final LogEntry logEntry = parser.parse(version, channel, marker, commandReader);
            LogEntry logEntry = parser.parse(_version, channel, _marker, _commandReader);

            // then
            assertEquals(start, logEntry);
            assertFalse(parser.skip());
        }
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
//ORIGINAL LINE: public boolean visit(ReadableClosablePositionAwareChannel channel) throws java.io.IOException
            public override bool Visit(ReadableClosablePositionAwareChannel channel)
            {
                LogEntry      logEntry;
                LogEntryStart startEntry = null;

                while ((logEntry = LogEntryReader.readLogEntry(channel)) != null)
                {
                    switch (logEntry.Type)
                    {
                    case TX_START:
                        startEntry = logEntry.As();
                        break;

                    case TX_COMMIT:
                        LogEntryCommit commit = logEntry.As();
                        if (commit.TxId == StartTransactionId)
                        {
                            StartEntryForFoundTransaction = startEntry;
                            CommitTimestamp = commit.TimeWritten;
                            return(false);
                        }

                    default:                              // just skip commands
                        break;
                    }
                }
                return(true);
            }
Пример #3
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void shouldReadAStartLogEntry() throws java.io.IOException
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        public virtual void ShouldReadAStartLogEntry()
        {
            // given
            LogEntryVersion version = LogEntryVersion.CURRENT;
//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
//ORIGINAL LINE: final LogEntryStart start = new LogEntryStart(version, 1, 2, 3, 4, new byte[]{5}, new org.neo4j.kernel.impl.transaction.log.LogPosition(0, 31));
            LogEntryStart start = new LogEntryStart(version, 1, 2, 3, 4, new sbyte[] { 5 }, new LogPosition(0, 31));
//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
//ORIGINAL LINE: final org.neo4j.kernel.impl.transaction.log.InMemoryClosableChannel channel = new org.neo4j.kernel.impl.transaction.log.InMemoryClosableChannel();
            InMemoryClosableChannel channel = new InMemoryClosableChannel();

            channel.Put(version.byteCode());                 // version
            channel.Put(LogEntryByteCodes.TxStart);          // type
            channel.PutInt(start.MasterId);
            channel.PutInt(start.LocalId);
            channel.PutLong(start.TimeWritten);
            channel.PutLong(start.LastCommittedTxWhenTransactionStarted);
            channel.PutInt(start.AdditionalHeader.Length);
            channel.Put(start.AdditionalHeader, start.AdditionalHeader.Length);

            // when
//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
//ORIGINAL LINE: final LogEntry logEntry = logEntryReader.readLogEntry(channel);
            LogEntry logEntry = _logEntryReader.readLogEntry(channel);

            // then
            assertEquals(start, logEntry);
        }
Пример #4
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);
        }
Пример #5
0
        public override bool Equals(object o)
        {
            if (this == o)
            {
                return(true);
            }
            if (o == null || this.GetType() != o.GetType())
            {
                return(false);
            }

            LogEntryStart start = ( LogEntryStart )o;

            return(_authorId == start._authorId && _lastCommittedTxWhenTransactionStarted == start._lastCommittedTxWhenTransactionStarted && _masterId == start._masterId && _timeWritten == start._timeWritten && Arrays.Equals(_additionalHeader, start._additionalHeader) && _startPosition.Equals(start._startPosition));
        }
Пример #6
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 LogPosition getAndCacheFoundLogPosition(TransactionMetadataCache transactionMetadataCache) throws NoSuchTransactionException
            public virtual LogPosition GetAndCacheFoundLogPosition(TransactionMetadataCache transactionMetadataCache)
            {
                if (StartEntryForFoundTransaction == null)
                {
                    throw new NoSuchTransactionException(StartTransactionId);
                }
                transactionMetadataCache.CacheTransactionMetadata(StartTransactionId, StartEntryForFoundTransaction.StartPosition, StartEntryForFoundTransaction.MasterId, StartEntryForFoundTransaction.LocalId, LogEntryStart.checksum(StartEntryForFoundTransaction), CommitTimestamp);
                return(StartEntryForFoundTransaction.StartPosition);
            }
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
//ORIGINAL LINE: public org.neo4j.kernel.impl.transaction.log.TransactionMetadataCache.TransactionMetadata getMetadataFor(long transactionId) throws java.io.IOException
        public override TransactionMetadata GetMetadataFor(long transactionId)
        {
            if (transactionId <= BASE_TX_ID)
            {
                return(_metadataForEmptyStore);
            }

            TransactionMetadata transactionMetadata = _transactionMetadataCache.getTransactionMetadata(transactionId);

            if (transactionMetadata == null)
            {
                using (IOCursor <CommittedTransactionRepresentation> cursor = GetTransactions(transactionId))
                {
                    while (cursor.next())
                    {
                        CommittedTransactionRepresentation tx = cursor.get();
                        LogEntryCommit      commitEntry       = tx.CommitEntry;
                        long                committedTxId     = commitEntry.TxId;
                        long                timeWritten       = commitEntry.TimeWritten;
                        TransactionMetadata metadata          = _transactionMetadataCache.cacheTransactionMetadata(committedTxId, tx.StartEntry.StartPosition, tx.StartEntry.MasterId, tx.StartEntry.LocalId, LogEntryStart.checksum(tx.StartEntry), timeWritten);
                        if (committedTxId == transactionId)
                        {
                            transactionMetadata = metadata;
                        }
                    }
                }
                if (transactionMetadata == null)
                {
                    throw new NoSuchTransactionException(transactionId);
                }
            }

            return(transactionMetadata);
        }
Пример #9
0
 public static long Checksum(LogEntryStart entry)
 {
     return(Checksum(entry._additionalHeader, entry._masterId, entry._authorId));
 }
Пример #10
0
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
//ORIGINAL LINE: public void writeStartEntry(LogEntryStart entry) throws java.io.IOException
        public virtual void WriteStartEntry(LogEntryStart entry)
        {
            WriteStartEntry(entry.MasterId, entry.LocalId, entry.TimeWritten, entry.LastCommittedTxWhenTransactionStarted, entry.AdditionalHeader);
        }
Пример #11
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void shouldFindTransactionLogPosition() throws java.io.IOException
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        public virtual void ShouldFindTransactionLogPosition()
        {
            // given
//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
//ORIGINAL LINE: final PhysicalLogicalTransactionStore.TransactionPositionLocator locator = new PhysicalLogicalTransactionStore.TransactionPositionLocator(txId, logEntryReader);
            PhysicalLogicalTransactionStore.TransactionPositionLocator locator = new PhysicalLogicalTransactionStore.TransactionPositionLocator(_txId, _logEntryReader);

            when(_logEntryReader.readLogEntry(_channel)).thenReturn(_start, _command, _commit, null);

            // when
//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
//ORIGINAL LINE: final boolean result = locator.visit(channel);
            bool result = locator.Visit(_channel);
//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
//ORIGINAL LINE: final LogPosition position = locator.getAndCacheFoundLogPosition(metadataCache);
            LogPosition position = locator.GetAndCacheFoundLogPosition(_metadataCache);

            // then
            assertFalse(result);
            assertEquals(_startPosition, position);
            verify(_metadataCache, times(1)).cacheTransactionMetadata(_txId, _startPosition, _start.MasterId, _start.LocalId, LogEntryStart.checksum(_start), _commit.TimeWritten);
        }
Пример #12
0
 private void InitializeInstanceFields()
 {
     _start  = new LogEntryStart(0, 0, 0, 0, null, _startPosition);
     _commit = new LogEntryCommit(_txId, DateTimeHelper.CurrentUnixTimeMillis());
 }