/// <exception cref="System.IO.IOException"/>
        public virtual void TestNodeLabelsDisabled()
        {
            DummyCommonNodeLabelsManager mgr = new DummyCommonNodeLabelsManager();
            Configuration conf = new YarnConfiguration();

            conf.SetBoolean(YarnConfiguration.NodeLabelsEnabled, false);
            mgr.Init(conf);
            mgr.Start();
            bool caught = false;

            // add labels
            try
            {
                mgr.AddToCluserNodeLabels(ImmutableSet.Of("x"));
            }
            catch (IOException e)
            {
                AssertNodeLabelsDisabledErrorMessage(e);
                caught = true;
            }
            // check exception caught
            NUnit.Framework.Assert.IsTrue(caught);
            caught = false;
            // remove labels
            try
            {
                mgr.RemoveFromClusterNodeLabels(ImmutableSet.Of("x"));
            }
            catch (IOException e)
            {
                AssertNodeLabelsDisabledErrorMessage(e);
                caught = true;
            }
            // check exception caught
            NUnit.Framework.Assert.IsTrue(caught);
            caught = false;
            // add labels to node
            try
            {
                mgr.AddLabelsToNode(ImmutableMap.Of(NodeId.NewInstance("host", 0), CommonNodeLabelsManager
                                                    .EmptyStringSet));
            }
            catch (IOException e)
            {
                AssertNodeLabelsDisabledErrorMessage(e);
                caught = true;
            }
            // check exception caught
            NUnit.Framework.Assert.IsTrue(caught);
            caught = false;
            // remove labels from node
            try
            {
                mgr.RemoveLabelsFromNode(ImmutableMap.Of(NodeId.NewInstance("host", 0), CommonNodeLabelsManager
                                                         .EmptyStringSet));
            }
            catch (IOException e)
            {
                AssertNodeLabelsDisabledErrorMessage(e);
                caught = true;
            }
            // check exception caught
            NUnit.Framework.Assert.IsTrue(caught);
            caught = false;
            // replace labels on node
            try
            {
                mgr.ReplaceLabelsOnNode(ImmutableMap.Of(NodeId.NewInstance("host", 0), CommonNodeLabelsManager
                                                        .EmptyStringSet));
            }
            catch (IOException e)
            {
                AssertNodeLabelsDisabledErrorMessage(e);
                caught = true;
            }
            // check exception caught
            NUnit.Framework.Assert.IsTrue(caught);
            caught = false;
            mgr.Close();
        }
        /// <exception cref="System.Exception"/>
        public virtual void TestAddReplaceRemoveLabelsOnNodes()
        {
            // set a label on a node, but label doesn't exist
            bool caught = false;

            try
            {
                mgr.ReplaceLabelsOnNode(ImmutableMap.Of(ToNodeId("node"), ToSet("label")));
            }
            catch (IOException)
            {
                caught = true;
            }
            NUnit.Framework.Assert.IsTrue("trying to set a label to a node but " + "label doesn't exist in repository should fail"
                                          , caught);
            // set a label on a node, but node is null or empty
            try
            {
                mgr.ReplaceLabelsOnNode(ImmutableMap.Of(ToNodeId(CommonNodeLabelsManager.NoLabel)
                                                        , ToSet("label")));
            }
            catch (IOException)
            {
                caught = true;
            }
            NUnit.Framework.Assert.IsTrue("trying to add a empty node but succeeded", caught);
            // set node->label one by one
            mgr.AddToCluserNodeLabels(ToSet("p1", "p2", "p3"));
            mgr.ReplaceLabelsOnNode(ImmutableMap.Of(ToNodeId("n1"), ToSet("p1")));
            mgr.ReplaceLabelsOnNode(ImmutableMap.Of(ToNodeId("n1"), ToSet("p2")));
            mgr.ReplaceLabelsOnNode(ImmutableMap.Of(ToNodeId("n2"), ToSet("p3")));
            AssertMapEquals(mgr.GetNodeLabels(), ImmutableMap.Of(ToNodeId("n1"), ToSet("p2"),
                                                                 ToNodeId("n2"), ToSet("p3")));
            AssertMapEquals(mgr.lastNodeToLabels, ImmutableMap.Of(ToNodeId("n2"), ToSet("p3")
                                                                  ));
            // set bunch of node->label
            mgr.ReplaceLabelsOnNode((IDictionary)ImmutableMap.Of(ToNodeId("n3"), ToSet("p3"),
                                                                 ToNodeId("n1"), ToSet("p1")));
            AssertMapEquals(mgr.GetNodeLabels(), ImmutableMap.Of(ToNodeId("n1"), ToSet("p1"),
                                                                 ToNodeId("n2"), ToSet("p3"), ToNodeId("n3"), ToSet("p3")));
            AssertMapEquals(mgr.lastNodeToLabels, ImmutableMap.Of(ToNodeId("n3"), ToSet("p3")
                                                                  , ToNodeId("n1"), ToSet("p1")));

            /*
             * n1: p1
             * n2: p3
             * n3: p3
             */
            // remove label on node
            mgr.RemoveLabelsFromNode(ImmutableMap.Of(ToNodeId("n1"), ToSet("p1")));
            AssertMapEquals(mgr.GetNodeLabels(), ImmutableMap.Of(ToNodeId("n2"), ToSet("p3"),
                                                                 ToNodeId("n3"), ToSet("p3")));
            AssertMapEquals(mgr.lastNodeToLabels, ImmutableMap.Of(ToNodeId("n1"), CommonNodeLabelsManager
                                                                  .EmptyStringSet));
            // add label on node
            mgr.AddLabelsToNode(ImmutableMap.Of(ToNodeId("n1"), ToSet("p1")));
            AssertMapEquals(mgr.GetNodeLabels(), ImmutableMap.Of(ToNodeId("n1"), ToSet("p1"),
                                                                 ToNodeId("n2"), ToSet("p3"), ToNodeId("n3"), ToSet("p3")));
            AssertMapEquals(mgr.lastNodeToLabels, ImmutableMap.Of(ToNodeId("n1"), ToSet("p1")
                                                                  ));
            // remove labels on node
            mgr.RemoveLabelsFromNode(ImmutableMap.Of(ToNodeId("n1"), ToSet("p1"), ToNodeId("n2"
                                                                                           ), ToSet("p3"), ToNodeId("n3"), ToSet("p3")));
            NUnit.Framework.Assert.AreEqual(0, mgr.GetNodeLabels().Count);
            AssertMapEquals(mgr.lastNodeToLabels, ImmutableMap.Of(ToNodeId("n1"), CommonNodeLabelsManager
                                                                  .EmptyStringSet, ToNodeId("n2"), CommonNodeLabelsManager.EmptyStringSet, ToNodeId
                                                                      ("n3"), CommonNodeLabelsManager.EmptyStringSet));
        }