Exemple #1
0
 public void AddConsequence(Consequence consequence)
 {
     lock (this)
         consequences.Add(consequence);
 }
Exemple #2
0
        public bool Run(int numberOfRuns)
        {
            bool result = true;

            if (this.CanSkipTest)
            {
                Console.WriteLine("Test skiped");
                return(true);
            }
            Console.WriteLine("Building test - " + Name);
            Build();

            Console.WriteLine("Initializing  test - " + Name);
            foreach (PreRequisite prereq in preRequisites)
            {
                if (prereq.Call().IsFailure())
                {
                    Console.WriteLine("##PreRequisite execution failed - " + prereq.Name);
                }
            }

            Console.WriteLine("Performing test - " + Name);

            WaitHandle[] handles = new WaitHandle[consequences.Count + 1];
            int          index   = 0;

            foreach (Consequence consequence in consequences)
            {
                Consequence tmpConsequence = consequence; // if you know closures you understand this.
                ThreadPool.QueueUserWorkItem(
                    (o) =>
                {
                    tmpConsequence.Call();
                }
                    );

                handles[index++] = consequence.ManualResetEvent;
            }

            ThreadPool.QueueUserWorkItem(
                (o) => {
                action.Call();
            }
                );
            handles[index] = action.ManualResetEvent;


            bool res = WaitHandle.WaitAll(handles, this.Timeout, false);


            if (!res)
            {
                Console.WriteLine("### Action or consquences timedout.");
            }

            if (!DisplayStepResult(action))
            {
                result = false;
            }


            foreach (Consequence consequence in consequences)
            {
                if (!DisplayStepResult(consequence))
                {
                    result = false;
                }
            }

            Console.WriteLine("Finalizing test - " + Name);

            foreach (Epilogue epilogue in epilogues)
            {
                if (epilogue.Call().IsFailure())
                {
                    Console.WriteLine("##Epilogue execution failed - " + epilogue.Name);
                }
            }

            return(result);
        }
        public virtual void AddConsequences()
        {
            foreach (TestClientInfo tci in ConsumersInfo)
            {
                Consequence consequence = new Consequence("Consume", "Consumer");
                consequence.Runnable = () =>
                {

                    bool signaled = tci.notificationHandler.ManualResetEvent.WaitOne(this.Timeout, false);
                    if (!signaled)
                    {
                        consequence.Sucess = false;
                        consequence.Done = false;
                        return;
                    }

                    foreach (NetNotification notification in tci.notificationHandler.Notifications)
                    {
                        if (!notification.Destination.Equals(this.SubscriptionName))
                        {
                            consequence.ReasonForFailure = String.Format("Unexpected Destination. Expected '{0}', Received: '{1}'", this.SubscriptionName, notification.Destination);
                            return;
                        }
                        //if ( !System.Array.Equals(notification.Message.Payload, Payload ) )
                        if (!EqualArray(notification.Message.Payload,Payload) )
                        {
                            consequence.ReasonForFailure = String.Format("Message Payload was different (content). Expected size '{0}', Received size: '{1}'", this.Payload.Length, notification.Message.Payload.Length);
                            return;
                        }
                    }
                    tci.brokerClient.Close();
                    consequence.Sucess = true;
                    consequence.Done = true;
                };
                this.AddConsequence(consequence);
            }
        }
Exemple #4
0
 public void AddConsequence(Consequence consequence)
 {
     lock (this)
         consequences.Add(consequence);
 }