/// <exception cref="System.Exception"/>
 public virtual void TestAddRemovelabel()
 {
     // Add some label
     mgr.AddToCluserNodeLabels(ImmutableSet.Of("hello"));
     AssertCollectionEquals(mgr.lastAddedlabels, Arrays.AsList("hello"));
     mgr.AddToCluserNodeLabels(ImmutableSet.Of("world"));
     mgr.AddToCluserNodeLabels(ToSet("hello1", "world1"));
     AssertCollectionEquals(mgr.lastAddedlabels, Sets.NewHashSet("hello1", "world1"));
     NUnit.Framework.Assert.IsTrue(mgr.GetClusterNodeLabels().ContainsAll(Sets.NewHashSet
                                                                              ("hello", "world", "hello1", "world1")));
     // try to remove null, empty and non-existed label, should fail
     foreach (string p in Arrays.AsList(null, CommonNodeLabelsManager.NoLabel, "xx"))
     {
         bool caught = false;
         try
         {
             mgr.RemoveFromClusterNodeLabels(Arrays.AsList(p));
         }
         catch (IOException)
         {
             caught = true;
         }
         NUnit.Framework.Assert.IsTrue("remove label should fail " + "when label is null/empty/non-existed"
                                       , caught);
     }
     // Remove some label
     mgr.RemoveFromClusterNodeLabels(Arrays.AsList("hello"));
     AssertCollectionEquals(mgr.lastRemovedlabels, Arrays.AsList("hello"));
     NUnit.Framework.Assert.IsTrue(mgr.GetClusterNodeLabels().ContainsAll(Arrays.AsList
                                                                              ("world", "hello1", "world1")));
     mgr.RemoveFromClusterNodeLabels(Arrays.AsList("hello1", "world1", "world"));
     NUnit.Framework.Assert.IsTrue(mgr.lastRemovedlabels.ContainsAll(Sets.NewHashSet("hello1"
                                                                                     , "world1", "world")));
     NUnit.Framework.Assert.IsTrue(mgr.GetClusterNodeLabels().IsEmpty());
 }
        /// <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();
        }