示例#1
0
        private void VerifyCommandFailed(TestEvents ev, TimeSpan timeout, params string[] commands)
        {
            List <string> expected = new List <string>();

            expected.Add("Request[Type:Create, Path:/$metadata/scheduler/commands]");
            expected.Add("Request[Type:Create, Path:/$metadata/scheduler/failures]");
            expected.Add("Request[Type:Create, Path:/$metadata/scheduler/inflight]");
            expected.Add("Request[Type:GetChildren, Path:/$metadata/scheduler/commands]");
            foreach (string command in commands)
            {
                expected.Add("<contains>Request[Type:Create, Path:/$metadata/scheduler/commands/" + command + "]");
            }

            expected.Add("WatchedEvent[Class:WatchedEvent,Path=/$metadata/scheduler/commands,EventType=NodeChildrenChanged,KeeperState=SyncConnected]");
            expected.Add("Request[Type:GetChildren, Path:/$metadata/scheduler/commands]");
            foreach (string command in commands)
            {
                expected.Add("Request[Type:GetData, Path:/$metadata/scheduler/commands/" + command + "]");
                expected.Add("Request[Type:Multi, Requests:Request[Type:Create, Path:/$metadata/scheduler/failures/" + command + "];Request[Type:Move, Path:/$metadata/scheduler/commands/" + command + ", PathDst:/$metadata/scheduler/failures/" + command + "];Request[Type:Create, Path:/$metadata/scheduler/failures/" + command + "/ResultData]]");
            }

            string[] expectedArray = expected.ToArray();

            ev.AssertOccursInOrder(
                "Timeout (10s) waiting for scheduler to close command as failed",
                false,
                TimeSpan.FromSeconds(10),
                expectedArray);
        }
示例#2
0
 private void OutputDataReceived(object sender, DataReceivedEventArgs e)
 {
     if (OnTestProgress != null && e != null && String.IsNullOrEmpty(e.Data) == false)
     {
         TestEvents.ProcessProgress(e.Data, OnTestProgress);
     }
 }
示例#3
0
        private void OnProgress(string cmdId, string args)
        {
            if (String.IsNullOrEmpty(args))
            {
                return;
            }

            String[] vals = Regex.Split(args, ";");

            if (vals == null || vals.Length != 3)
            {
                return;
            }

            try
            {
                CollectPageInformation collectType = (CollectPageInformation)Enum.ToObject(typeof(CollectPageInformation), int.Parse(vals[0]));

                int prg = int.Parse(vals[1]);
                int tot = int.Parse(vals[2]);

                if ((collectType & CollectPageInformation.Screenshots_Small) == CollectPageInformation.Screenshots_Small ||
                    (collectType & CollectPageInformation.Screenshots_Full) == CollectPageInformation.Screenshots_Full)
                {
                    TestEvents.FireProgressEvent(TestEventType.CapturingSegment, prg, tot, null);
                }
                else
                {
                    TestEvents.FireProgressEvent(TestEventType.RenderingSegment, prg, tot, null);
                }
            }
            catch
            {
            }
        }
示例#4
0
 private void VerifyCreated(TestEvents ev, TimeSpan timeout, string path)
 {
     ev.AssertOccursInOrder(
         "Timeout (10s) waiting for path to be created",
         false,
         TimeSpan.FromSeconds(10),
         "<contains>Request[Type:Create, Path:" + path + "]");
 }
示例#5
0
 private void VerifySetup(TestEvents ev, TimeSpan timeout)
 {
     ev.AssertOccursInOrder(
         "Timeout (10s) waiting for scheduler to learn about baseline commands",
         false,
         TimeSpan.FromSeconds(10),
         "Request[Type:Create, Path:/$metadata/scheduler/commands]",
         "Request[Type:Create, Path:/$metadata/scheduler/failures]",
         "Request[Type:GetChildren, Path:/$metadata/scheduler/commands]");
 }
示例#6
0
        public ActionResult About()
        {
            TestEvents events = new TestEvents()
            {
                Message = "this is my first events"
            };

            EventBus.Publish(events);

            return(Content(""));
        }
