Пример #1
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void whenInToSlaveStateLosingQuorumShouldPutInPending()
        public virtual void WhenInToSlaveStateLosingQuorumShouldPutInPending()
        {
            // Given
            InstanceId me    = new InstanceId(1);
            InstanceId other = new InstanceId(2);
            HighAvailabilityMemberContext context = new SimpleHighAvailabilityMemberContext(me, false);
            AvailabilityGuard             guard   = mock(typeof(DatabaseAvailabilityGuard));
            ObservedClusterMembers        members = MockClusterMembers(me, emptyList(), singletonList(other));

            ClusterMemberEvents            events = mock(typeof(ClusterMemberEvents));
            ClusterMemberListenerContainer memberListenerContainer = MockAddClusterMemberListener(events);

            HighAvailabilityMemberStateMachine stateMachine = BuildMockedStateMachine(context, events, members, guard);

            stateMachine.Init();
            ClusterMemberListener memberListener = memberListenerContainer.Get();
            HAStateChangeListener probe          = new HAStateChangeListener();

            stateMachine.AddHighAvailabilityMemberListener(probe);

            // Send it to MASTER
            memberListener.MemberIsAvailable(MASTER, other, URI.create("ha://whatever"), StoreId.DEFAULT);

            assertThat(stateMachine.CurrentState, equalTo(HighAvailabilityMemberState.ToSlave));

            // When
            memberListener.MemberIsFailed(new InstanceId(2));

            // Then
            assertThat(stateMachine.CurrentState, equalTo(HighAvailabilityMemberState.Pending));
            assertThat(probe.InstanceStopsConflict, @is(false));
            assertThat(probe.InstanceDetachedConflict, @is(true));
            verify(guard, times(1)).require(any(typeof(AvailabilityRequirement)));
        }
Пример #2
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void whenInSlaveStateLosingOtherSlaveShouldNotPutInPending()
        public virtual void WhenInSlaveStateLosingOtherSlaveShouldNotPutInPending()
        {
            // Given
            InstanceId me         = new InstanceId(1);
            InstanceId master     = new InstanceId(2);
            InstanceId otherSlave = new InstanceId(3);
            HighAvailabilityMemberContext context = new SimpleHighAvailabilityMemberContext(me, false);
            AvailabilityGuard             guard   = mock(typeof(DatabaseAvailabilityGuard));
            ObservedClusterMembers        members = MockClusterMembers(me, singletonList(master), singletonList(otherSlave));

            ClusterMemberEvents            events = mock(typeof(ClusterMemberEvents));
            ClusterMemberListenerContainer memberListenerContainer = MockAddClusterMemberListener(events);

            HighAvailabilityMemberStateMachine stateMachine = BuildMockedStateMachine(context, events, members, guard);

            stateMachine.Init();
            ClusterMemberListener memberListener = memberListenerContainer.Get();
            HAStateChangeListener probe          = new HAStateChangeListener();

            stateMachine.AddHighAvailabilityMemberListener(probe);

            // Send it to MASTER
            memberListener.MemberIsAvailable(MASTER, master, URI.create("ha://whatever"), StoreId.DEFAULT);
            memberListener.MemberIsAvailable(SLAVE, me, URI.create("ha://whatever3"), StoreId.DEFAULT);
            memberListener.MemberIsAvailable(SLAVE, otherSlave, URI.create("ha://whatever2"), StoreId.DEFAULT);

            assertThat(stateMachine.CurrentState, equalTo(HighAvailabilityMemberState.Slave));

            // When
            memberListener.MemberIsFailed(otherSlave);

            // Then
            assertThat(stateMachine.CurrentState, equalTo(HighAvailabilityMemberState.Slave));
            assertThat(probe.InstanceStopsConflict, @is(false));
        }
Пример #3
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void whenInMasterStateLosingQuorumFromTwoInstancesShouldRemainMaster()
        public virtual void WhenInMasterStateLosingQuorumFromTwoInstancesShouldRemainMaster()
        {
            // Given
            InstanceId me    = new InstanceId(1);
            InstanceId other = new InstanceId(2);
            HighAvailabilityMemberContext context = new SimpleHighAvailabilityMemberContext(me, false);

            AvailabilityGuard      guard   = mock(typeof(DatabaseAvailabilityGuard));
            ObservedClusterMembers members = MockClusterMembers(me, emptyList(), singletonList(other));

            ClusterMemberEvents            events = mock(typeof(ClusterMemberEvents));
            ClusterMemberListenerContainer memberListenerContainer = MockAddClusterMemberListener(events);

            HighAvailabilityMemberStateMachine stateMachine = BuildMockedStateMachine(context, events, members, guard);

            stateMachine.Init();
            ClusterMemberListener memberListener = memberListenerContainer.Get();
            HAStateChangeListener probe          = new HAStateChangeListener();

            stateMachine.AddHighAvailabilityMemberListener(probe);

            // Send it to MASTER
            memberListener.CoordinatorIsElected(me);
            memberListener.MemberIsAvailable(MASTER, me, URI.create("ha://whatever"), StoreId.DEFAULT);

            assertThat(stateMachine.CurrentState, equalTo(HighAvailabilityMemberState.Master));

            // When
            memberListener.MemberIsFailed(new InstanceId(2));

            // Then
            assertThat(stateMachine.CurrentState, equalTo(HighAvailabilityMemberState.Master));
            assertThat(probe.InstanceStopsConflict, @is(false));
            assertThat(probe.InstanceDetachedConflict, @is(false));
        }
