Beispiel #1
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void failedThenAliveMemberShowsAsAlive()
        public virtual void FailedThenAliveMemberShowsAsAlive()
        {
            // given
            Cluster             cluster      = mock(typeof(Cluster));
            Heartbeat           heartbeat    = mock(typeof(Heartbeat));
            ClusterMemberEvents memberEvents = mock(typeof(ClusterMemberEvents));

            ObservedClusterMembers members = new ObservedClusterMembers(_logProvider, cluster, heartbeat, memberEvents, null);

            ArgumentCaptor <ClusterListener> listener = ArgumentCaptor.forClass(typeof(ClusterListener));

            verify(cluster).addClusterListener(listener.capture());
            listener.Value.enteredCluster(ClusterConfiguration(_clusterUri1, _clusterUri2, _clusterUri3));

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

            verify(heartbeat).addHeartbeatListener(heartBeatListener.capture());

            // when
            heartBeatListener.Value.failed(_clusterId1);
            heartBeatListener.Value.alive(_clusterId1);

            // then
            assertThat(members.Members, hasItem(sameMemberAs(new ClusterMember(_clusterId1))));
        }
Beispiel #2
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void receivingInstanceFailureEventRemovesAllRolesForIt()
        public virtual void ReceivingInstanceFailureEventRemovesAllRolesForIt()
        {
            // given
            Cluster             cluster      = mock(typeof(Cluster));
            Heartbeat           heartbeat    = mock(typeof(Heartbeat));
            ClusterMemberEvents memberEvents = mock(typeof(ClusterMemberEvents));

            ObservedClusterMembers members = new ObservedClusterMembers(_logProvider, cluster, heartbeat, memberEvents, _clusterId1);
            // initialized with the members of the cluster
            ArgumentCaptor <ClusterListener> listener = ArgumentCaptor.forClass(typeof(ClusterListener));

            verify(cluster).addClusterListener(listener.capture());
            listener.Value.enteredCluster(ClusterConfiguration(_clusterUri1, _clusterUri2, _clusterUri3));

            ArgumentCaptor <ClusterMemberListener> memberListener = ArgumentCaptor.forClass(typeof(ClusterMemberListener));

            verify(memberEvents).addClusterMemberListener(memberListener.capture());

            // instance 2 is available as MASTER and BACKUP
            memberListener.Value.memberIsAvailable(OnlineBackupKernelExtension.BACKUP, _clusterId2, _clusterUri2, StoreId.DEFAULT);
            memberListener.Value.memberIsAvailable(MASTER, _clusterId2, _clusterUri2, StoreId.DEFAULT);

            // when - instance 2 becomes failed
            memberListener.Value.memberIsFailed(_clusterId2);

            // then - instance 2 should not be available as any roles
            foreach (ClusterMember clusterMember in members.Members)
            {
                if (clusterMember.InstanceId.Equals(_clusterId2))
                {
                    assertThat(count(clusterMember.Roles), equalTo(0L));
                    break;                              // that's the only member we care about
                }
            }
        }
Beispiel #3
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void missingSlaveUnavailabilityEventDoesNotClobberState()
        public virtual void MissingSlaveUnavailabilityEventDoesNotClobberState()
        {
            // given
            Cluster             cluster      = mock(typeof(Cluster));
            Heartbeat           heartbeat    = mock(typeof(Heartbeat));
            ClusterMemberEvents memberEvents = mock(typeof(ClusterMemberEvents));

            ObservedClusterMembers members = new ObservedClusterMembers(_logProvider, cluster, heartbeat, memberEvents, _clusterId1);

            ArgumentCaptor <ClusterListener> listener = ArgumentCaptor.forClass(typeof(ClusterListener));

            verify(cluster).addClusterListener(listener.capture());
            listener.Value.enteredCluster(ClusterConfiguration(_clusterUri1, _clusterUri2, _clusterUri3));

            ArgumentCaptor <ClusterMemberListener> memberListener = ArgumentCaptor.forClass(typeof(ClusterMemberListener));

            verify(memberEvents).addClusterMemberListener(memberListener.capture());

            // when
            // first we are available as master
            memberListener.Value.memberIsAvailable(MASTER, _clusterId1, _haUri1, StoreId.DEFAULT);
            // and then for some reason as slave, without an unavailable message in between
            memberListener.Value.memberIsAvailable(SLAVE, _clusterId1, _haUri1, StoreId.DEFAULT);

            // then
            assertThat(members.CurrentMember.HARole, equalTo(SLAVE));
        }
