Exemple #1
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void applyTo()
        public virtual void ApplyTo()
        {
            //Test that truncate commands correctly remove entries from the cache.

            //given
            AssertableLogProvider logProvider = new AssertableLogProvider();
            Log  log       = logProvider.getLog(this.GetType());
            long fromIndex = 2L;
            TruncateLogCommand truncateLogCommand = new TruncateLogCommand(fromIndex);
            InFlightCache      inFlightCache      = new ConsecutiveInFlightCache();

            inFlightCache.Put(0L, new RaftLogEntry(0L, valueOf(0)));
            inFlightCache.Put(1L, new RaftLogEntry(1L, valueOf(1)));
            inFlightCache.Put(2L, new RaftLogEntry(2L, valueOf(2)));
            inFlightCache.Put(3L, new RaftLogEntry(3L, valueOf(3)));

            //when
            truncateLogCommand.ApplyTo(inFlightCache, log);

            //then
            assertNotNull(inFlightCache.Get(0L));
            assertNotNull(inFlightCache.Get(1L));
            assertNull(inFlightCache.Get(2L));
            assertNull(inFlightCache.Get(3L));

            logProvider.AssertAtLeastOnce(inLog(this.GetType()).debug("Start truncating in-flight-map from index %d. Current map:%n%s", fromIndex, inFlightCache));
        }
Exemple #2
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void shouldNotCacheInFlightEntriesUntilAfterRecovery() throws Exception
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        public virtual void ShouldNotCacheInFlightEntriesUntilAfterRecovery()
        {
            // given
            FakeClock            fakeClock     = Clocks.fakeClock();
            InFlightCache        inFlightCache = new ConsecutiveInFlightCache(10, 10000, InFlightCacheMonitor.VOID, false);
            OnDemandTimerService timerService  = new OnDemandTimerService(fakeClock);
            RaftMachine          raft          = (new RaftMachineBuilder(_myself, 3, RaftTestMemberSetBuilder.INSTANCE)).timerService(timerService).clock(fakeClock).raftLog(_raftLog).inFlightCache(inFlightCache).build();

            _raftLog.append(new RaftLogEntry(0, new MemberIdSet(asSet(_myself, _member1, _member2))));

            // when
            raft.Handle(appendEntriesRequest().from(_member1).prevLogIndex(0).prevLogTerm(0).leaderTerm(0).logEntry(new RaftLogEntry(0, _data1)).build());

            // then
            assertEquals(_data1, readLogEntry(_raftLog, 1).content());
            assertNull(inFlightCache.Get(1L));

            // when
            raft.PostRecoveryActions();
            raft.Handle(appendEntriesRequest().from(_member1).prevLogIndex(1).prevLogTerm(0).leaderTerm(0).logEntry(new RaftLogEntry(0, _data2)).build());

            // then
            assertEquals(_data2, readLogEntry(_raftLog, 2).content());
            assertEquals(_data2, inFlightCache.Get(2L).content());
        }
Exemple #3
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void shouldTruncateWithGaps()
        public virtual void ShouldTruncateWithGaps()
        {
            //given
            long fromIndex = 1L;
            TruncateLogCommand truncateLogCommand = new TruncateLogCommand(fromIndex);

            InFlightCache inFlightCache = new ConsecutiveInFlightCache();

            inFlightCache.Put(0L, new RaftLogEntry(0L, valueOf(0)));
            inFlightCache.Put(2L, new RaftLogEntry(1L, valueOf(1)));
            inFlightCache.Put(4L, new RaftLogEntry(2L, valueOf(2)));

            truncateLogCommand.ApplyTo(inFlightCache, NullLog.Instance);

            inFlightCache.Put(1L, new RaftLogEntry(3L, valueOf(1)));
            inFlightCache.Put(2L, new RaftLogEntry(4L, valueOf(2)));

            assertNotNull(inFlightCache.Get(1L));
            assertNotNull(inFlightCache.Get(2L));
        }