コード例 #1
0
        public virtual void TestCreateInvalidTopology()
        {
            NetworkTopology invalCluster = new NetworkTopology();

            DatanodeDescriptor[] invalDataNodes = new DatanodeDescriptor[] { DFSTestUtil.GetDatanodeDescriptor
                                                                                 ("1.1.1.1", "/d1/r1"), DFSTestUtil.GetDatanodeDescriptor("2.2.2.2", "/d1/r1"), DFSTestUtil
                                                                             .GetDatanodeDescriptor("3.3.3.3", "/d1") };
            invalCluster.Add(invalDataNodes[0]);
            invalCluster.Add(invalDataNodes[1]);
            try
            {
                invalCluster.Add(invalDataNodes[2]);
                NUnit.Framework.Assert.Fail("expected InvalidTopologyException");
            }
            catch (NetworkTopology.InvalidTopologyException e)
            {
                NUnit.Framework.Assert.IsTrue(e.Message.StartsWith("Failed to add "));
                NUnit.Framework.Assert.IsTrue(e.Message.Contains("You cannot have a rack and a non-rack node at the same "
                                                                 + "level of the network topology."));
            }
        }
コード例 #2
0
        public virtual void TestCountNumNodes()
        {
            // create the topology
            NetworkTopology cluster = new NetworkTopology();

            cluster.Add(GetNewNode("node1", "/d1/r1"));
            TestClusterTopology.NodeElement node2 = GetNewNode("node2", "/d1/r2");
            cluster.Add(node2);
            cluster.Add(GetNewNode("node3", "/d1/r3"));
            TestClusterTopology.NodeElement node3 = GetNewNode("node4", "/d1/r4");
            cluster.Add(node3);
            // create exclude list
            IList <Node> excludedNodes = new AList <Node>();

            Assert.Equal("4 nodes should be available", 4, cluster.CountNumOfAvailableNodes
                             (NodeBase.Root, excludedNodes));
            TestClusterTopology.NodeElement deadNode = GetNewNode("node5", "/d1/r2");
            excludedNodes.AddItem(deadNode);
            Assert.Equal("4 nodes should be available with extra excluded Node"
                         , 4, cluster.CountNumOfAvailableNodes(NodeBase.Root, excludedNodes));
            // add one existing node to exclude list
            excludedNodes.AddItem(node3);
            Assert.Equal("excluded nodes with ROOT scope should be considered"
                         , 3, cluster.CountNumOfAvailableNodes(NodeBase.Root, excludedNodes));
            Assert.Equal("excluded nodes without ~ scope should be considered"
                         , 2, cluster.CountNumOfAvailableNodes("~" + deadNode.GetNetworkLocation(), excludedNodes
                                                               ));
            Assert.Equal("excluded nodes with rack scope should be considered"
                         , 1, cluster.CountNumOfAvailableNodes(deadNode.GetNetworkLocation(), excludedNodes
                                                               ));
            // adding the node in excluded scope to excluded list
            excludedNodes.AddItem(node2);
            Assert.Equal("excluded nodes with ~ scope should be considered"
                         , 2, cluster.CountNumOfAvailableNodes("~" + deadNode.GetNetworkLocation(), excludedNodes
                                                               ));
            // getting count with non-exist scope.
            Assert.Equal("No nodes should be considered for non-exist scope"
                         , 0, cluster.CountNumOfAvailableNodes("/non-exist", excludedNodes));
        }
コード例 #3
0
        /// <exception cref="System.Exception"/>
        public virtual void TestInvalidNetworkTopologiesNotCachedInHdfs()
        {
            // start a cluster
            Configuration  conf    = new HdfsConfiguration();
            MiniDFSCluster cluster = null;

            try
            {
                // bad rack topology
                string[] racks = new string[] { "/a/b", "/c" };
                string[] hosts = new string[] { "foo1.example.com", "foo2.example.com" };
                cluster = new MiniDFSCluster.Builder(conf).NumDataNodes(2).Racks(racks).Hosts(hosts
                                                                                              ).Build();
                cluster.WaitActive();
                NamenodeProtocols nn = cluster.GetNameNodeRpc();
                NUnit.Framework.Assert.IsNotNull(nn);
                // Wait for one DataNode to register.
                // The other DataNode will not be able to register up because of the rack mismatch.
                DatanodeInfo[] info;
                while (true)
                {
                    info = nn.GetDatanodeReport(HdfsConstants.DatanodeReportType.Live);
                    NUnit.Framework.Assert.IsFalse(info.Length == 2);
                    if (info.Length == 1)
                    {
                        break;
                    }
                    Sharpen.Thread.Sleep(1000);
                }
                // Set the network topology of the other node to the match the network
                // topology of the node that came up.
                int validIdx   = info[0].GetHostName().Equals(hosts[0]) ? 0 : 1;
                int invalidIdx = validIdx == 1 ? 0 : 1;
                StaticMapping.AddNodeToRack(hosts[invalidIdx], racks[validIdx]);
                Log.Info("datanode " + validIdx + " came up with network location " + info[0].GetNetworkLocation
                             ());
                // Restart the DN with the invalid topology and wait for it to register.
                cluster.RestartDataNode(invalidIdx);
                Sharpen.Thread.Sleep(5000);
                while (true)
                {
                    info = nn.GetDatanodeReport(HdfsConstants.DatanodeReportType.Live);
                    if (info.Length == 2)
                    {
                        break;
                    }
                    if (info.Length == 0)
                    {
                        Log.Info("got no valid DNs");
                    }
                    else
                    {
                        if (info.Length == 1)
                        {
                            Log.Info("got one valid DN: " + info[0].GetHostName() + " (at " + info[0].GetNetworkLocation
                                         () + ")");
                        }
                    }
                    Sharpen.Thread.Sleep(1000);
                }
                NUnit.Framework.Assert.AreEqual(info[0].GetNetworkLocation(), info[1].GetNetworkLocation
                                                    ());
            }
            finally
            {
                if (cluster != null)
                {
                    cluster.Shutdown();
                }
            }
        }