Exemple #1
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void shouldTruncateOnFirstMismatchAndThenAppendOtherEntries() throws Exception
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        public virtual void ShouldTruncateOnFirstMismatchAndThenAppendOtherEntries()
        {
            _testEntryLog.append(new RaftLogEntry(1, valueOf(99)));
            _testEntryLog.append(new RaftLogEntry(1, valueOf(99)));
            _testEntryLog.append(new RaftLogEntry(1, valueOf(99)));
            _testEntryLog.append(new RaftLogEntry(2, valueOf(99)));
            _testEntryLog.append(new RaftLogEntry(2, valueOf(99)));
            _testEntryLog.append(new RaftLogEntry(2, valueOf(99)));
            _testEntryLog.append(new RaftLogEntry(3, valueOf(99)));
            _testEntryLog.append(new RaftLogEntry(3, valueOf(99)));
            _testEntryLog.append(new RaftLogEntry(3, valueOf(99)));
            _testEntryLog.append(new RaftLogEntry(3, valueOf(99)));
            _testEntryLog.append(new RaftLogEntry(3, valueOf(99)));

            // when instance A as leader
            ReplicatedInteger newData = valueOf(99);

            _raft.handle(appendEntriesRequest().leaderTerm(8).prevLogIndex(0).prevLogTerm(0).logEntry(new RaftLogEntry(1, newData)).logEntry(new RaftLogEntry(1, newData)).logEntry(new RaftLogEntry(1, newData)).logEntry(new RaftLogEntry(4, newData)).logEntry(new RaftLogEntry(4, newData)).logEntry(new RaftLogEntry(5, newData)).logEntry(new RaftLogEntry(5, newData)).logEntry(new RaftLogEntry(6, newData)).logEntry(new RaftLogEntry(6, newData)).logEntry(new RaftLogEntry(6, newData)).build());

            // then
            assertEquals(10, _testEntryLog.appendIndex());
            assertEquals(1, _testEntryLog.readEntryTerm(1));
            assertEquals(1, _testEntryLog.readEntryTerm(2));
            assertEquals(1, _testEntryLog.readEntryTerm(3));
            assertEquals(4, _testEntryLog.readEntryTerm(4));
            assertEquals(4, _testEntryLog.readEntryTerm(5));
            assertEquals(5, _testEntryLog.readEntryTerm(6));
            assertEquals(5, _testEntryLog.readEntryTerm(7));
            assertEquals(6, _testEntryLog.readEntryTerm(8));
            assertEquals(6, _testEntryLog.readEntryTerm(9));
            assertEquals(6, _testEntryLog.readEntryTerm(10));
        }
Exemple #2
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test void stopReplicationOnShutdown() throws InterruptedException
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        internal virtual void StopReplicationOnShutdown()
        {
            // given
            Monitors           monitors           = new Monitors();
            ReplicationMonitor replicationMonitor = mock(typeof(ReplicationMonitor));

            monitors.AddMonitorListener(replicationMonitor);
            CapturingProgressTracker capturedProgress = new CapturingProgressTracker(this);
            CapturingOutbound <Org.Neo4j.causalclustering.core.consensus.RaftMessages_RaftMessage> outbound = new CapturingOutbound <Org.Neo4j.causalclustering.core.consensus.RaftMessages_RaftMessage>();

            RaftReplicator replicator = GetReplicator(outbound, capturedProgress, monitors);

            replicator.OnLeaderSwitch(_leaderInfo);
            ReplicatedInteger content           = ReplicatedInteger.valueOf(5);
            ReplicatingThread replicatingThread = replicatingThread(replicator, content, true);

            // when
            replicatingThread.Start();

            _databaseAvailabilityGuard.shutdown();
            replicatingThread.Join();
            assertThat(replicatingThread.ReplicationException.InnerException, Matchers.instanceOf(typeof(UnavailableException)));

            verify(replicationMonitor, times(1)).startReplication();
            verify(replicationMonitor, atLeast(1)).replicationAttempt();
            verify(replicationMonitor, never()).successfulReplication();
            verify(replicationMonitor, times(1)).failedReplication(any());
        }
