public virtual void TestZKAuths()
        {
            TestZKRMStateStoreZKClientConnections.TestZKClient zkClientTester = new TestZKRMStateStoreZKClientConnections.TestZKClient
                                                                                    (this);
            YarnConfiguration conf = new YarnConfiguration();

            conf.SetInt(YarnConfiguration.RmZkNumRetries, 1);
            conf.SetInt(YarnConfiguration.RmZkTimeoutMs, ZkTimeoutMs);
            conf.Set(YarnConfiguration.RmZkAcl, TestAcl);
            conf.Set(YarnConfiguration.RmZkAuth, TestAuthGood);
            zkClientTester.GetRMStateStore(conf);
        }
        /// <exception cref="System.Exception"/>
        public virtual void TestZKSessionTimeout()
        {
            TestZKRMStateStoreZKClientConnections.TestZKClient zkClientTester = new TestZKRMStateStoreZKClientConnections.TestZKClient
                                                                                    (this);
            string            path = "/test";
            YarnConfiguration conf = new YarnConfiguration();

            conf.SetInt(YarnConfiguration.RmZkTimeoutMs, ZkTimeoutMs);
            ZKRMStateStore store = (ZKRMStateStore)zkClientTester.GetRMStateStore(conf);

            RMStateStoreTestBase.TestDispatcher dispatcher = new RMStateStoreTestBase.TestDispatcher
                                                                 ();
            store.SetRMDispatcher(dispatcher);
            // a hack to trigger expired event
            zkClientTester.forExpire = true;
            // trigger watch
            store.CreateWithRetries(path, null, ZooDefs.Ids.OpenAclUnsafe, CreateMode.Persistent
                                    );
            store.GetDataWithRetries(path, true);
            store.SetDataWithRetries(path, Sharpen.Runtime.GetBytesForString("bytes"), 0);
            zkClientTester.syncBarrier.Await();
            // after this point, expired event has already been processed.
            try
            {
                byte[] ret = store.GetDataWithRetries(path, false);
                NUnit.Framework.Assert.AreEqual("bytes", Sharpen.Runtime.GetStringForBytes(ret));
            }
            catch (Exception e)
            {
                string error = "New session creation failed";
                Log.Error(error, e);
                NUnit.Framework.Assert.Fail(error);
            }
            // send Disconnected event from old client session to ZKRMStateStore
            // check the current client session is not affected.
            NUnit.Framework.Assert.IsTrue(zkClientTester.oldWatcher != null);
            WatchedEvent disconnectedEvent = new WatchedEvent(Watcher.Event.EventType.None, Watcher.Event.KeeperState
                                                              .Disconnected, null);

            zkClientTester.oldWatcher.Process(disconnectedEvent);
            NUnit.Framework.Assert.IsTrue(store.zkClient != null);
            zkClientTester.watcher.Process(disconnectedEvent);
            NUnit.Framework.Assert.IsTrue(store.zkClient == null);
            WatchedEvent connectedEvent = new WatchedEvent(Watcher.Event.EventType.None, Watcher.Event.KeeperState
                                                           .SyncConnected, null);

            zkClientTester.watcher.Process(connectedEvent);
            NUnit.Framework.Assert.IsTrue(store.zkClient != null);
            NUnit.Framework.Assert.IsTrue(store.zkClient == store.activeZkClient);
        }
        public virtual void TestZKRetryInterval()
        {
            TestZKRMStateStoreZKClientConnections.TestZKClient zkClientTester = new TestZKRMStateStoreZKClientConnections.TestZKClient
                                                                                    (this);
            YarnConfiguration conf  = new YarnConfiguration();
            ZKRMStateStore    store = (ZKRMStateStore)zkClientTester.GetRMStateStore(conf);

            NUnit.Framework.Assert.AreEqual(YarnConfiguration.DefaultRmZkRetryIntervalMs, store
                                            .zkRetryInterval);
            store.Stop();
            conf.SetBoolean(YarnConfiguration.RmHaEnabled, true);
            store = (ZKRMStateStore)zkClientTester.GetRMStateStore(conf);
            NUnit.Framework.Assert.AreEqual(YarnConfiguration.DefaultRmZkTimeoutMs / YarnConfiguration
                                            .DefaultZkRmNumRetries, store.zkRetryInterval);
            store.Stop();
        }
        public virtual void TestSetZKAcl()
        {
            TestZKRMStateStoreZKClientConnections.TestZKClient zkClientTester = new TestZKRMStateStoreZKClientConnections.TestZKClient
                                                                                    (this);
            YarnConfiguration conf = new YarnConfiguration();

            conf.Set(YarnConfiguration.RmZkAcl, "world:anyone:rwca");
            try
            {
                zkClientTester.store.zkClient.Delete(zkClientTester.store.znodeWorkingPath, -1);
                NUnit.Framework.Assert.Fail("Shouldn't be able to delete path");
            }
            catch (Exception)
            {
            }
        }
        /// <exception cref="System.Exception"/>
        public virtual void TestZKClientDisconnectAndReconnect()
        {
            TestZKRMStateStoreZKClientConnections.TestZKClient zkClientTester = new TestZKRMStateStoreZKClientConnections.TestZKClient
                                                                                    (this);
            string            path = "/test";
            YarnConfiguration conf = new YarnConfiguration();

            conf.SetInt(YarnConfiguration.RmZkTimeoutMs, ZkTimeoutMs);
            ZKRMStateStore store = (ZKRMStateStore)zkClientTester.GetRMStateStore(conf);

            RMStateStoreTestBase.TestDispatcher dispatcher = new RMStateStoreTestBase.TestDispatcher
                                                                 ();
            store.SetRMDispatcher(dispatcher);
            // trigger watch
            store.CreateWithRetries(path, null, ZooDefs.Ids.OpenAclUnsafe, CreateMode.Persistent
                                    );
            store.GetDataWithRetries(path, true);
            store.SetDataWithRetries(path, Sharpen.Runtime.GetBytesForString("newBytes"), 0);
            StopServer();
            AtomicBoolean isSucceeded = new AtomicBoolean(false);

            zkClientTester.watcher.WaitForDisconnected(ZkOpWaitTime);
            Sharpen.Thread thread = new _Thread_190(store, path, isSucceeded);
            thread.Start();
            // ZKRMStateStore Session restored
            StartServer();
            zkClientTester.watcher.WaitForConnected(ZkOpWaitTime);
            byte[] ret = null;
            try
            {
                ret = store.GetDataWithRetries(path, true);
            }
            catch (Exception e)
            {
                string error = "ZKRMStateStore Session restore failed";
                Log.Error(error, e);
                NUnit.Framework.Assert.Fail(error);
            }
            NUnit.Framework.Assert.AreEqual("newBytes", Sharpen.Runtime.GetStringForBytes(ret
                                                                                          ));
            thread.Join();
            NUnit.Framework.Assert.IsTrue(isSucceeded.Get());
        }
        /* expected behavior */
        public virtual void TestInvalidZKAclConfiguration()
        {
            TestZKRMStateStoreZKClientConnections.TestZKClient zkClientTester = new TestZKRMStateStoreZKClientConnections.TestZKClient
                                                                                    (this);
            YarnConfiguration conf = new YarnConfiguration();

            conf.Set(YarnConfiguration.RmZkAcl, "randomstring&*");
            try
            {
                zkClientTester.GetRMStateStore(conf);
                NUnit.Framework.Assert.Fail("ZKRMStateStore created with bad ACL");
            }
            catch (ZKUtil.BadAclFormatException)
            {
            }
            catch (Exception e)
            {
                // expected behavior
                string error = "Incorrect exception on BadAclFormat";
                Log.Error(error, e);
                NUnit.Framework.Assert.Fail(error);
            }
        }
        /// <exception cref="System.Exception"/>
        public virtual void TestZKClientRetry()
        {
            TestZKRMStateStoreZKClientConnections.TestZKClient zkClientTester = new TestZKRMStateStoreZKClientConnections.TestZKClient
                                                                                    (this);
            string            path = "/test";
            YarnConfiguration conf = new YarnConfiguration();

            conf.SetInt(YarnConfiguration.RmZkTimeoutMs, ZkTimeoutMs);
            conf.SetLong(YarnConfiguration.RmZkRetryIntervalMs, 100);
            ZKRMStateStore store = (ZKRMStateStore)zkClientTester.GetRMStateStore(conf);

            RMStateStoreTestBase.TestDispatcher dispatcher = new RMStateStoreTestBase.TestDispatcher
                                                                 ();
            store.SetRMDispatcher(dispatcher);
            AtomicBoolean assertionFailedInThread = new AtomicBoolean(false);

            StopServer();
            Sharpen.Thread clientThread = new _Thread_151(store, path, assertionFailedInThread
                                                          );
            Sharpen.Thread.Sleep(2000);
            StartServer();
            clientThread.Join();
            NUnit.Framework.Assert.IsFalse(assertionFailedInThread.Get());
        }