/// <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());
        }
        /// <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());
        }
Exemple #4
0
        public virtual int Run(string[] args)
        {
            Log.Info("Starting ZKRMStateStorePerf ver." + version);
            int    numApp = ZkPerfNumAppDefault;
            int    numAppAttemptPerApp = ZkPerfNumAppattemptPerApp;
            string hostPort            = null;
            bool   launchLocalZK       = true;

            if (args.Length == 0)
            {
                System.Console.Error.WriteLine("Missing arguments.");
                return(-1);
            }
            for (int i = 0; i < args.Length; i++)
            {
                // parse command line
                if (Sharpen.Runtime.EqualsIgnoreCase(args[i], "-appsize"))
                {
                    numApp = System.Convert.ToInt32(args[++i]);
                }
                else
                {
                    if (Sharpen.Runtime.EqualsIgnoreCase(args[i], "-appattemptsize"))
                    {
                        numAppAttemptPerApp = System.Convert.ToInt32(args[++i]);
                    }
                    else
                    {
                        if (Sharpen.Runtime.EqualsIgnoreCase(args[i], "-hostPort"))
                        {
                            hostPort      = args[++i];
                            launchLocalZK = false;
                        }
                        else
                        {
                            if (Sharpen.Runtime.EqualsIgnoreCase(args[i], "-workingZnode"))
                            {
                                workingZnode = args[++i];
                            }
                            else
                            {
                                System.Console.Error.WriteLine("Illegal argument: " + args[i]);
                                return(-1);
                            }
                        }
                    }
                }
            }
            if (launchLocalZK)
            {
                try
                {
                    SetUp();
                }
                catch (Exception e)
                {
                    System.Console.Error.WriteLine("failed to setup. : " + e.Message);
                    return(-1);
                }
            }
            InitStore(hostPort);
            long submitTime = Runtime.CurrentTimeMillis();
            long startTime  = Runtime.CurrentTimeMillis() + 1234;
            AList <ApplicationId>        applicationIds = new AList <ApplicationId>();
            AList <RMApp>                rmApps         = new AList <RMApp>();
            AList <ApplicationAttemptId> attemptIds     = new AList <ApplicationAttemptId>();
            Dictionary <ApplicationId, ICollection <ApplicationAttemptId> > appIdsToAttemptId =
                new Dictionary <ApplicationId, ICollection <ApplicationAttemptId> >();

            RMStateStoreTestBase.TestDispatcher dispatcher = new RMStateStoreTestBase.TestDispatcher
                                                                 ();
            store.SetRMDispatcher(dispatcher);
            for (int i_1 = 0; i_1 < numApp; i_1++)
            {
                ApplicationId appId = ApplicationId.NewInstance(clusterTimeStamp, i_1);
                applicationIds.AddItem(appId);
                AList <ApplicationAttemptId> attemptIdsForThisApp = new AList <ApplicationAttemptId
                                                                               >();
                for (int j = 0; j < numAppAttemptPerApp; j++)
                {
                    ApplicationAttemptId attemptId = ApplicationAttemptId.NewInstance(appId, j);
                    attemptIdsForThisApp.AddItem(attemptId);
                }
                appIdsToAttemptId[appId] = new LinkedHashSet(attemptIdsForThisApp);
                Sharpen.Collections.AddAll(attemptIds, attemptIdsForThisApp);
            }
            foreach (ApplicationId appId_1 in applicationIds)
            {
                RMApp app = null;
                try
                {
                    app = StoreApp(store, appId_1, submitTime, startTime);
                }
                catch (Exception e)
                {
                    System.Console.Error.WriteLine("failed to create Application Znode. : " + e.Message
                                                   );
                    return(-1);
                }
                WaitNotify(dispatcher);
                rmApps.AddItem(app);
            }
            foreach (ApplicationAttemptId attemptId_1 in attemptIds)
            {
                Org.Apache.Hadoop.Security.Token.Token <AMRMTokenIdentifier> tokenId = GenerateAMRMToken
                                                                                           (attemptId_1, appTokenMgr);
                SecretKey clientTokenKey = clientToAMTokenMgr.CreateMasterKey(attemptId_1);
                try
                {
                    StoreAttempt(store, attemptId_1, ContainerId.NewContainerId(attemptId_1, 0L).ToString
                                     (), tokenId, clientTokenKey, dispatcher);
                }
                catch (Exception e)
                {
                    System.Console.Error.WriteLine("failed to create AppAttempt Znode. : " + e.Message
                                                   );
                    return(-1);
                }
            }
            long storeStart = Runtime.CurrentTimeMillis();

            try
            {
                store.LoadState();
            }
            catch (Exception e)
            {
                System.Console.Error.WriteLine("failed to locaState from ZKRMStateStore. : " + e.
                                               Message);
                return(-1);
            }
            long   storeEnd  = Runtime.CurrentTimeMillis();
            long   loadTime  = storeEnd - storeStart;
            string resultMsg = "ZKRMStateStore takes " + loadTime + " msec to loadState.";

            Log.Info(resultMsg);
            System.Console.Out.WriteLine(resultMsg);
            // cleanup
            try
            {
                foreach (RMApp app in rmApps)
                {
                    ApplicationStateData appState = ApplicationStateData.NewInstance(app.GetSubmitTime
                                                                                         (), app.GetStartTime(), app.GetApplicationSubmissionContext(), app.GetUser());
                    ApplicationId appId = app.GetApplicationId();
                    IDictionary   m     = Org.Mockito.Mockito.Mock <IDictionary>();
                    Org.Mockito.Mockito.When(m.Keys).ThenReturn(appIdsToAttemptId[appId_1]);
                    appState.attempts = m;
                    store.RemoveApplicationStateInternal(appState);
                }
            }
            catch (Exception e)
            {
                System.Console.Error.WriteLine("failed to cleanup. : " + e.Message);
                return(-1);
            }
            return(0);
        }