Exemple #3
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test void shouldResendAfterTimeout() throws Exception
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        internal virtual void ShouldResendAfterTimeout()
        {
            // given
            Monitors           monitors           = new Monitors();
            ReplicationMonitor replicationMonitor = mock(typeof(ReplicationMonitor));

            monitors.AddMonitorListener(replicationMonitor);
            CapturingProgressTracker capturedProgress = new CapturingProgressTracker(this);
            CapturingOutbound <Org.Neo4j.causalclustering.core.consensus.RaftMessages_RaftMessage> outbound = new CapturingOutbound <Org.Neo4j.causalclustering.core.consensus.RaftMessages_RaftMessage>();

            RaftReplicator replicator = GetReplicator(outbound, capturedProgress, monitors);

            replicator.OnLeaderSwitch(_leaderInfo);

            ReplicatedInteger content           = ReplicatedInteger.valueOf(5);
            Thread            replicatingThread = replicatingThread(replicator, content, false);

            // when
            replicatingThread.Start();
            // then
            assertEventually("send count", () => outbound.Count, greaterThan(2), DEFAULT_TIMEOUT_MS, MILLISECONDS);

            // cleanup
            capturedProgress.Last.setReplicated();
            replicatingThread.Join(DEFAULT_TIMEOUT_MS);

            verify(replicationMonitor, times(1)).startReplication();
            verify(replicationMonitor, atLeast(2)).replicationAttempt();
            verify(replicationMonitor, times(1)).successfulReplication();
            verify(replicationMonitor, never()).failedReplication(any());
        }
Exemple #4
0
 internal ReplicatingThread(RaftReplicatorTest outerInstance, RaftReplicator replicator, ReplicatedInteger content, bool trackResult)
 {
     this._outerInstance = outerInstance;
     this.Replicator     = replicator;
     this.Content        = content;
     this.TrackResult    = trackResult;
 }
Exemple #5
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test void shouldReleaseSessionWhenFinished() throws Exception
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        internal virtual void ShouldReleaseSessionWhenFinished()
        {
            // given
            CapturingProgressTracker capturedProgress = new CapturingProgressTracker(this);
            CapturingOutbound <Org.Neo4j.causalclustering.core.consensus.RaftMessages_RaftMessage> outbound = new CapturingOutbound <Org.Neo4j.causalclustering.core.consensus.RaftMessages_RaftMessage>();

            RaftReplicator replicator = GetReplicator(outbound, capturedProgress, new Monitors());

            replicator.OnLeaderSwitch(_leaderInfo);
            ReplicatedInteger content           = ReplicatedInteger.valueOf(5);
            Thread            replicatingThread = replicatingThread(replicator, content, true);

            // when
            replicatingThread.Start();

            // then
            assertEventually("making progress", () => capturedProgress.Last, not(equalTo(null)), DEFAULT_TIMEOUT_MS, MILLISECONDS);
            assertEquals(1, _sessionPool.openSessionCount());

            // when
            capturedProgress.Last.setReplicated();
            capturedProgress.Last.futureResult().complete(5);
            replicatingThread.Join(DEFAULT_TIMEOUT_MS);

            // then
            assertEquals(0, _sessionPool.openSessionCount());
        }
Exemple #6
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void shouldAppendAndCommit() throws Exception
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        public virtual void ShouldAppendAndCommit()
        {
            RaftLog log = _logFactory.createBasedOn(FsRule.get());

            RaftLogEntry logEntry = new RaftLogEntry(1, ReplicatedInteger.valueOf(1));

            log.Append(logEntry);

            VerifyCurrentLogAndNewLogLoadedFromFileSystem(log, FsRule.get(), myLog => assertThat(myLog.appendIndex(), @is(0L)));
        }
Exemple #7
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test void shouldFailIfNoLeaderIsAvailable()
        internal virtual void ShouldFailIfNoLeaderIsAvailable()
        {
            // given
            CapturingProgressTracker capturedProgress = new CapturingProgressTracker(this);
            CapturingOutbound <Org.Neo4j.causalclustering.core.consensus.RaftMessages_RaftMessage> outbound = new CapturingOutbound <Org.Neo4j.causalclustering.core.consensus.RaftMessages_RaftMessage>();

            RaftReplicator    replicator = GetReplicator(outbound, capturedProgress, new Monitors());
            ReplicatedInteger content    = ReplicatedInteger.valueOf(5);

            // when
            assertThrows(typeof(ReplicationFailureException), () => replicator.Replicate(content, true));
        }
Exemple #8
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void shouldTruncatePreviouslyAppendedEntries() throws Exception
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        public virtual void ShouldTruncatePreviouslyAppendedEntries()
        {
            RaftLog log = _logFactory.createBasedOn(FsRule.get());

            RaftLogEntry logEntryA = new RaftLogEntry(1, ReplicatedInteger.valueOf(1));
            RaftLogEntry logEntryB = new RaftLogEntry(1, ReplicatedInteger.valueOf(2));

            log.Append(logEntryA);
            log.Append(logEntryB);
            log.Truncate(1);

            VerifyCurrentLogAndNewLogLoadedFromFileSystem(log, FsRule.get(), myLog => assertThat(myLog.appendIndex(), @is(0L)));
        }