Beispiel #4
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void membersShowsAsUnavailableWhenNewMasterElectedBeforeTheyBecomeAvailable()
        public virtual void MembersShowsAsUnavailableWhenNewMasterElectedBeforeTheyBecomeAvailable()
        {
            // given
            Cluster             cluster      = mock(typeof(Cluster));
            Heartbeat           heartbeat    = mock(typeof(Heartbeat));
            ClusterMemberEvents memberEvents = mock(typeof(ClusterMemberEvents));

            ObservedClusterMembers members = new ObservedClusterMembers(_logProvider, cluster, heartbeat, memberEvents, null);

            ArgumentCaptor <ClusterListener> listener = ArgumentCaptor.forClass(typeof(ClusterListener));

            verify(cluster).addClusterListener(listener.capture());
            listener.Value.enteredCluster(ClusterConfiguration(_clusterUri1, _clusterUri2, _clusterUri3));

            ArgumentCaptor <ClusterMemberListener> memberListener = ArgumentCaptor.forClass(typeof(ClusterMemberListener));

            verify(memberEvents).addClusterMemberListener(memberListener.capture());
            memberListener.Value.memberIsAvailable(SLAVE, _clusterId1, _haUri1, StoreId.DEFAULT);

            // when
            memberListener.Value.coordinatorIsElected(_clusterId2);

            // then
            assertThat(members.Members, hasItem(sameMemberAs(new ClusterMember(_clusterId1))));
        }
Beispiel #5
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void shouldRegisterItselfOnListeners()
        public virtual void ShouldRegisterItselfOnListeners()
        {
            // given
            Cluster             cluster             = mock(typeof(Cluster));
            Heartbeat           heartbeat           = mock(typeof(Heartbeat));
            ClusterMemberEvents clusterMemberEvents = mock(typeof(ClusterMemberEvents));

            // when
            new ObservedClusterMembers(_logProvider, cluster, heartbeat, clusterMemberEvents, null);

            // then
            verify(cluster).addClusterListener(Mockito.any());
            verify(heartbeat).addHeartbeatListener(Mockito.any());
            verify(clusterMemberEvents).addClusterMemberListener(Mockito.any());
        }
Beispiel #6
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);
        }
Beispiel #7
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void shouldContainMemberListAfterEnteringCluster()
        public virtual void ShouldContainMemberListAfterEnteringCluster()
        {
            // given
            Cluster             cluster      = mock(typeof(Cluster));
            Heartbeat           heartbeat    = mock(typeof(Heartbeat));
            ClusterMemberEvents memberEvents = mock(typeof(ClusterMemberEvents));

            ObservedClusterMembers members = new ObservedClusterMembers(_logProvider, cluster, heartbeat, memberEvents, null);

            // when
            ArgumentCaptor <ClusterListener> listener = ArgumentCaptor.forClass(typeof(ClusterListener));

            verify(cluster).addClusterListener(listener.capture());
            listener.Value.enteredCluster(ClusterConfiguration(_clusterUri1, _clusterUri2, _clusterUri3));

            // then
            assertThat(members.Members, hasItems(sameMemberAs(new ClusterMember(_clusterId1)), sameMemberAs(new ClusterMember(_clusterId2)), sameMemberAs(new ClusterMember(_clusterId3))));
        }
Beispiel #8
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void leftMemberDisappearsFromList()
        public virtual void LeftMemberDisappearsFromList()
        {
            // given
            Cluster             cluster      = mock(typeof(Cluster));
            Heartbeat           heartbeat    = mock(typeof(Heartbeat));
            ClusterMemberEvents memberEvents = mock(typeof(ClusterMemberEvents));

            ObservedClusterMembers members = new ObservedClusterMembers(_logProvider, cluster, heartbeat, memberEvents, null);

            ArgumentCaptor <ClusterListener> listener = ArgumentCaptor.forClass(typeof(ClusterListener));

            verify(cluster).addClusterListener(listener.capture());

            listener.Value.enteredCluster(ClusterConfiguration(_clusterUri1, _clusterUri2, _clusterUri3));

            // when
            listener.Value.leftCluster(_clusterId3, _clusterUri3);

            // then
            assertThat(members.Members, not(hasItems(sameMemberAs(new ClusterMember(_clusterId3)))));
        }