示例#7
0
 private void VerifyCommandTaken(TestEvents ev, TimeSpan timeout, string command)
 {
     ev.AssertOccursInOrder(
         "Timeout (10s) waiting for scheduler to collect data for the new command",
         false,
         timeout,
         "Request[Type:Create, Path:/$metadata/scheduler/commands]",
         "Request[Type:Create, Path:/$metadata/scheduler/failures]",
         "Request[Type:Create, Path:/$metadata/scheduler/inflight]",
         "Request[Type:GetChildren, Path:/$metadata/scheduler/commands]",
         "<contains>Request[Type:Create, Path:/$metadata/scheduler/commands/" + command + "]",
         "WatchedEvent[Class:WatchedEvent,Path=/$metadata/scheduler/commands,EventType=NodeChildrenChanged,KeeperState=SyncConnected]",
         "Request[Type:GetChildren, Path:/$metadata/scheduler/commands]",
         "Request[Type:GetData, Path:/$metadata/scheduler/commands/" + command + "]",
         "<contains>Request[Type:Move, Path:/$metadata/scheduler/commands/" + command + ", PathDst:/$metadata/scheduler/");
 }
示例#8
0
        public override void SendData(byte[] buffer, int offset, int length)
        {
            if (isRequest && this.PipesChain.ChainState.ContainsKey(STATE_KEY) == false && this.PipesChain.ChainState.ContainsKey("REQUEST_URI"))
            {
                HttpTransaction httpTranc = new HttpTransaction();

                httpTranc.URL  = (String)this.PipesChain.ChainState["REQUEST_URI"];
                httpTranc.Mode = HttpMode.SendingRequest;

                httpTranc.ConnectionStartTime     = DateTime.Now;
                httpTranc.SendingRequestStartTime = DateTime.Now;
                httpTranc.TotalSent = length;

                TestEvents.FireProgressEvent(TestEventType.RequestingFile, httpTranc.URL);
                TestEvents.FireProgressEvent(TestEventType.SendingData, length, 0, httpTranc.URL);

                this.PipesChain.ChainState.Add(STATE_KEY, httpTranc);

                AddRequestToTracker(httpTranc);
            }
            else if (isRequest)
            {
                HttpTransaction httpTranc = (HttpTransaction)this.PipesChain.ChainState[STATE_KEY];
                httpTranc.TotalSent += length;
                TestEvents.FireProgressEvent(TestEventType.SendingData, length, 0, httpTranc.URL);
            }
            else if (isRequest == false && this.PipesChain.ChainState.ContainsKey(STATE_KEY))
            {
                HttpTransaction httpTranc = (HttpTransaction)this.PipesChain.ChainState[STATE_KEY];

                if (httpTranc.Mode == HttpMode.WaitingForResponse)
                {
                    httpTranc.Mode = HttpMode.ReceivingResponse;
                    httpTranc.ReceivingResponseStartTime = DateTime.Now;
                }
                httpTranc.TotalReceived += length;

                TestEvents.FireProgressEvent(TestEventType.ReceivingData, length, 0, httpTranc.URL);
            }

            base.SendData(buffer, offset, length);
        }
示例#9
0
        public override void Flush()
        {
            if (this.PipesChain.ChainState.ContainsKey(STATE_KEY))
            {
                HttpTransaction httpTranc = (HttpTransaction)this.PipesChain.ChainState[STATE_KEY];

                if (isRequest)
                {
                    httpTranc.Mode = HttpMode.WaitingForResponse;
                    httpTranc.SendingRequestEndTime = DateTime.Now;
                }
                else
                {
                    TestEvents.FireProgressEvent(TestEventType.ResponseEnded, httpTranc.URL);
                    httpTranc.Mode = HttpMode.Completed;
                    httpTranc.ReceivingResponseEndTime = DateTime.Now;
                    httpTranc.ConnectionEndTime        = DateTime.Now;
                }
            }

            base.Flush();
        }