Exemple #9
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void shouldRemoveLaterEntryFromLogConflictingWithNewEntry() throws Exception
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        public virtual void ShouldRemoveLaterEntryFromLogConflictingWithNewEntry()
        {
            _testEntryLog.append(new RaftLogEntry(1, valueOf(1)));
            _testEntryLog.append(new RaftLogEntry(1, valueOf(4)));
            _testEntryLog.append(new RaftLogEntry(1, valueOf(7)));                     // conflicting entry

            // when
            ReplicatedInteger newData = valueOf(11);

            _raft.handle(appendEntriesRequest().leaderTerm(2).prevLogIndex(2).prevLogTerm(1).logEntry(new RaftLogEntry(2, newData)).build());

            // then
            assertEquals(3, _testEntryLog.appendIndex());
            assertEquals(newData, readLogEntry(_testEntryLog, 3).content());
        }
Exemple #10
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void shouldAppendDataAndNotCommitImmediately() throws Exception
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        public virtual void ShouldAppendDataAndNotCommitImmediately()
        {
            RaftLog log = _logFactory.createBasedOn(FsRule.get());

//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
//ORIGINAL LINE: final RaftLogEntry logEntry = new RaftLogEntry(1, org.neo4j.causalclustering.core.consensus.ReplicatedInteger.valueOf(1));
            RaftLogEntry logEntry = new RaftLogEntry(1, ReplicatedInteger.valueOf(1));

            log.Append(logEntry);

            VerifyCurrentLogAndNewLogLoadedFromFileSystem(log, FsRule.get(), myLog =>
            {
                assertThat(myLog.appendIndex(), @is(0L));
                assertThat(readLogEntry(myLog, 0), equalTo(logEntry));
            });
        }
Exemple #11
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void shouldIgnoreOtherSessions()
        public virtual void ShouldIgnoreOtherSessions()
        {
            // given
            GlobalSession        sessionB           = new GlobalSession(System.Guid.randomUUID(), null);
            DistributedOperation aliasUnderSessionB = new DistributedOperation(ReplicatedInteger.valueOf(0), sessionB, new LocalOperationId(_operationA.operationId().localSessionId(), _operationA.operationId().sequenceNumber()));

            Progress progressA = _tracker.start(_operationA);

            // when
            _tracker.trackReplication(aliasUnderSessionB);
            _tracker.trackResult(aliasUnderSessionB, Result.of("result"));

            // then
            assertFalse(progressA.Replicated);
            assertFalse(progressA.FutureResult().Done);
        }
Exemple #12
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void shouldReturnFalseOnCursorForEntryThatWasPruned() throws Exception
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        public virtual void ShouldReturnFalseOnCursorForEntryThatWasPruned()
        {
            //given
            SegmentedRaftLog segmentedRaftLog = CreateRaftLog(1, "keep_none");
            long             firstIndex       = segmentedRaftLog.Append(new RaftLogEntry(1, ReplicatedInteger.valueOf(1)));

            segmentedRaftLog.Append(new RaftLogEntry(2, ReplicatedInteger.valueOf(2)));
            long lastIndex = segmentedRaftLog.Append(new RaftLogEntry(3, ReplicatedInteger.valueOf(3)));

            //when
            segmentedRaftLog.Prune(firstIndex);
            RaftLogCursor entryCursor = segmentedRaftLog.GetEntryCursor(firstIndex);
            bool          next        = entryCursor.Next();

            //then
            assertFalse(next);
        }
Exemple #13
0
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
//ORIGINAL LINE: public org.neo4j.causalclustering.core.replication.ReplicatedContent unmarshal0(org.neo4j.storageengine.api.ReadableChannel channel) throws java.io.IOException
            public override ReplicatedContent unmarshal0(ReadableChannel channel)
            {
                sbyte type = channel.Get();
//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
//ORIGINAL LINE: final org.neo4j.causalclustering.core.replication.ReplicatedContent content;
                ReplicatedContent content;

                switch (type)
                {
                case 1:
                    content = ReplicatedInteger.valueOf(channel.Int);
                    break;

                default:
                    throw new System.ArgumentException(string.Format("Unknown content type 0x{0:x}", type));
                }
                return(content);
            }
