示例#1
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void shouldSupportConcurrentConsumptionOfSlaves() throws Exception
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        public virtual void ShouldSupportConcurrentConsumptionOfSlaves()
        {
            // Given
            LogEntryReader <ReadableClosablePositionAwareChannel> logEntryReader = new VersionAwareLogEntryReader <ReadableClosablePositionAwareChannel>();
            HighAvailabilitySlaves haSlaves = new HighAvailabilitySlaves(ClusterMembersOfSize(1000), mock(typeof(Cluster)), new DefaultSlaveFactory(NullLogProvider.Instance, new Monitors(), 42, Suppliers.singleton(logEntryReader)), new HostnamePort(null, 0));

            // When
            ExecutorService executor = Executors.newFixedThreadPool(5);

            for (int i = 0; i < 5; i++)
            {
                executor.submit(SlavesConsumingRunnable(haSlaves));
            }
            executor.shutdown();
            executor.awaitTermination(30, SECONDS);

            // Then
            int         slavesCount = 0;
            LifeSupport life        = ReflectionUtil.getPrivateField(haSlaves, "life", typeof(LifeSupport));

            foreach (Lifecycle lifecycle in life.LifecycleInstances)
            {
                if (lifecycle is Slave)
                {
                    slavesCount++;
                }
            }
            assertEquals("Unexpected number of slaves", 1000 - 1, slavesCount);                 // One instance is master
        }
示例#2
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)));
        }
示例#3
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: private static Runnable slavesConsumingRunnable(final HighAvailabilitySlaves haSlaves)
        private static ThreadStart SlavesConsumingRunnable(HighAvailabilitySlaves haSlaves)
        {
            return(() =>
            {
                foreach (Slave slave in haSlaves.Slaves)
                {
                    assertNotNull(slave);
                }
            });
        }
示例#4
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));
        }
示例#5
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));
        }
示例#6
0
 public HASClusterListener(HighAvailabilitySlaves outerInstance)
 {
     this._outerInstance = outerInstance;
 }