Пример #1
0
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
//ORIGINAL LINE: private void applyUpTo(long applyUpToIndex) throws Exception
        private void ApplyUpTo(long applyUpToIndex)
        {
            using (InFlightLogEntryReader logEntrySupplier = new InFlightLogEntryReader(_raftLog, _inFlightCache, true))
            {
                for (long logIndex = _applierState.lastApplied + 1; _applierState.keepRunning && logIndex <= applyUpToIndex; logIndex++)
                {
                    RaftLogEntry entry = logEntrySupplier.Get(logIndex);
                    if (entry == null)
                    {
                        throw new System.InvalidOperationException(format("Committed log entry at index %d must exist.", logIndex));
                    }

                    if (entry.Content() is DistributedOperation)
                    {
                        DistributedOperation distributedOperation = ( DistributedOperation )entry.Content();
                        _progressTracker.trackReplication(distributedOperation);
                        _batcher.add(logIndex, distributedOperation);
                    }
                    else
                    {
                        _batcher.flush();
                        // since this last entry didn't get in the batcher we need to update the lastApplied:
                        _applierState.lastApplied = logIndex;
                    }
                }
                _batcher.flush();
            }
        }
Пример #2
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void shouldNeverUseMapAgainAfterHavingFallenBackToTheRaftLog() throws Exception
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        public virtual void ShouldNeverUseMapAgainAfterHavingFallenBackToTheRaftLog()
        {
            // given
            InFlightLogEntryReader reader = new InFlightLogEntryReader(_raftLog, _inFlightCache, ClearCache);

            StartingFromIndexReturnEntries(_inFlightCache, _logIndex, _entry, null, mock(typeof(RaftLogEntry)));
            RaftLogEntry[] entries = new RaftLogEntry[] { _entry, mock(typeof(RaftLogEntry)), mock(typeof(RaftLogEntry)) };
            StartingFromIndexReturnEntries(_raftLog, _logIndex + 1, entries[1], entries[2]);

            for (int offset = 0; offset < 3; offset++)
            {
                // when
                RaftLogEntry raftLogEntry = reader.Get(offset + _logIndex);

                // then
                assertEquals(entries[offset], raftLogEntry);

                if (offset <= 1)
                {
                    verify(_inFlightCache).get(offset + _logIndex);
                }

                if (offset == 1)
                {
                    verify(_raftLog).getEntryCursor(offset + _logIndex);
                }

                AssertCacheIsUpdated(_inFlightCache, offset + _logIndex);
            }

            verifyNoMoreInteractions(_inFlightCache);
            verifyNoMoreInteractions(_raftLog);
        }
Пример #3
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void shouldUseTheCacheWhenTheIndexIsPresent() throws Exception
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        public virtual void ShouldUseTheCacheWhenTheIndexIsPresent()
        {
            // given
            InFlightLogEntryReader reader = new InFlightLogEntryReader(_raftLog, _inFlightCache, ClearCache);

            StartingFromIndexReturnEntries(_inFlightCache, _logIndex, _entry);
            StartingFromIndexReturnEntries(_raftLog, -1, null);

            // when
            RaftLogEntry raftLogEntry = reader.Get(_logIndex);

            // then
            assertEquals(_entry, raftLogEntry);
            verify(_inFlightCache).get(_logIndex);
            AssertCacheIsUpdated(_inFlightCache, _logIndex);
            verifyNoMoreInteractions(_inFlightCache);
            verifyZeroInteractions(_raftLog);
        }