public virtual void TestRefreshNamenodes() { // Start cluster with a single NN and DN Configuration conf = new Configuration(); MiniDFSCluster cluster = null; try { MiniDFSNNTopology topology = new MiniDFSNNTopology().AddNameservice(new MiniDFSNNTopology.NSConf ("ns1").AddNN(new MiniDFSNNTopology.NNConf(null).SetIpcPort(nnPort1))).SetFederation (true); cluster = new MiniDFSCluster.Builder(conf).NnTopology(topology).Build(); DataNode dn = cluster.GetDataNodes()[0]; NUnit.Framework.Assert.AreEqual(1, dn.GetAllBpOs().Length); cluster.AddNameNode(conf, nnPort2); NUnit.Framework.Assert.AreEqual(2, dn.GetAllBpOs().Length); cluster.AddNameNode(conf, nnPort3); NUnit.Framework.Assert.AreEqual(3, dn.GetAllBpOs().Length); cluster.AddNameNode(conf, nnPort4); // Ensure a BPOfferService in the datanodes corresponds to // a namenode in the cluster ICollection <IPEndPoint> nnAddrsFromCluster = Sets.NewHashSet(); for (int i = 0; i < 4; i++) { NUnit.Framework.Assert.IsTrue(nnAddrsFromCluster.AddItem(cluster.GetNameNode(i).GetNameNodeAddress ())); } ICollection <IPEndPoint> nnAddrsFromDN = Sets.NewHashSet(); foreach (BPOfferService bpos in dn.GetAllBpOs()) { foreach (BPServiceActor bpsa in bpos.GetBPServiceActors()) { NUnit.Framework.Assert.IsTrue(nnAddrsFromDN.AddItem(bpsa.GetNNSocketAddress())); } } NUnit.Framework.Assert.AreEqual(string.Empty, Joiner.On(",").Join(Sets.SymmetricDifference (nnAddrsFromCluster, nnAddrsFromDN))); } finally { if (cluster != null) { cluster.Shutdown(); } } }
public virtual void TestClusterIdMismatch() { MiniDFSCluster cluster = new MiniDFSCluster.Builder(conf).NnTopology(MiniDFSNNTopology .SimpleFederatedTopology(2)).Build(); try { cluster.WaitActive(); DataNode dn = cluster.GetDataNodes()[0]; BPOfferService[] bposs = dn.GetAllBpOs(); Log.Info("dn bpos len (should be 2):" + bposs.Length); NUnit.Framework.Assert.AreEqual("should've registered with two namenodes", bposs. Length, 2); // add another namenode cluster.AddNameNode(conf, 9938); Sharpen.Thread.Sleep(500); // lets wait for the registration to happen bposs = dn.GetAllBpOs(); Log.Info("dn bpos len (should be 3):" + bposs.Length); NUnit.Framework.Assert.AreEqual("should've registered with three namenodes", bposs .Length, 3); // change cluster id and another Namenode HdfsServerConstants.StartupOption.Format.SetClusterId("DifferentCID"); cluster.AddNameNode(conf, 9948); NameNode nn4 = cluster.GetNameNode(3); NUnit.Framework.Assert.IsNotNull("cannot create nn4", nn4); Sharpen.Thread.Sleep(500); // lets wait for the registration to happen bposs = dn.GetAllBpOs(); Log.Info("dn bpos len (still should be 3):" + bposs.Length); NUnit.Framework.Assert.AreEqual("should've registered with three namenodes", 3, bposs .Length); } finally { cluster.Shutdown(); } }
public virtual void TestMiniDFSClusterWithMultipleNN() { Configuration conf = new HdfsConfiguration(); // start Federated cluster and add a node. MiniDFSCluster cluster = new MiniDFSCluster.Builder(conf).NnTopology(MiniDFSNNTopology .SimpleFederatedTopology(2)).Build(); // add a node try { cluster.WaitActive(); NUnit.Framework.Assert.AreEqual("(1)Should be 2 namenodes", 2, cluster.GetNumNameNodes ()); cluster.AddNameNode(conf, 0); NUnit.Framework.Assert.AreEqual("(1)Should be 3 namenodes", 3, cluster.GetNumNameNodes ()); } catch (IOException ioe) { NUnit.Framework.Assert.Fail("Failed to add NN to cluster:" + StringUtils.StringifyException (ioe)); } finally { cluster.Shutdown(); } // 2. start with Federation flag set conf = new HdfsConfiguration(); cluster = new MiniDFSCluster.Builder(conf).NnTopology(MiniDFSNNTopology.SimpleFederatedTopology (1)).Build(); try { NUnit.Framework.Assert.IsNotNull(cluster); cluster.WaitActive(); NUnit.Framework.Assert.AreEqual("(2)Should be 1 namenodes", 1, cluster.GetNumNameNodes ()); // add a node cluster.AddNameNode(conf, 0); NUnit.Framework.Assert.AreEqual("(2)Should be 2 namenodes", 2, cluster.GetNumNameNodes ()); } catch (IOException ioe) { NUnit.Framework.Assert.Fail("Failed to add NN to cluster:" + StringUtils.StringifyException (ioe)); } finally { cluster.Shutdown(); } // 3. start non-federated conf = new HdfsConfiguration(); cluster = new MiniDFSCluster.Builder(conf).Build(); // add a node try { cluster.WaitActive(); NUnit.Framework.Assert.IsNotNull(cluster); NUnit.Framework.Assert.AreEqual("(2)Should be 1 namenodes", 1, cluster.GetNumNameNodes ()); cluster.AddNameNode(conf, 9929); NUnit.Framework.Assert.Fail("shouldn't be able to add another NN to non federated cluster" ); } catch (IOException e) { // correct NUnit.Framework.Assert.IsTrue(e.Message.StartsWith("cannot add namenode")); NUnit.Framework.Assert.AreEqual("(3)Should be 1 namenodes", 1, cluster.GetNumNameNodes ()); } finally { cluster.Shutdown(); } }