Пример #4
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Before public void setup()
        public virtual void Setup()
        {
            HighAvailabilityMemberContext context = new SimpleHighAvailabilityMemberContext(_me, false);

            ClusterMemberEvents events = mock(typeof(ClusterMemberEvents));

            HighAvailabilityMemberStateMachineTest.ClusterMemberListenerContainer memberListenerContainer = mockAddClusterMemberListener(events);

            _election = mock(typeof(Election));

            _stateMachine = BuildMockedStateMachine(context, events, _election);
            _stateMachine.init();
            _memberListener = memberListenerContainer.Get();
            HighAvailabilityMemberStateMachineTest.HAStateChangeListener probe = new HighAvailabilityMemberStateMachineTest.HAStateChangeListener();
            _stateMachine.addHighAvailabilityMemberListener(probe);
        }
Пример #5
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void shouldRemainToPendingOnMasterElectedForSomeoneElse()
        public virtual void ShouldRemainToPendingOnMasterElectedForSomeoneElse()
        {
            // Given
            InstanceId me = new InstanceId(1);
            HighAvailabilityMemberContext  context = new SimpleHighAvailabilityMemberContext(me, false);
            ClusterMemberEvents            events  = mock(typeof(ClusterMemberEvents));
            ClusterMemberListenerContainer memberListenerContainer = MockAddClusterMemberListener(events);

            HighAvailabilityMemberStateMachine stateMachine = BuildMockedStateMachine(context, events);

            stateMachine.Init();
            ClusterMemberListener memberListener = memberListenerContainer.Get();

            // When
            memberListener.CoordinatorIsElected(new InstanceId(2));

            // Then
            assertThat(stateMachine.CurrentState, equalTo(HighAvailabilityMemberState.Pending));
        }
Пример #6
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void whenSlaveOnlyIsElectedStayInPending()
        public virtual void WhenSlaveOnlyIsElectedStayInPending()
        {
            // Given
            InstanceId me = new InstanceId(1);
            HighAvailabilityMemberContext  context = new SimpleHighAvailabilityMemberContext(me, true);
            ClusterMemberEvents            events  = mock(typeof(ClusterMemberEvents));
            ClusterMemberListenerContainer memberListenerContainer = MockAddClusterMemberListener(events);

            HighAvailabilityMemberStateMachine stateMachine = BuildMockedStateMachine(context, events);

            stateMachine.Init();

            ClusterMemberListener memberListener = memberListenerContainer.Get();

            // When
            memberListener.CoordinatorIsElected(me);

            // Then
            assertThat(stateMachine.CurrentState, equalTo(HighAvailabilityMemberState.Pending));
        }
Пример #7
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void shouldSwitchToToSlaveOnMasterAvailableForSomeoneElse()
        public virtual void ShouldSwitchToToSlaveOnMasterAvailableForSomeoneElse()
        {
            // Given
            InstanceId me = new InstanceId(1);
            HighAvailabilityMemberContext  context = new SimpleHighAvailabilityMemberContext(me, false);
            ClusterMemberEvents            events  = mock(typeof(ClusterMemberEvents));
            ClusterMemberListenerContainer memberListenerContainer = MockAddClusterMemberListener(events);

            HighAvailabilityMemberStateMachine stateMachine = BuildMockedStateMachine(context, events);

            stateMachine.Init();
            ClusterMemberListener memberListener = memberListenerContainer.Get();
            HAStateChangeListener probe          = new HAStateChangeListener();

            stateMachine.AddHighAvailabilityMemberListener(probe);

            // When
            memberListener.MemberIsAvailable(MASTER, new InstanceId(2), URI.create("ha://whatever"), StoreId.DEFAULT);

            // Then
            assertThat(stateMachine.CurrentState, equalTo(HighAvailabilityMemberState.ToSlave));
            assertThat(probe.MasterIsAvailableConflict, @is(true));
        }