Esempio n. 1
0
 internal ReplicatingThread(RaftReplicatorTest outerInstance, RaftReplicator replicator, ReplicatedInteger content, bool trackResult)
 {
     this._outerInstance = outerInstance;
     this.Replicator     = replicator;
     this.Content        = content;
     this.TrackResult    = trackResult;
 }
Esempio n. 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());
        }
Esempio n. 3
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());
        }
Esempio n. 4
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());
        }
Esempio n. 5
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));
        }
Esempio n. 6
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);
        }
Esempio n. 7
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)));
        }
Esempio n. 8
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());
        }
Esempio n. 9
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);
        }
Esempio n. 10
0
 private ReplicatingThread ReplicatingThread(RaftReplicator replicator, ReplicatedInteger content, bool trackResult)
 {
     return(new ReplicatingThread(this, replicator, content, trackResult));
 }