//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)); }
//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 }
//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)); }