Example #1
0
        public virtual void TestAddResolveNodes()
        {
            StaticMapping mapping = NewInstance();

            StaticMapping.AddNodeToRack("n1", "/r1");
            IList <string> queryList = CreateQueryList();
            IList <string> resolved  = mapping.Resolve(queryList);

            Assert.Equal(2, resolved.Count);
            Assert.Equal("/r1", resolved[0]);
            Assert.Equal(NetworkTopology.DefaultRack, resolved[1]);
            // get the switch map and examine it
            IDictionary <string, string> switchMap = mapping.GetSwitchMap();
            string topology = mapping.DumpTopology();

            Log.Info(topology);
            Assert.Equal(topology, 1, switchMap.Count);
            Assert.Equal(topology, "/r1", switchMap["n1"]);
        }
Example #2
0
        public virtual void TestCachingRelaysResolveQueries()
        {
            StaticMapping mapping = NewInstance();

            mapping.SetConf(CreateConf("top"));
            StaticMapping            staticMapping = mapping;
            CachedDNSToSwitchMapping cachedMap     = new CachedDNSToSwitchMapping(staticMapping);

            AssertMapSize(cachedMap, 0);
            //add a node to the static map
            StaticMapping.AddNodeToRack("n1", "/r1");
            //verify it is there
            AssertMapSize(staticMapping, 1);
            //verify that the cache hasn't picked it up yet
            AssertMapSize(cachedMap, 0);
            //now relay the query
            cachedMap.Resolve(CreateQueryList());
            //and verify the cache is no longer empty
            AssertMapSize(cachedMap, 2);
        }
        /// <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();
                }
            }
        }