コード例 #1
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void shouldUpdateDiscoveryHeaderWithContactingInstances()
        public virtual void ShouldUpdateDiscoveryHeaderWithContactingInstances()
        {
            // Given
            InstanceId me         = new InstanceId(1);
            InstanceId joiningOne = new InstanceId(2);
            InstanceId joiningTwo = new InstanceId(3);

            CommonContextState commonContextState = mock(typeof(CommonContextState), RETURNS_MOCKS);
            Timeouts           timeouts           = mock(typeof(Timeouts));
            Executor           executor           = mock(typeof(Executor));

            HeartbeatContext heartbeatContext = mock(typeof(HeartbeatContext));

            ClusterContext context = new ClusterContextImpl(me, commonContextState, NullLogProvider.Instance, timeouts, executor, mock(typeof(ObjectOutputStreamFactory)), mock(typeof(ObjectInputStreamFactory)), mock(typeof(LearnerContext)), heartbeatContext, mock(typeof(Config)));

            ClusterMessage.ConfigurationRequestState requestOne = mock(typeof(ClusterMessage.ConfigurationRequestState));
            when(requestOne.JoiningId).thenReturn(joiningOne);

            ClusterMessage.ConfigurationRequestState requestTwo = mock(typeof(ClusterMessage.ConfigurationRequestState));
            when(requestTwo.JoiningId).thenReturn(joiningTwo);

            // When
            // Instance 2 contacts us twice and Instance 3 contacts us once
            context.AddContactingInstance(requestOne, "4, 5");                 // discovery headers are random here
            context.AddContactingInstance(requestOne, "4, 5");
            context.AddContactingInstance(requestTwo, "2, 5");

            // Then
            // The discovery header we generate should still contain one copy of each instance
            assertEquals("2,3", context.GenerateDiscoveryHeader());
        }
コード例 #2
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void shouldGracefullyHandleEmptyDiscoveryHeader()
        public virtual void ShouldGracefullyHandleEmptyDiscoveryHeader()
        {
            // Given
            InstanceId me      = new InstanceId(1);
            InstanceId joining = new InstanceId(2);

            CommonContextState commonContextState = mock(typeof(CommonContextState), RETURNS_MOCKS);
            Timeouts           timeouts           = mock(typeof(Timeouts));
            Executor           executor           = mock(typeof(Executor));

            HeartbeatContext heartbeatContext = mock(typeof(HeartbeatContext));

            ClusterContext context = new ClusterContextImpl(me, commonContextState, NullLogProvider.Instance, timeouts, executor, mock(typeof(ObjectOutputStreamFactory)), mock(typeof(ObjectInputStreamFactory)), mock(typeof(LearnerContext)), heartbeatContext, mock(typeof(Config)));

            ClusterMessage.ConfigurationRequestState request = mock(typeof(ClusterMessage.ConfigurationRequestState));
            when(request.JoiningId).thenReturn(joining);

            // When
            // Instance 2 contacts us with a request but it is empty
            context.AddContactingInstance(request, "");

            // Then
            // The discovery header we generate should still contain that instance
            assertEquals("2", context.GenerateDiscoveryHeader());
        }
コード例 #3
0
        /*
         * This test ensures that an instance that is marked as failed has its elector version reset. This means that
         * the instance, once it comes back, will still be able to do elections even if it lost state
         */
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void nonElectorFailingMustNotCauseElectorVersionToBeReset()
        public virtual void NonElectorFailingMustNotCauseElectorVersionToBeReset()
        {
            // Given
            InstanceId me      = new InstanceId(1);
            InstanceId elector = new InstanceId(2);

            CommonContextState commonContextState = mock(typeof(CommonContextState), RETURNS_MOCKS);
            Timeouts           timeouts           = mock(typeof(Timeouts));
            Executor           executor           = mock(typeof(Executor));

            HeartbeatContext heartbeatContext = mock(typeof(HeartbeatContext));

            ArgumentCaptor <HeartbeatListener> listenerCaptor = ArgumentCaptor.forClass(typeof(HeartbeatListener));

            ClusterContext context = new ClusterContextImpl(me, commonContextState, NullLogProvider.Instance, timeouts, executor, mock(typeof(ObjectOutputStreamFactory)), mock(typeof(ObjectInputStreamFactory)), mock(typeof(LearnerContext)), heartbeatContext, mock(typeof(Config)));

            verify(heartbeatContext).addHeartbeatListener(listenerCaptor.capture());

            HeartbeatListener theListener = listenerCaptor.Value;

            // This means instance 2 was the elector at version 8
            context.LastElector        = elector;
            context.LastElectorVersion = 8;

            // When
            theListener.Failed(new InstanceId(3));

            // Then
            assertEquals(context.LastElector, elector);
            assertEquals(context.LastElectorVersion, 8);
        }
