public virtual void TestSimplePlacementPolicyFromConf()
        {
            Configuration conf = new Configuration();

            conf.Set(FairSchedulerConfiguration.AllocationFile, AllocFile);
            conf.SetBoolean(FairSchedulerConfiguration.AllowUndeclaredPools, false);
            conf.SetBoolean(FairSchedulerConfiguration.UserAsDefaultQueue, false);
            PrintWriter @out = new PrintWriter(new FileWriter(AllocFile));

            @out.WriteLine("<?xml version=\"1.0\"?>");
            @out.WriteLine("<allocations>");
            @out.WriteLine("</allocations>");
            @out.Close();
            AllocationFileLoaderService allocLoader = new AllocationFileLoaderService();

            allocLoader.Init(conf);
            TestAllocationFileLoaderService.ReloadListener confHolder = new TestAllocationFileLoaderService.ReloadListener
                                                                            (this);
            allocLoader.SetReloadListener(confHolder);
            allocLoader.ReloadAllocations();
            AllocationConfiguration    allocConf       = confHolder.allocConf;
            QueuePlacementPolicy       placementPolicy = allocConf.GetPlacementPolicy();
            IList <QueuePlacementRule> rules           = placementPolicy.GetRules();

            NUnit.Framework.Assert.AreEqual(2, rules.Count);
            NUnit.Framework.Assert.AreEqual(typeof(QueuePlacementRule.Specified), rules[0].GetType
                                                ());
            NUnit.Framework.Assert.AreEqual(false, rules[0].create);
            NUnit.Framework.Assert.AreEqual(typeof(QueuePlacementRule.Default), rules[1].GetType
                                                ());
        }
        /// <exception cref="System.Exception"/>
        public virtual void TestReload()
        {
            PrintWriter @out = new PrintWriter(new FileWriter(AllocFile));

            @out.WriteLine("<?xml version=\"1.0\"?>");
            @out.WriteLine("<allocations>");
            @out.WriteLine("  <queue name=\"queueA\">");
            @out.WriteLine("    <maxRunningApps>1</maxRunningApps>");
            @out.WriteLine("  </queue>");
            @out.WriteLine("  <queue name=\"queueB\" />");
            @out.WriteLine("  <queuePlacementPolicy>");
            @out.WriteLine("    <rule name='default' />");
            @out.WriteLine("  </queuePlacementPolicy>");
            @out.WriteLine("</allocations>");
            @out.Close();
            TestAllocationFileLoaderService.MockClock clock = new TestAllocationFileLoaderService.MockClock
                                                                  (this);
            Configuration conf = new Configuration();

            conf.Set(FairSchedulerConfiguration.AllocationFile, AllocFile);
            AllocationFileLoaderService allocLoader = new AllocationFileLoaderService(clock);

            allocLoader.reloadIntervalMs = 5;
            allocLoader.Init(conf);
            TestAllocationFileLoaderService.ReloadListener confHolder = new TestAllocationFileLoaderService.ReloadListener
                                                                            (this);
            allocLoader.SetReloadListener(confHolder);
            allocLoader.ReloadAllocations();
            AllocationConfiguration allocConf = confHolder.allocConf;
            // Verify conf
            QueuePlacementPolicy       policy = allocConf.GetPlacementPolicy();
            IList <QueuePlacementRule> rules  = policy.GetRules();

            NUnit.Framework.Assert.AreEqual(1, rules.Count);
            NUnit.Framework.Assert.AreEqual(typeof(QueuePlacementRule.Default), rules[0].GetType
                                                ());
            NUnit.Framework.Assert.AreEqual(1, allocConf.GetQueueMaxApps("root.queueA"));
            NUnit.Framework.Assert.AreEqual(2, allocConf.GetConfiguredQueues()[FSQueueType.Leaf
                                            ].Count);
            NUnit.Framework.Assert.IsTrue(allocConf.GetConfiguredQueues()[FSQueueType.Leaf].Contains
                                              ("root.queueA"));
            NUnit.Framework.Assert.IsTrue(allocConf.GetConfiguredQueues()[FSQueueType.Leaf].Contains
                                              ("root.queueB"));
            confHolder.allocConf = null;
            // Modify file and advance the clock
            @out = new PrintWriter(new FileWriter(AllocFile));
            @out.WriteLine("<?xml version=\"1.0\"?>");
            @out.WriteLine("<allocations>");
            @out.WriteLine("  <queue name=\"queueB\">");
            @out.WriteLine("    <maxRunningApps>3</maxRunningApps>");
            @out.WriteLine("  </queue>");
            @out.WriteLine("  <queuePlacementPolicy>");
            @out.WriteLine("    <rule name='specified' />");
            @out.WriteLine("    <rule name='nestedUserQueue' >");
            @out.WriteLine("         <rule name='primaryGroup' />");
            @out.WriteLine("    </rule>");
            @out.WriteLine("    <rule name='default' />");
            @out.WriteLine("  </queuePlacementPolicy>");
            @out.WriteLine("</allocations>");
            @out.Close();
            clock.Tick(Runtime.CurrentTimeMillis() + AllocationFileLoaderService.AllocReloadWaitMs
                       + 10000);
            allocLoader.Start();
            while (confHolder.allocConf == null)
            {
                Sharpen.Thread.Sleep(20);
            }
            // Verify conf
            allocConf = confHolder.allocConf;
            policy    = allocConf.GetPlacementPolicy();
            rules     = policy.GetRules();
            NUnit.Framework.Assert.AreEqual(3, rules.Count);
            NUnit.Framework.Assert.AreEqual(typeof(QueuePlacementRule.Specified), rules[0].GetType
                                                ());
            NUnit.Framework.Assert.AreEqual(typeof(QueuePlacementRule.NestedUserQueue), rules
                                            [1].GetType());
            NUnit.Framework.Assert.AreEqual(typeof(QueuePlacementRule.PrimaryGroup), ((QueuePlacementRule.NestedUserQueue
                                                                                       )(rules[1])).nestedRule.GetType());
            NUnit.Framework.Assert.AreEqual(typeof(QueuePlacementRule.Default), rules[2].GetType
                                                ());
            NUnit.Framework.Assert.AreEqual(3, allocConf.GetQueueMaxApps("root.queueB"));
            NUnit.Framework.Assert.AreEqual(1, allocConf.GetConfiguredQueues()[FSQueueType.Leaf
                                            ].Count);
            NUnit.Framework.Assert.IsTrue(allocConf.GetConfiguredQueues()[FSQueueType.Leaf].Contains
                                              ("root.queueB"));
        }