Exemple #14
0
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
//ORIGINAL LINE: protected org.neo4j.causalclustering.core.replication.ReplicatedContent unmarshal0(org.neo4j.storageengine.api.ReadableChannel channel) throws java.io.IOException
        protected internal override ReplicatedContent Unmarshal0(ReadableChannel channel)
        {
            sbyte type = channel.Get();

            switch (type)
            {
            case REPLICATED_INTEGER_TYPE:
                return(ReplicatedInteger.valueOf(channel.Int));

            case REPLICATED_STRING_TYPE:
                int     length = channel.Int;
                sbyte[] bytes  = new sbyte[length];
                channel.Get(bytes, length);
                return(ReplicatedString.valueOf(StringHelper.NewString(bytes)));

            default:
                throw new System.ArgumentException("Unknown content type: " + type);
            }
        }
Exemple #15
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test void stopReplicationWhenUnavailable() throws InterruptedException
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        internal virtual void StopReplicationWhenUnavailable()
        {
            CapturingProgressTracker capturedProgress = new CapturingProgressTracker(this);
            CapturingOutbound <Org.Neo4j.causalclustering.core.consensus.RaftMessages_RaftMessage> outbound = new CapturingOutbound <Org.Neo4j.causalclustering.core.consensus.RaftMessages_RaftMessage>();

            RaftReplicator replicator = GetReplicator(outbound, capturedProgress, new Monitors());

            replicator.OnLeaderSwitch(_leaderInfo);

            ReplicatedInteger content           = ReplicatedInteger.valueOf(5);
            ReplicatingThread replicatingThread = replicatingThread(replicator, content, true);

            // when
            replicatingThread.Start();

            _databaseAvailabilityGuard.require(() => "Database not unavailable");
            replicatingThread.Join();
            assertThat(replicatingThread.ReplicationException.InnerException, Matchers.instanceOf(typeof(UnavailableException)));
        }
Exemple #16
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void shouldAppendAfterReloadingFromFileSystem() throws Exception
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        public virtual void ShouldAppendAfterReloadingFromFileSystem()
        {
            RaftLog log = _logFactory.createBasedOn(FsRule.get());

            RaftLogEntry logEntryA = new RaftLogEntry(1, ReplicatedInteger.valueOf(1));

            log.Append(logEntryA);

            FsRule.get().crash();
            log = _logFactory.createBasedOn(FsRule.get());

            RaftLogEntry logEntryB = new RaftLogEntry(1, ReplicatedInteger.valueOf(2));

            log.Append(logEntryB);

            assertThat(log.AppendIndex(), @is(1L));
            assertThat(readLogEntry(log, 0), @is(logEntryA));
            assertThat(readLogEntry(log, 1), @is(logEntryB));
        }
Exemple #17
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test void stopReplicationWhenUnHealthy() throws InterruptedException
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        internal virtual void StopReplicationWhenUnHealthy()
        {
            CapturingProgressTracker capturedProgress = new CapturingProgressTracker(this);
            CapturingOutbound <Org.Neo4j.causalclustering.core.consensus.RaftMessages_RaftMessage> outbound = new CapturingOutbound <Org.Neo4j.causalclustering.core.consensus.RaftMessages_RaftMessage>();

            RaftReplicator replicator = GetReplicator(outbound, capturedProgress, new Monitors());

            replicator.OnLeaderSwitch(_leaderInfo);

            ReplicatedInteger content           = ReplicatedInteger.valueOf(5);
            ReplicatingThread replicatingThread = replicatingThread(replicator, content, true);

            // when
            replicatingThread.Start();

            _databaseHealth.panic(new System.InvalidOperationException("PANIC"));
            replicatingThread.Join();
            Assertions.assertNotNull(replicatingThread.ReplicationException);
        }
Exemple #18
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void shouldSendAllEntriesAndCatchupCompletely() throws Throwable
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        public virtual void ShouldSendAllEntriesAndCatchupCompletely()
        {
            // given
//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
//ORIGINAL LINE: final int ENTRY_COUNT = catchupBatchSize * 10;
            int entryCount = _catchupBatchSize * 10;
            ICollection <RaftLogEntry> entries = new List <RaftLogEntry>();

            for (int i = 0; i < entryCount; i++)
            {
                entries.Add(new RaftLogEntry(0, ReplicatedInteger.valueOf(i)));
            }

            foreach (RaftLogEntry entry in entries)
            {
                _raftLog.append(entry);
            }

            // then
            StartLogShipper();

            // back-tracking stage
            Org.Neo4j.causalclustering.core.consensus.RaftMessages_AppendEntries_Request expected = new Org.Neo4j.causalclustering.core.consensus.RaftMessages_AppendEntries_Request(_leader, _leaderTerm, 0, 0, RaftLogEntry.empty, _leaderCommit);
            while (!_outbound.sentTo(_follower).Contains(expected))
            {
                _logShipper.onMismatch(-1, new LeaderContext(0, 0));
            }

            // catchup stage
            long matchIndex;

            do
            {
                Org.Neo4j.causalclustering.core.consensus.RaftMessages_AppendEntries_Request last = (Org.Neo4j.causalclustering.core.consensus.RaftMessages_AppendEntries_Request)Iterables.last(_outbound.sentTo(_follower));
                matchIndex = last.PrevLogIndex() + last.Entries().Length;

                _outbound.clear();
                _logShipper.onMatch(matchIndex, new LeaderContext(0, 0));
            } while (_outbound.sentTo(_follower).Count > 0);

            assertEquals(entryCount - 1, matchIndex);
        }
