Ejemplo n.º 1
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void shouldClearSlavesWhenNewMasterElected()
        public virtual void ShouldClearSlavesWhenNewMasterElected()
        {
            // given
            Cluster        cluster        = mock(typeof(Cluster));
            ClusterMembers clusterMembers = mock(typeof(ClusterMembers));

            when(clusterMembers.AliveMembers).thenReturn(Iterables.option((new ClusterMember(_instanceId)).availableAs(SLAVE, _haUri, StoreId.DEFAULT)));

            SlaveFactory slaveFactory = mock(typeof(SlaveFactory));
            Slave        slave1       = mock(typeof(Slave));
            Slave        slave2       = mock(typeof(Slave));

            when(slaveFactory.NewSlave(any(typeof(LifeSupport)), any(typeof(ClusterMember)), any(typeof(string)), any(typeof(Integer)))).thenReturn(slave1, slave2);

            HighAvailabilitySlaves slaves = new HighAvailabilitySlaves(clusterMembers, cluster, slaveFactory, new HostnamePort("localhost", 0));

            slaves.Init();

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

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

            // when
            Slave actualSlave1 = slaves.Slaves.GetEnumerator().next();

            listener.Value.elected(ClusterConfiguration.COORDINATOR, _instanceId, _clusterUri);

            Slave actualSlave2 = slaves.Slaves.GetEnumerator().next();

            // then
            assertThat(actualSlave2, not(sameInstance(actualSlave1)));
        }
Ejemplo n.º 2
0
 public HighAvailabilitySlaves(ClusterMembers clusterMembers, Cluster cluster, SlaveFactory slaveFactory, HostnamePort me)
 {
     this._clusterMembers = clusterMembers;
     this._cluster        = cluster;
     this._slaveFactory   = slaveFactory;
     this._me             = me;
 }
Ejemplo n.º 3
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void shouldRegisterItselfOnMonitors()
        public virtual void ShouldRegisterItselfOnMonitors()
        {
            // given
            ClusterMembers clusterMembers = mock(typeof(ClusterMembers));
            Cluster        cluster        = mock(typeof(Cluster));
            SlaveFactory   slaveFactory   = mock(typeof(SlaveFactory));

            // when
            (new HighAvailabilitySlaves(clusterMembers, cluster, slaveFactory, new HostnamePort(null, 0))).init();

            // then
            verify(cluster).addClusterListener(any(typeof(ClusterListener)));
        }
Ejemplo n.º 4
0
        private static ClusterMembers ClusterMembersOfSize(int size)
        {
            IList <ClusterMember> members = new List <ClusterMember>(size);

            members.Add(MockClusterMemberWithRole(HighAvailabilityModeSwitcher.MASTER));
            for (int i = 0; i < size - 1; i++)
            {
                members.Add(MockClusterMemberWithRole(SLAVE));
            }

            ClusterMembers clusterMembers = mock(typeof(ClusterMembers));

            when(clusterMembers.AliveMembers).thenReturn(members);

            return(clusterMembers);
        }
Ejemplo n.º 5
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void shouldNotReturnUnavailableSlaves()
        public virtual void ShouldNotReturnUnavailableSlaves()
        {
            // given
            Cluster        cluster        = mock(typeof(Cluster));
            ClusterMembers clusterMembers = mock(typeof(ClusterMembers));

            when(clusterMembers.AliveMembers).thenReturn(Iterables.option(new ClusterMember(_instanceId)));

            SlaveFactory slaveFactory = mock(typeof(SlaveFactory));

            HighAvailabilitySlaves slaves = new HighAvailabilitySlaves(clusterMembers, cluster, slaveFactory, new HostnamePort(null, 0));

            slaves.Init();

            // when
            IEnumerable <Slave> memberSlaves = slaves.Slaves;

            // then
            assertThat(count(memberSlaves), equalTo(0L));
        }
Ejemplo n.º 6
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void shouldReturnAvailableAndAliveSlaves()
        public virtual void ShouldReturnAvailableAndAliveSlaves()
        {
            // given
            Cluster        cluster        = mock(typeof(Cluster));
            ClusterMembers clusterMembers = mock(typeof(ClusterMembers));

            when(clusterMembers.AliveMembers).thenReturn(Iterables.option((new ClusterMember(_instanceId)).availableAs(SLAVE, _haUri, StoreId.DEFAULT)));

            SlaveFactory slaveFactory = mock(typeof(SlaveFactory));
            Slave        slave        = mock(typeof(Slave));

            when(slaveFactory.NewSlave(any(typeof(LifeSupport)), any(typeof(ClusterMember)), any(typeof(string)), any(typeof(Integer)))).thenReturn(slave);

            HighAvailabilitySlaves slaves = new HighAvailabilitySlaves(clusterMembers, cluster, slaveFactory, new HostnamePort(null, 0));

            slaves.Init();

            // when
            IEnumerable <Slave> memberSlaves = slaves.Slaves;

            // then
            assertThat(count(memberSlaves), equalTo(1L));
        }
Ejemplo n.º 7
0
 private void InitializeInstanceFields()
 {
     _clusterMembers = new ClusterMembers(_observedClusterMembers, _stateMachine);
 }