Esempio n. 1
0
        private static ClusterMember MockClusterMemberWithRole(string role)
        {
            ClusterMember member = mock(typeof(ClusterMember));

            when(member.HAUri).thenReturn(URI.create("http://localhost:7474"));
            when(member.Alive).thenReturn(true);
            when(member.HasRole(eq(role))).thenReturn(true);
            return(member);
        }
Esempio n. 2
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void currentMemberHasCorrectRoleWhenInToMasterState()
        public virtual void CurrentMemberHasCorrectRoleWhenInToMasterState()
        {
            ClusterMember member = CreateClusterMember(1, HighAvailabilityModeSwitcher.MASTER);

            when(_observedClusterMembers.CurrentMember).thenReturn(member);
            when(_stateMachine.CurrentState).thenReturn(HighAvailabilityMemberState.TO_MASTER);

            assertEquals(HighAvailabilityModeSwitcher.UNKNOWN, _clusterMembers.CurrentMemberRole);
        }
Esempio n. 3
0
        private ClusterMember GetMember(InstanceId server)
        {
            ClusterMember clusterMember = _members[server];

            if (clusterMember == null)
            {
                throw new System.InvalidOperationException("Member " + server + " not found in " + new Dictionary <>(_members));
            }
            return(clusterMember);
        }
Esempio n. 4
0
            public override void MemberIsFailed(InstanceId instanceId)
            {
                // Make it unavailable for all its current roles
                ClusterMember member = outerInstance.getMember(instanceId);

                foreach (string role in member.Roles)
                {
                    member = member.UnavailableAs(role);
                }
                outerInstance.members[instanceId] = member;
            }
Esempio n. 5
0
        private IEnumerable <ClusterMember> GetActualMembers(IEnumerable <ClusterMember> members)
        {
//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
//ORIGINAL LINE: final ClusterMember currentMember = getCurrentMember();
            ClusterMember currentMember = CurrentMember;

            if (currentMember == null)
            {
                return(members);
            }
            return(Iterables.map(member => currentMember.InstanceId.Equals(member.InstanceId) ? currentMember : member, members));
        }
Esempio n. 6
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void currentInstanceStateUpdated()
        public virtual void CurrentInstanceStateUpdated()
        {
            ClusterMember currentInstance = CreateClusterMember(1, HighAvailabilityModeSwitcher.UNKNOWN);

            when(_observedClusterMembers.AliveMembers).thenReturn(Collections.singletonList(currentInstance));
            when(_observedClusterMembers.CurrentMember).thenReturn(currentInstance);
            when(_stateMachine.CurrentState).thenReturn(HighAvailabilityMemberState.MASTER);

            ClusterMember self = _clusterMembers.CurrentMember;

            assertEquals(HighAvailabilityModeSwitcher.MASTER, self.HARole);
        }
Esempio n. 7
0
            public override void EnteredCluster(ClusterConfiguration configuration)
            {
                IDictionary <InstanceId, ClusterMember> newMembers = new Dictionary <InstanceId, ClusterMember>();

                foreach (InstanceId memberClusterId in configuration.MemberIds)
                {
                    newMembers[memberClusterId] = new ClusterMember(memberClusterId);
                }
                outerInstance.members.Clear();
//JAVA TO C# CONVERTER TODO TASK: There is no .NET Dictionary equivalent to the Java 'putAll' method:
                outerInstance.members.putAll(newMembers);
            }
Esempio n. 8
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void observedStateDoesNotKnowCurrentInstance()
        public virtual void ObservedStateDoesNotKnowCurrentInstance()
        {
            ClusterMember         currentInstance = CreateClusterMember(1, HighAvailabilityModeSwitcher.SLAVE);
            ClusterMember         otherInstance   = CreateClusterMember(2, HighAvailabilityModeSwitcher.MASTER);
            IList <ClusterMember> members         = Arrays.asList(currentInstance, otherInstance);

            when(_observedClusterMembers.Members).thenReturn(members);
            when(_observedClusterMembers.CurrentMember).thenReturn(null);
            when(_stateMachine.CurrentState).thenReturn(HighAvailabilityMemberState.SLAVE);

            assertNull(_clusterMembers.CurrentMember);
            assertEquals(members, _clusterMembers.Members);
        }
Esempio n. 9
0
        private static ClusterMember UpdateRole(ClusterMember member, HighAvailabilityMemberState state)
        {
            switch (state.innerEnumValue)
            {
            case HighAvailabilityMemberState.InnerEnum.MASTER:
                return(member.AvailableAs(HighAvailabilityModeSwitcher.MASTER, member.HAUri, member.StoreId));

            case HighAvailabilityMemberState.InnerEnum.SLAVE:
                return(member.AvailableAs(HighAvailabilityModeSwitcher.SLAVE, member.HAUri, member.StoreId));

            default:
                return(member.Unavailable());
            }
        }
Esempio n. 10
0
        public override bool Equals(object o)
        {
            if (this == o)
            {
                return(true);
            }
            if (o == null || this.GetType() != o.GetType())
            {
                return(false);
            }
            ClusterMember that = ( ClusterMember )o;

            return(_instanceId.Equals(that._instanceId));
        }
Esempio n. 11
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void incorrectlyObservedCurrentInstanceStateUpdated()
        public virtual void IncorrectlyObservedCurrentInstanceStateUpdated()
        {
            ClusterMember         currentInstance = CreateClusterMember(1, HighAvailabilityModeSwitcher.SLAVE);
            ClusterMember         otherInstance   = CreateClusterMember(2, HighAvailabilityModeSwitcher.MASTER);
            IList <ClusterMember> members         = Arrays.asList(currentInstance, otherInstance);

            when(_observedClusterMembers.Members).thenReturn(members);
            when(_observedClusterMembers.CurrentMember).thenReturn(currentInstance);
            when(_stateMachine.CurrentState).thenReturn(HighAvailabilityMemberState.MASTER);

            IEnumerable <ClusterMember> currentMembers = _clusterMembers.Members;

            assertEquals("All members should be available", 2, Iterables.count(currentMembers));
            assertEquals(2, CountInstancesWithRole(currentMembers, HighAvailabilityModeSwitcher.MASTER));
        }
Esempio n. 12
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);
        }
Esempio n. 13
0
        private static ClusterMember CreateClusterMember(int id, string role)
        {
            ClusterMember member = new ClusterMember(new InstanceId(id));

            return(member.AvailableAs(role, null, StoreId.DEFAULT));
        }
Esempio n. 14
0
//JAVA TO C# CONVERTER WARNING: 'final' parameters are ignored unless the option to convert to C# 7.2 'in' parameters is selected:
//ORIGINAL LINE: public static org.hamcrest.Matcher<ClusterMember> sameMemberAs(final ClusterMember clusterMember)
        public static Matcher <ClusterMember> SameMemberAs(ClusterMember clusterMember)
        {
            return(new BaseMatcherAnonymousInnerClass(clusterMember));
        }