Exemplo n.º 1
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void shouldFailAndAliveBothNotifyHeartbeatListenerInDelayedDirectExecutor()
        public virtual void ShouldFailAndAliveBothNotifyHeartbeatListenerInDelayedDirectExecutor()
        {
            // Given
            InstanceId me            = new InstanceId(1);
            InstanceId failedMachine = new InstanceId(2);
            InstanceId goodMachine   = new InstanceId(3);

            Timeouts timeouts = mock(typeof(Timeouts));

            CommonContextState   commonState   = mock(typeof(CommonContextState));
            ClusterConfiguration configuration = mock(typeof(ClusterConfiguration));

            when(commonState.Configuration()).thenReturn(configuration);
            when(configuration.Members).thenReturn(members(3));
            when(configuration.MemberIds).thenReturn(ids(3));

//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
//ORIGINAL LINE: final java.util.List<Runnable> runnables = new java.util.ArrayList<>();
            IList <ThreadStart> runnables = new List <ThreadStart>();
            HeartbeatContext    context   = new HeartbeatContextImpl(me, commonState, NullLogProvider.Instance, timeouts, new DelayedDirectExecutorAnonymousInnerClass(this, NullLogProvider.Instance, runnables));

            context.AddHeartbeatListener(mock(typeof(HeartbeatListener)));

            context.Suspicions(goodMachine, new HashSet <InstanceId>(singletonList(failedMachine)));
            context.Suspect(failedMachine);               // fail
            context.Alive(failedMachine);                 // alive

            // Then
            assertEquals(2, runnables.Count);                 // fail + alive
        }
Exemplo n.º 2
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void majorityOfNonSuspectedInstancesShouldBeEnoughToMarkAnInstanceAsFailed()
        public virtual void MajorityOfNonSuspectedInstancesShouldBeEnoughToMarkAnInstanceAsFailed()
        {
            // Given
            InstanceId me      = new InstanceId(1);
            InstanceId member2 = new InstanceId(2);
            InstanceId member3 = new InstanceId(3);
            InstanceId member4 = new InstanceId(4);
            InstanceId member5 = new InstanceId(5);

            Timeouts timeouts = mock(typeof(Timeouts));

            CommonContextState   commonState   = mock(typeof(CommonContextState));
            ClusterConfiguration configuration = mock(typeof(ClusterConfiguration));

            when(commonState.Configuration()).thenReturn(configuration);
            when(configuration.Members).thenReturn(members(5));
            when(configuration.MemberIds).thenReturn(ids(5));

            DelayedDirectExecutor executor = new DelayedDirectExecutor(NullLogProvider.Instance);
            HeartbeatContext      context  = new HeartbeatContextImpl(me, commonState, NullLogProvider.Instance, timeouts, executor);

//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
//ORIGINAL LINE: final java.util.List<org.neo4j.cluster.InstanceId> failed = new java.util.ArrayList<>(4);
            IList <InstanceId> failed   = new List <InstanceId>(4);
            HeartbeatListener  listener = new HeartbeatListenerAnonymousInnerClass2(this, failed);

            context.AddHeartbeatListener(listener);

            // when
            // just two suspicions come, no extra failing action should be taken since this is not majority
            context.Suspect(member2);
            context.Suspect(member3);
            executor.Drain();

            // then
            assertEquals(0, failed.Count);

            // when
            // the another instance suspects them, therefore have a majority of non suspected, then 2 and 3 must fail
            ISet <InstanceId> suspicionsFrom5 = new HashSet <InstanceId>();

            suspicionsFrom5.Add(member2);
            suspicionsFrom5.Add(member3);
            context.Suspicions(member5, suspicionsFrom5);
            executor.Drain();

            // then
            assertEquals(2, failed.Count);
            assertTrue(failed.Contains(member2));
            assertTrue(failed.Contains(member3));

            // when
            // an instance sends a heartbeat, it should be set as alive
            context.Alive(member2);
            executor.Drain();

            // then
            assertEquals(1, failed.Count);
            assertTrue(failed.Contains(member3));
        }
Exemplo n.º 3
0
        /*
         * This test ensures that an instance that cleanly leaves the cluster but is not the elector has no effect on
         * elector id and last version
         */
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void nonElectorLeavingTheClusterMustNotAffectElectorInformation()
        public virtual void NonElectorLeavingTheClusterMustNotAffectElectorInformation()
        {
            // Given
            InstanceId me      = new InstanceId(1);
            InstanceId elector = new InstanceId(2);
            InstanceId other   = new InstanceId(3);

            ClusterConfiguration clusterConfiguration = mock(typeof(ClusterConfiguration));

            when(clusterConfiguration.GetUriForId(other)).thenReturn(URI.create("cluster://instance2"));

            CommonContextState commonContextState = mock(typeof(CommonContextState));

            when(commonContextState.Configuration()).thenReturn(clusterConfiguration);

            ClusterContext context = new ClusterContextImpl(me, commonContextState, NullLogProvider.Instance, mock(typeof(Timeouts)), mock(typeof(Executor)), mock(typeof(ObjectOutputStreamFactory)), mock(typeof(ObjectInputStreamFactory)), mock(typeof(LearnerContext)), mock(typeof(HeartbeatContext)), mock(typeof(Config)));

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

            // When
            context.Left(other);

            // Then
            assertEquals(context.LastElector, elector);
            assertEquals(context.LastElectorVersion, 8);
        }
Exemplo n.º 4
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void shouldFailAllInstancesIfAllOtherInstancesAreSuspected()
        public virtual void ShouldFailAllInstancesIfAllOtherInstancesAreSuspected()
        {
            // Given
            InstanceId me      = new InstanceId(1);
            InstanceId member2 = new InstanceId(2);
            InstanceId member3 = new InstanceId(3);

            Timeouts timeouts = mock(typeof(Timeouts));

            CommonContextState   commonState   = mock(typeof(CommonContextState));
            ClusterConfiguration configuration = mock(typeof(ClusterConfiguration));

            when(commonState.Configuration()).thenReturn(configuration);
            when(configuration.Members).thenReturn(members(3));
            when(configuration.MemberIds).thenReturn(ids(3));

            DelayedDirectExecutor executor = new DelayedDirectExecutor(NullLogProvider.Instance);
            HeartbeatContext      context  = new HeartbeatContextImpl(me, commonState, NullLogProvider.Instance, timeouts, executor);

            IList <InstanceId> failed   = new List <InstanceId>(2);
            HeartbeatListener  listener = new HeartbeatListenerAnonymousInnerClass(this, failed);

            context.AddHeartbeatListener(listener);

            // when
            // just one suspicion comes, no extra failing action should be taken
            context.Suspect(member2);
            executor.Drain();

            // then
            assertEquals(0, failed.Count);

            // when
            // the other instance is suspected, all instances must be marked as failed
            context.Suspect(member3);
            executor.Drain();

            // then
            assertEquals(2, failed.Count);
            assertTrue(failed.Contains(member2));
            assertTrue(failed.Contains(member3));

            // when
            // one of them comes alive again, only that instance should be marked as alive
            context.Alive(member2);
            executor.Drain();

            // then
            assertEquals(1, failed.Count);
            assertTrue(failed.Contains(member3));
        }
Exemplo n.º 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);
        }