Beispiel #9
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void iCanGetToMyself()
        public virtual void ICanGetToMyself()
        {
            // given
            Cluster             cluster      = mock(typeof(Cluster));
            Heartbeat           heartbeat    = mock(typeof(Heartbeat));
            ClusterMemberEvents memberEvents = mock(typeof(ClusterMemberEvents));

            ObservedClusterMembers members = new ObservedClusterMembers(_logProvider, cluster, heartbeat, memberEvents, _clusterId1);

            // when

            ArgumentCaptor <ClusterListener> listener = ArgumentCaptor.forClass(typeof(ClusterListener));

            verify(cluster).addClusterListener(listener.capture());

            listener.Value.enteredCluster(ClusterConfiguration(_clusterUri1, _clusterUri2));

            ClusterMember me = members.CurrentMember;

            assertNotNull(me);
            assertEquals(1, me.InstanceId.toIntegerIndex());
            assertEquals(_clusterId1, me.InstanceId);
        }
Beispiel #10
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void missingMasterUnavailabilityEventForOtherInstanceStillRemovesBackupRole()
        public virtual void MissingMasterUnavailabilityEventForOtherInstanceStillRemovesBackupRole()
        {
            // given
            Cluster             cluster      = mock(typeof(Cluster));
            Heartbeat           heartbeat    = mock(typeof(Heartbeat));
            ClusterMemberEvents memberEvents = mock(typeof(ClusterMemberEvents));

            ObservedClusterMembers members = new ObservedClusterMembers(_logProvider, cluster, heartbeat, memberEvents, _clusterId1);
            // initialized with the members of the cluster
            ArgumentCaptor <ClusterListener> listener = ArgumentCaptor.forClass(typeof(ClusterListener));

            verify(cluster).addClusterListener(listener.capture());
            listener.Value.enteredCluster(ClusterConfiguration(_clusterUri1, _clusterUri2, _clusterUri3));

            ArgumentCaptor <ClusterMemberListener> memberListener = ArgumentCaptor.forClass(typeof(ClusterMemberListener));

            verify(memberEvents).addClusterMemberListener(memberListener.capture());

            // instance 2 is available as MASTER and BACKUP
            memberListener.Value.memberIsAvailable(OnlineBackupKernelExtension.BACKUP, _clusterId2, _clusterUri2, StoreId.DEFAULT);
            memberListener.Value.memberIsAvailable(MASTER, _clusterId2, _clusterUri2, StoreId.DEFAULT);

            // when - instance 2 becomes available as SLAVE
            memberListener.Value.memberIsAvailable(SLAVE, _clusterId2, _clusterUri2, StoreId.DEFAULT);

            // then - instance 2 should be available ONLY as SLAVE
            foreach (ClusterMember clusterMember in members.Members)
            {
                if (clusterMember.InstanceId.Equals(_clusterId2))
                {
                    assertThat(count(clusterMember.Roles), equalTo(1L));
                    assertThat(Iterables.single(clusterMember.Roles), equalTo(SLAVE));
                    break;                              // that's the only member we care about
                }
            }
        }
Beispiel #11
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void availableSlaveShowsProperInformation()
        public virtual void AvailableSlaveShowsProperInformation()
        {
            // given
            Cluster             cluster      = mock(typeof(Cluster));
            Heartbeat           heartbeat    = mock(typeof(Heartbeat));
            ClusterMemberEvents memberEvents = mock(typeof(ClusterMemberEvents));

            ObservedClusterMembers members = new ObservedClusterMembers(_logProvider, cluster, heartbeat, memberEvents, null);

            ArgumentCaptor <ClusterListener> listener = ArgumentCaptor.forClass(typeof(ClusterListener));

            verify(cluster).addClusterListener(listener.capture());
            listener.Value.enteredCluster(ClusterConfiguration(_clusterUri1, _clusterUri2, _clusterUri3));

            ArgumentCaptor <ClusterMemberListener> memberListener = ArgumentCaptor.forClass(typeof(ClusterMemberListener));

            verify(memberEvents).addClusterMemberListener(memberListener.capture());

            // when
            memberListener.Value.memberIsAvailable(SLAVE, _clusterId1, _haUri1, StoreId.DEFAULT);

            // then
            assertThat(members.Members, hasItem(sameMemberAs((new ClusterMember(_clusterId1)).availableAs(SLAVE, _haUri1, StoreId.DEFAULT))));
        }
Beispiel #12
0
 private HighAvailabilityMemberStateMachine BuildMockedStateMachine(HighAvailabilityMemberContext context, ClusterMemberEvents events, Election election)
 {
     return((new HighAvailabilityMemberStateMachineTest.StateMachineBuilder()).WithContext(context).withEvents(events).withElection(election).build());
 }