示例#10
0
        static void Main(string[] args)
        {
            commandArgs = args;
            AppDomain.CurrentDomain.UnhandledException += new UnhandledExceptionEventHandler(CurrentDomain_UnhandledException);
            PageDataCollectorStartInfo pdcsi = new PageDataCollectorStartInfo(args);

            if (pdcsi.IsValid() == false)
            {
                PageDataCollectorStartInfo.PrintUsage(System.Console.Error);
                System.Environment.ExitCode = (int)(PageDataCollectorErrors.InvalidOrMissingArguments);
            }
            else
            {
                TestEvents.IsVerbose = pdcsi.IsVerbose;

                TestEvents.FireProgressEvent(TestEventType.TestStarted);

                pdcsi.IsDebug = true;

                _Collector c = new _Collector(pdcsi);

                try
                {
                    System.Environment.ExitCode = c.Run();
                }
                catch {
                    System.Environment.ExitCode = (int)PageDataCollectorErrors.Unknown;
                }
                finally
                {
                    c.Release();
                }

                TestEvents.FireProgressEvent(TestEventType.TestEnded);
            }
        }
示例#11
0
 public TestMarshaller(TestEvents ev)
 {
     this.ev = ev;
 }
示例#12
0
 public TestRingMaster(TestEvents ev, TestMarshaller marshaller)
     : base(string.Empty, 10, null)
 {
     this.ev         = ev;
     this.marshaller = marshaller;
 }
示例#13
0
        // [TestMethod]
        public void ValidateScheduler()
        {
            bool ok = false;

            TestEvents       ev         = new TestEvents();
            TestMarshaller   marshaller = new TestMarshaller(ev);
            TestRingMaster   testRM     = new TestRingMaster(ev, marshaller);
            ScheduledCommand scheduler  = null;

            try
            {
                foreach (string path in ScheduledCommand.GetPaths())
                {
                    testRM.Create(path, null, null, CreateMode.PersistentAllowPathCreation);
                }

                scheduler = new ScheduledCommand(() => { return(testRM.IsPrimary); }, testRM, marshaller);
                scheduler.InternalOnAbandon = new Action <Exception>(ex =>
                {
                    Assert.Fail("Scheduler Abandoned: " + ex);
                });

                scheduler.Start();

                this.VerifySetup(ev, TimeSpan.FromSeconds(15));

                string res = testRM.Create("/$metadata/scheduler/commands/c1", null, null, CreateMode.Persistent);

                this.VerifyCommandTaken(ev, TimeSpan.FromSeconds(10), "c1");
                this.VerifyCommandFailed(ev, TimeSpan.FromSeconds(10), "c1");

                List <Op> ops = new List <Op>();
                ops.Add(Op.Create("/$metadata/scheduler/commands/c2", null, null, CreateMode.Persistent));
                ops.Add(Op.Create("/$metadata/scheduler/commands/c4", null, null, CreateMode.Persistent));
                ops.Add(Op.Create("/$metadata/scheduler/commands/c3", null, null, CreateMode.Persistent));

                IReadOnlyList <OpResult> resL = testRM.Multi(ops.AsReadOnly(), completeSynchronously: true, scheduledName: null);

                this.VerifyCommandTaken(ev, TimeSpan.FromSeconds(10), "c2");
                this.VerifyCommandTaken(ev, TimeSpan.FromSeconds(10), "c3");
                this.VerifyCommandTaken(ev, TimeSpan.FromSeconds(10), "c4");
                this.VerifyCommandFailed(ev, TimeSpan.FromSeconds(10), "c2", "c3", "c4");

                ops.Clear();
                ops.Add(Op.Create("/test1", null, null, CreateMode.Persistent));
                resL = testRM.Multi(ops.AsReadOnly(), completeSynchronously: true, scheduledName: "c5");

                this.VerifyCommandTaken(ev, TimeSpan.FromSeconds(10), "c5");
                this.VerifyCommandSucceeded(ev, TimeSpan.FromSeconds(10), "c5");
                this.VerifyCreated(ev, TimeSpan.FromSeconds(10), "/test1");

                Assert.IsTrue(testRM.Exists("/test1", false, false) != null);
                Assert.IsTrue(testRM.Exists("/$metadata/scheduler/commands/c5", false, false) == null);

                ok = true;
            }
            finally
            {
                if (!ok)
                {
                    testRM.DumpNodes();
                }

                ThreadPool.QueueUserWorkItem(_ =>
                {
                    if (scheduler != null)
                    {
                        scheduler.Close();
                    }

                    testRM.Close();
                });
            }
        }
示例#14
0
 public Task HandleEventAsync(TestEvent e)
 {
     TestEvents.Add(e);
     return(Task.CompletedTask);
 }