Exemple #19
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void shouldReturnFalseOnCursorForEntryThatDoesntExist() throws Exception
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        public virtual void ShouldReturnFalseOnCursorForEntryThatDoesntExist()
        {
            //given
            SegmentedRaftLog segmentedRaftLog = CreateRaftLog(1);

            segmentedRaftLog.Append(new RaftLogEntry(1, ReplicatedInteger.valueOf(1)));
            segmentedRaftLog.Append(new RaftLogEntry(2, ReplicatedInteger.valueOf(2)));
            long lastIndex = segmentedRaftLog.Append(new RaftLogEntry(3, ReplicatedInteger.valueOf(3)));

            //when
            bool next;

            using (RaftLogCursor entryCursor = segmentedRaftLog.GetEntryCursor(lastIndex + 1))
            {
                next = entryCursor.Next();
            }

            //then
            assertFalse(next);
        }
Exemple #20
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void shouldBeAbleToRecoverToLatestStateAfterRotation() throws Throwable
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        public virtual void ShouldBeAbleToRecoverToLatestStateAfterRotation()
        {
            // Given
            int  term = 0;
            long indexToRestoreTo;

            using (Lifespan lifespan = new Lifespan())
            {
                SegmentedRaftLog log = lifespan.Add(CreateRaftLog(ROTATE_AT_SIZE_IN_BYTES));
                log.Append(new RaftLogEntry(term, ReplicatedStringOfBytes(ROTATE_AT_SIZE_IN_BYTES - 40)));
                indexToRestoreTo = log.Append(new RaftLogEntry(term, ReplicatedInteger.valueOf(1)));
            }

            // When
            SegmentedRaftLog log = _life.add(CreateRaftLog(ROTATE_AT_SIZE_IN_BYTES));

            // Then
            assertEquals(indexToRestoreTo, log.AppendIndex());
            assertEquals(term, log.ReadEntryTerm(indexToRestoreTo));
        }
Exemple #21
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void shouldLogDifferentContentTypes() throws Exception
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        public virtual void ShouldLogDifferentContentTypes()
        {
            RaftLog log = _logFactory.createBasedOn(FsRule.get());

//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
//ORIGINAL LINE: final RaftLogEntry logEntryA = new RaftLogEntry(1, org.neo4j.causalclustering.core.consensus.ReplicatedInteger.valueOf(1));
            RaftLogEntry logEntryA = new RaftLogEntry(1, ReplicatedInteger.valueOf(1));
//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
//ORIGINAL LINE: final RaftLogEntry logEntryB = new RaftLogEntry(1, org.neo4j.causalclustering.core.consensus.ReplicatedString.valueOf("hejzxcjkzhxcjkxz"));
            RaftLogEntry logEntryB = new RaftLogEntry(1, ReplicatedString.valueOf("hejzxcjkzhxcjkxz"));

            log.Append(logEntryA);
            log.Append(logEntryB);

            VerifyCurrentLogAndNewLogLoadedFromFileSystem(log, FsRule.get(), myLog =>
            {
                assertThat(myLog.appendIndex(), @is(1L));
                assertThat(readLogEntry(myLog, 0), equalTo(logEntryA));
                assertThat(readLogEntry(myLog, 1), equalTo(logEntryB));
            });
        }
Exemple #22
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test void shouldListenToLeaderUpdates() throws ReplicationFailureException
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        internal virtual void ShouldListenToLeaderUpdates()
        {
            OneProgressTracker oneProgressTracker = new OneProgressTracker(this);

            oneProgressTracker.Last.setReplicated();
            CapturingOutbound <Org.Neo4j.causalclustering.core.consensus.RaftMessages_RaftMessage> outbound = new CapturingOutbound <Org.Neo4j.causalclustering.core.consensus.RaftMessages_RaftMessage>();
            RaftReplicator    replicator = GetReplicator(outbound, oneProgressTracker, new Monitors());
            ReplicatedInteger content    = ReplicatedInteger.valueOf(5);

            LeaderInfo lastLeader = _leaderInfo;

            // set initial leader, sens to that leader
            replicator.OnLeaderSwitch(lastLeader);
            replicator.Replicate(content, false);
            assertEquals(outbound.LastTo, lastLeader.MemberId());

            // update with valid new leader, sends to new leader
            lastLeader = new LeaderInfo(new MemberId(System.Guid.randomUUID()), 1);
            replicator.OnLeaderSwitch(lastLeader);
            replicator.Replicate(content, false);
            assertEquals(outbound.LastTo, lastLeader.MemberId());
        }