コード例 #4
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void shouldKeepTrackOfInstancesWeHaveContacted()
        public virtual void ShouldKeepTrackOfInstancesWeHaveContacted()
        {
            // Given
            InstanceId me         = new InstanceId(1);
            InstanceId joiningOne = new InstanceId(2);
            InstanceId joiningTwo = new InstanceId(3);

            CommonContextState commonContextState = mock(typeof(CommonContextState), RETURNS_MOCKS);
            Timeouts           timeouts           = mock(typeof(Timeouts));
            Executor           executor           = mock(typeof(Executor));

            HeartbeatContext heartbeatContext = mock(typeof(HeartbeatContext));

            ClusterContext context = new ClusterContextImpl(me, commonContextState, NullLogProvider.Instance, timeouts, executor, mock(typeof(ObjectOutputStreamFactory)), mock(typeof(ObjectInputStreamFactory)), mock(typeof(LearnerContext)), heartbeatContext, mock(typeof(Config)));

            ClusterMessage.ConfigurationRequestState requestOne = mock(typeof(ClusterMessage.ConfigurationRequestState));
            when(requestOne.JoiningId).thenReturn(joiningOne);

            ClusterMessage.ConfigurationRequestState requestTwo = mock(typeof(ClusterMessage.ConfigurationRequestState));
            when(requestTwo.JoiningId).thenReturn(joiningTwo);

            // When
            // Instance two contacts us but we are not in the header
            context.AddContactingInstance(requestOne, "4, 5");
            // Then we haven't contacted instance 2
            assertFalse(context.HaveWeContactedInstance(requestOne));

            // When
            // Instance 2 reports that we have contacted it after all
            context.AddContactingInstance(requestOne, "4, 5, 1");
            // Then
            assertTrue(context.HaveWeContactedInstance(requestOne));

            // When
            // Instance 3 says we have contacted it
            context.AddContactingInstance(requestTwo, "2, 5, 1");
            // Then
            assertTrue(context.HaveWeContactedInstance(requestTwo));

            // When
            // For some reason we are not in the header of 3 in subsequent responses (a delayed one, for example)
            context.AddContactingInstance(requestTwo, "2, 5");
            // Then
            // The state should still keep the fact we've contacted it already
            assertTrue(context.HaveWeContactedInstance(requestTwo));
        }
コード例 #5
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void shouldHasQuorumWhenOneMachineAliveInAClusterWithOneMachine()
        public virtual void ShouldHasQuorumWhenOneMachineAliveInAClusterWithOneMachine()
        {
            //Given
            HeartbeatContext     heartbeatContext = mock(typeof(HeartbeatContext));
            CommonContextState   commonState      = mock(typeof(CommonContextState));
            ClusterConfiguration configuration    = mock(typeof(ClusterConfiguration));

            when(heartbeatContext.Alive).thenReturn(ids(1));
            when(commonState.Configuration()).thenReturn(configuration);
            when(configuration.Members).thenReturn(members(1));

            AtomicBroadcastContextImpl context = new AtomicBroadcastContextImpl(null, commonState, null, null, null, heartbeatContext);                 // we do not care about other args
            //When
            bool hasQuorum = context.HasQuorum();

            //Then
            assertTrue(hasQuorum);
        }
コード例 #6
0
 public virtual AtomicBroadcastContextImpl Snapshot(CommonContextState commonStateSnapshot, LogProvider logging, Timeouts timeouts, Executor executor, HeartbeatContext heartbeatContext)
 {
     return(new AtomicBroadcastContextImpl(Me, commonStateSnapshot, logging, timeouts, executor, heartbeatContext));
 }
コード例 #7
0
 internal AtomicBroadcastContextImpl(Org.Neo4j.cluster.InstanceId me, CommonContextState commonState, LogProvider logging, Timeouts timeouts, Executor executor, HeartbeatContext heartbeatContext) : base(me, commonState, logging, timeouts)
 {
     this._executor         = executor;
     this._heartbeatContext = heartbeatContext;
 }