Example #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)));
        }
Example #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));
        }
Example #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));
        }
Example #4
0
 public virtual void Set(ClusterMemberListener clusterMemberListener)
 {
     if (this.ClusterMemberListener != null)
     {
         throw new System.InvalidOperationException("Expected to have only 1 listener, but have more. " + "Defined listener: " + this.ClusterMemberListener + ". Newly added listener:" + clusterMemberListener);
     }
     this.ClusterMemberListener = clusterMemberListener;
 }
Example #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));
        }
Example #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));
        }
Example #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));
        }
Example #8
0
 public override void AddClusterMemberListener(ClusterMemberListener listener)
 {
     Listeners.add(listener);
 }
Example #9
0
 public override void RemoveClusterMemberListener(ClusterMemberListener listener)
 {
     Listeners.remove(listener);
 }
Example #10
0
 public override void RemoveClusterMemberListener(ClusterMemberListener listener)
 {
 }
Example #11
0
 public override void AddClusterMemberListener(ClusterMemberListener listener)
 {
     this.Listener = listener;
 }