Exemple #23
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void shouldNotTruncateLogIfHistoryDoesNotMatch() throws Exception
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        public virtual void ShouldNotTruncateLogIfHistoryDoesNotMatch()
        {
            _testEntryLog.append(new RaftLogEntry(1, valueOf(99)));
            _testEntryLog.append(new RaftLogEntry(1, valueOf(99)));
            _testEntryLog.append(new RaftLogEntry(1, valueOf(99)));
            _testEntryLog.append(new RaftLogEntry(2, valueOf(99)));
            _testEntryLog.append(new RaftLogEntry(2, valueOf(99)));
            _testEntryLog.append(new RaftLogEntry(2, valueOf(99)));
            _testEntryLog.append(new RaftLogEntry(3, valueOf(99)));
            _testEntryLog.append(new RaftLogEntry(3, valueOf(99)));
            _testEntryLog.append(new RaftLogEntry(3, valueOf(99)));
            _testEntryLog.append(new RaftLogEntry(3, valueOf(99)));
            _testEntryLog.append(new RaftLogEntry(3, valueOf(99)));

            // when instance A as leader
            ReplicatedInteger newData = valueOf(99);

            _raft.handle(appendEntriesRequest().leaderTerm(8).prevLogIndex(4).prevLogTerm(4).logEntry(new RaftLogEntry(4, newData)).logEntry(new RaftLogEntry(5, newData)).logEntry(new RaftLogEntry(5, newData)).logEntry(new RaftLogEntry(6, newData)).logEntry(new RaftLogEntry(6, newData)).logEntry(new RaftLogEntry(6, newData)).build());

            // then
            assertEquals(11, _testEntryLog.appendIndex());
        }
Exemple #24
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test void shouldSuccessfullySendIfLeaderIsLostAndFound() throws InterruptedException
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        internal virtual void ShouldSuccessfullySendIfLeaderIsLostAndFound()
        {
            OneProgressTracker capturedProgress = new OneProgressTracker(this);
            CapturingOutbound <Org.Neo4j.causalclustering.core.consensus.RaftMessages_RaftMessage> outbound = new CapturingOutbound <Org.Neo4j.causalclustering.core.consensus.RaftMessages_RaftMessage>();

            RaftReplicator replicator = GetReplicator(outbound, capturedProgress, new Monitors());

            replicator.OnLeaderSwitch(_leaderInfo);

            ReplicatedInteger content           = ReplicatedInteger.valueOf(5);
            ReplicatingThread replicatingThread = replicatingThread(replicator, content, false);

            // when
            replicatingThread.Start();

            // then
            assertEventually("send count", () => outbound.Count, greaterThan(1), DEFAULT_TIMEOUT_MS, MILLISECONDS);
            replicator.OnLeaderSwitch(new LeaderInfo(null, 1));
            capturedProgress.Last.setReplicated();
            replicator.OnLeaderSwitch(_leaderInfo);

            replicatingThread.Join(DEFAULT_TIMEOUT_MS);
        }
