/// <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);
        }
        /// <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());
        }