Ejemplo n.º 1
0
        /// <summary>
        /// This test also serves to test
        /// <see cref="Org.Apache.Hadoop.Hdfs.HAUtil.GetProxiesForAllNameNodesInNameservice(Org.Apache.Hadoop.Conf.Configuration, string)
        ///     "/>
        /// and
        /// <see cref="Org.Apache.Hadoop.Hdfs.DFSUtil.GetRpcAddressesForNameserviceId(Org.Apache.Hadoop.Conf.Configuration, string, string)
        ///     "/>
        /// by virtue of the fact that it wouldn't work properly if the proxies
        /// returned were not for the correct NNs.
        /// </summary>
        /// <exception cref="System.Exception"/>
        public virtual void TestIsAtLeastOneActive()
        {
            MiniDFSCluster cluster = new MiniDFSCluster.Builder(new HdfsConfiguration()).NnTopology
                                         (MiniDFSNNTopology.SimpleHATopology()).NumDataNodes(0).Build();

            try
            {
                Configuration conf = new HdfsConfiguration();
                HATestUtil.SetFailoverConfigurations(cluster, conf);
                IList <ClientProtocol> namenodes = HAUtil.GetProxiesForAllNameNodesInNameservice(conf
                                                                                                 , HATestUtil.GetLogicalHostname(cluster));
                NUnit.Framework.Assert.AreEqual(2, namenodes.Count);
                NUnit.Framework.Assert.IsFalse(HAUtil.IsAtLeastOneActive(namenodes));
                cluster.TransitionToActive(0);
                NUnit.Framework.Assert.IsTrue(HAUtil.IsAtLeastOneActive(namenodes));
                cluster.TransitionToStandby(0);
                NUnit.Framework.Assert.IsFalse(HAUtil.IsAtLeastOneActive(namenodes));
                cluster.TransitionToActive(1);
                NUnit.Framework.Assert.IsTrue(HAUtil.IsAtLeastOneActive(namenodes));
                cluster.TransitionToStandby(1);
                NUnit.Framework.Assert.IsFalse(HAUtil.IsAtLeastOneActive(namenodes));
            }
            finally
            {
                if (cluster != null)
                {
                    cluster.Shutdown();
                }
            }
        }