Exemple #25
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void shouldReplacePreviouslyAppendedEntries() throws Exception
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        public virtual void ShouldReplacePreviouslyAppendedEntries()
        {
            RaftLog log = _logFactory.createBasedOn(FsRule.get());

//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
//ORIGINAL LINE: final RaftLogEntry logEntryA = new RaftLogEntry(1, org.neo4j.causalclustering.core.consensus.ReplicatedInteger.valueOf(1));
            RaftLogEntry logEntryA = new RaftLogEntry(1, ReplicatedInteger.valueOf(1));
//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
//ORIGINAL LINE: final RaftLogEntry logEntryB = new RaftLogEntry(1, org.neo4j.causalclustering.core.consensus.ReplicatedInteger.valueOf(2));
            RaftLogEntry logEntryB = new RaftLogEntry(1, ReplicatedInteger.valueOf(2));
//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
//ORIGINAL LINE: final RaftLogEntry logEntryC = new RaftLogEntry(1, org.neo4j.causalclustering.core.consensus.ReplicatedInteger.valueOf(3));
            RaftLogEntry logEntryC = new RaftLogEntry(1, ReplicatedInteger.valueOf(3));
//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
//ORIGINAL LINE: final RaftLogEntry logEntryD = new RaftLogEntry(1, org.neo4j.causalclustering.core.consensus.ReplicatedInteger.valueOf(4));
            RaftLogEntry logEntryD = new RaftLogEntry(1, ReplicatedInteger.valueOf(4));
//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
//ORIGINAL LINE: final RaftLogEntry logEntryE = new RaftLogEntry(1, org.neo4j.causalclustering.core.consensus.ReplicatedInteger.valueOf(5));
            RaftLogEntry logEntryE = new RaftLogEntry(1, ReplicatedInteger.valueOf(5));

            log.Append(logEntryA);
            log.Append(logEntryB);
            log.Append(logEntryC);

            log.Truncate(1);

            log.Append(logEntryD);
            log.Append(logEntryE);

            VerifyCurrentLogAndNewLogLoadedFromFileSystem(log, FsRule.get(), myLog =>
            {
                assertThat(myLog.appendIndex(), @is(2L));
                assertThat(readLogEntry(myLog, 0), equalTo(logEntryA));
                assertThat(readLogEntry(myLog, 1), equalTo(logEntryD));
                assertThat(readLogEntry(myLog, 2), equalTo(logEntryE));
            });
        }
Exemple #26
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void shouldMonitorAppendIndexAndCommitIndex() throws Exception
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        public virtual void ShouldMonitorAppendIndexAndCommitIndex()
        {
            // Given
            Monitors monitors = new Monitors();
            StubRaftLogAppendIndexMonitor appendMonitor = new StubRaftLogAppendIndexMonitor();

            monitors.AddMonitorListener(appendMonitor);

            StubRaftLogCommitIndexMonitor commitMonitor = new StubRaftLogCommitIndexMonitor();

            monitors.AddMonitorListener(commitMonitor);

            MonitoredRaftLog log = new MonitoredRaftLog(new InMemoryRaftLog(), monitors);

            // When
            log.Append(new RaftLogEntry(0, ReplicatedInteger.valueOf(1)));
            log.Append(new RaftLogEntry(0, ReplicatedInteger.valueOf(1)));

            assertEquals(1, appendMonitor.AppendIndex());
            assertEquals(0, commitMonitor.CommitIndex());

            log.Truncate(1);
            assertEquals(0, appendMonitor.AppendIndex());
        }
Exemple #27
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void shouldNotTouchTheLogIfWeDoMatchEverywhere() throws Exception
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        public virtual void ShouldNotTouchTheLogIfWeDoMatchEverywhere()
        {
            _testEntryLog.append(new RaftLogEntry(1, valueOf(99)));                     // 0
            _testEntryLog.append(new RaftLogEntry(1, valueOf(99)));                     // 1
            _testEntryLog.append(new RaftLogEntry(1, valueOf(99)));
            _testEntryLog.append(new RaftLogEntry(2, valueOf(99)));
            _testEntryLog.append(new RaftLogEntry(2, valueOf(99)));
            _testEntryLog.append(new RaftLogEntry(2, valueOf(99)));                     // 5
            _testEntryLog.append(new RaftLogEntry(3, valueOf(99)));
            _testEntryLog.append(new RaftLogEntry(3, valueOf(99)));
            _testEntryLog.append(new RaftLogEntry(3, valueOf(99)));
            _testEntryLog.append(new RaftLogEntry(3, valueOf(99)));
            _testEntryLog.append(new RaftLogEntry(3, valueOf(99)));                     // 10

            // when instance A as leader
            ReplicatedInteger newData = valueOf(99);

            // Matches everything in the given range
            _raft.handle(appendEntriesRequest().leaderTerm(8).prevLogIndex(5).prevLogTerm(2).logEntry(new RaftLogEntry(2, newData)).logEntry(new RaftLogEntry(3, newData)).logEntry(new RaftLogEntry(3, newData)).logEntry(new RaftLogEntry(3, newData)).build());

            // then
            assertEquals(11, _testEntryLog.appendIndex());
            assertEquals(3, _testEntryLog.readEntryTerm(11));
        }
