Пример #1
0
        public void testRunApp()
        {
            var lo = new LocalOperations("m1", lf, appInitializedDetectorFactory, null);

            lo.SelectPlan("p1");

            AppState st;

            st = lo.GetAppState(ads["a"].AppIdTuple);
            Assert.AreEqual(st.Started, false, "not yet launched");
            Assert.AreEqual(st.Running, false, "not yet running");
            Assert.AreEqual(st.Killed, false, "not yet killed");
            Assert.AreEqual(st.Initialized, false, "not yet initialized");

            lo.LaunchApp(ads["a"].AppIdTuple);
            lo.tick(10.0);

            st = lo.GetAppState(ads["a"].AppIdTuple);
            Assert.AreEqual(st.Started, true, "launched");
            Assert.AreEqual(st.Running, true, "running");
            Assert.AreEqual(st.Killed, false, "not yet killed");
            Assert.AreEqual(st.Initialized, true, "initialized");

            lo.KillApp(ads["a"].AppIdTuple);
            lo.tick(10.0);

            st = lo.GetAppState(ads["a"].AppIdTuple);
            Assert.AreEqual(st.Started, true, "started after kill");
            Assert.AreEqual(st.Killed, true, "killed after kill");
            Assert.AreEqual(st.Running, false, "not running after kill");
            Assert.AreEqual(st.Initialized, false, "not initialized after kill");
        }
Пример #2
0
        /// <summary>
        /// Returns a string with comma separated appIdTuples of apps whose state matches given predicate;
        /// the apps go in alphabetical order ("m10.b", "m2.a"...)
        /// </summary>
        public string getAppsWithMatchingState(LocalOperations lo, Predicate <AppState> predicate)
        {
            var appIds =
                from p in lo.GetPlanRepo()
                from a in p.getAppDefs()
                where predicate(lo.GetAppState(a.AppIdTuple))
                orderby a.AppIdTuple.ToString()
                select a.AppIdTuple.ToString();

            return(string.Join(",", appIds.ToArray()));
        }
Пример #3
0
        public void Read1()
        {
            LauncherFactory launcherFactory = new LauncherFactory();
            AppInitializedDetectorFactory appInitializedDetectorFactory = new AppInitializedDetectorFactory();
            var localOps = new LocalOperations("m1", launcherFactory, appInitializedDetectorFactory, null);

            localOps.SetPlanRepo(TestPlanRepo.plans.Values);

            var server = new CLIServer("127.0.0.1", 6001, localOps);

            server.Start();


            var client = new TcpClient("localhost", 6001);

            SendReq(client, "001", "StartPlan p1");
            server.Tick();
            var resp001 = ReadResp(client, 1000);


            SendReq(client, "002", "GetAppState m1.a");
            server.Tick();
            var resp002 = ReadResp(client, 1000);

            SendReq(client, "003", "GetPlanState p1");
            server.Tick();
            var resp003 = ReadResp(client, 1000);

            SendReq(client, "004", "GetAllPlansState");
            server.Tick();
            var resp004 = ReadResp(client, 1000);

            SendReq(client, "005", "GetAllAppsState");
            server.Tick();
            var resp005 = ReadResp(client, 1000);


            client.Close();


            //Assert.IsNotNull(cfg.Plans[0].getAppDefs());
            //Assert.AreEqual( "m1.a", cfg.Plans[0].getAppDefs().First().AppIdTuple.ToString() );

            server.Stop();
        }
Пример #4
0
        public void testStopPlan()
        {
            var lo = new LocalOperations("m1", lf, appInitializedDetectorFactory, null);

            var planName = "p1";

            lo.SelectPlan(planName);
            lo.StartPlan(planName);
            for (int i = 0; i < 10; i++)
            {
                lo.tick(i);                        // give enought ticks to start all
            }
            Assert.AreEqual("m1.a,m1.b,m1.c,m1.d", getAppsWithMatchingState(lo, st => st.Running), "all aps running after Start()");


            lo.KillPlan(planName);
            lo.tick(20.0);
            Assert.AreEqual("", getAppsWithMatchingState(lo, st => st.Running), "no app running after Stop()");
        }
Пример #5
0
        public void testLaunchSequence()
        {
            var lo = new LocalOperations("m1", lf, appInitializedDetectorFactory, null);

            lo.SelectPlan("p1");

            // start the plan
            lo.StartPlan("p1");

            var t = 0.0;

            Assert.AreEqual(0, lf.appsLaunched.Count, "nothing started without tick");

            lo.tick(t);

            Assert.AreEqual("m1.b", getOrder(lf.appsLaunched), "'b' started as first app");

            t += 1.0;
            lo.tick(t);

            Assert.AreEqual("m1.b", getOrder(lf.appsLaunched), "'a' waiting, not yet starting (separ. interval of b is 2.0)");

            t += 1.0;
            lo.tick(t);

            Assert.AreEqual("m1.b,m1.a", getOrder(lf.appsLaunched), "'a' started");

            t += 1.0;
            lo.tick(t);

            Assert.AreEqual("m1.b,m1.a,m1.c", getOrder(lf.appsLaunched), "'c' started");

            t += 1.0;
            lo.tick(t);

            Assert.AreEqual("m1.b,m1.a,m1.c,m1.d", getOrder(lf.appsLaunched), "'d' started as last app");

            Assert.AreEqual("m1.a,m1.b,m1.c,m1.d", getAppsWithMatchingState(lo, st => st.Running), "all aps running");
        }