Exemple #28
0
        /* Figure 3.6 */
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void shouldNotTouchTheLogIfWeDoNotMatchAnywhere() throws Exception
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        public virtual void ShouldNotTouchTheLogIfWeDoNotMatchAnywhere()
        {
            _testEntryLog.append(new RaftLogEntry(1, valueOf(99)));
            _testEntryLog.append(new RaftLogEntry(1, valueOf(99)));
            _testEntryLog.append(new RaftLogEntry(1, valueOf(99)));
            _testEntryLog.append(new RaftLogEntry(2, valueOf(99)));
            _testEntryLog.append(new RaftLogEntry(2, valueOf(99)));
            _testEntryLog.append(new RaftLogEntry(2, valueOf(99)));
            _testEntryLog.append(new RaftLogEntry(3, valueOf(99)));
            _testEntryLog.append(new RaftLogEntry(3, valueOf(99)));
            _testEntryLog.append(new RaftLogEntry(3, valueOf(99)));
            _testEntryLog.append(new RaftLogEntry(3, valueOf(99)));
            _testEntryLog.append(new RaftLogEntry(3, valueOf(99)));

            // when instance A as leader
            ReplicatedInteger newData = valueOf(99);

            // Will not match as the entry at index 5 has term  2
            _raft.handle(appendEntriesRequest().leaderTerm(8).prevLogIndex(6).prevLogTerm(5).logEntry(new RaftLogEntry(5, newData)).logEntry(new RaftLogEntry(5, newData)).logEntry(new RaftLogEntry(6, newData)).logEntry(new RaftLogEntry(6, newData)).logEntry(new RaftLogEntry(6, newData)).build());

            // then
            assertEquals(11, _testEntryLog.appendIndex());
            assertEquals(3, _testEntryLog.readEntryTerm(11));
        }
Exemple #29
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void shouldTruncateLogIfFirstEntryMatchesAndSecondEntryMismatchesOnTerm() throws Exception
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        public virtual void ShouldTruncateLogIfFirstEntryMatchesAndSecondEntryMismatchesOnTerm()
        {
            _testEntryLog.append(new RaftLogEntry(1, valueOf(99)));
            _testEntryLog.append(new RaftLogEntry(1, valueOf(99)));
            _testEntryLog.append(new RaftLogEntry(1, valueOf(99)));
            _testEntryLog.append(new RaftLogEntry(2, valueOf(99)));
            _testEntryLog.append(new RaftLogEntry(2, valueOf(99)));
            _testEntryLog.append(new RaftLogEntry(2, valueOf(99)));
            _testEntryLog.append(new RaftLogEntry(3, valueOf(99)));
            _testEntryLog.append(new RaftLogEntry(3, valueOf(99)));
            _testEntryLog.append(new RaftLogEntry(3, valueOf(99)));
            _testEntryLog.append(new RaftLogEntry(3, valueOf(99)));
            _testEntryLog.append(new RaftLogEntry(3, valueOf(99)));

            // when instance A as leader
            ReplicatedInteger newData = valueOf(99);

            _raft.handle(appendEntriesRequest().leaderTerm(8).prevLogIndex(2).prevLogTerm(1).logEntry(new RaftLogEntry(1, newData)).logEntry(new RaftLogEntry(4, newData)).logEntry(new RaftLogEntry(4, newData)).logEntry(new RaftLogEntry(5, newData)).logEntry(new RaftLogEntry(5, newData)).logEntry(new RaftLogEntry(6, newData)).logEntry(new RaftLogEntry(6, newData)).logEntry(new RaftLogEntry(6, newData)).build());

            // then
            assertEquals(10, _testEntryLog.appendIndex());

            // stay the same
            assertEquals(1, _testEntryLog.readEntryTerm(1));
            assertEquals(1, _testEntryLog.readEntryTerm(2));
            assertEquals(1, _testEntryLog.readEntryTerm(3));

            // replaced
            assertEquals(4, _testEntryLog.readEntryTerm(4));
            assertEquals(4, _testEntryLog.readEntryTerm(5));
            assertEquals(5, _testEntryLog.readEntryTerm(6));
            assertEquals(5, _testEntryLog.readEntryTerm(7));
            assertEquals(6, _testEntryLog.readEntryTerm(8));
            assertEquals(6, _testEntryLog.readEntryTerm(9));
            assertEquals(6, _testEntryLog.readEntryTerm(10));
        }
Exemple #30
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void shouldSerializeAppendRequestWithMultipleEntries() throws Exception
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        public virtual void ShouldSerializeAppendRequestWithMultipleEntries()
        {
            MemberId sender = new MemberId(System.Guid.randomUUID());

            Org.Neo4j.causalclustering.core.consensus.RaftMessages_AppendEntries_Request request = (new AppendEntriesRequestBuilder()).from(sender).leaderCommit(2).leaderTerm(4).logEntry(new RaftLogEntry(1, ReplicatedInteger.valueOf(2))).logEntry(new RaftLogEntry(1, ReplicatedInteger.valueOf(3))).logEntry(new RaftLogEntry(1, ReplicatedInteger.valueOf(4))).build();
            SerializeReadBackAndVerifyMessage(request);
        }