Beispiel #1
0
        /// <summary>
        /// monitored self hosted service and client handler added programmatically
        /// </summary>
        /// <param name="recordrequest"></param>
        /// <param name="recordresponse"></param>
        void TC00139_doWork(bool recordrequest, bool recordresponse)
        {
            Thread.Sleep(10000);
            CommonUtils.RemoveService(url_mod);
            CommonUtils.SetPolicy(url_mod, recordrequest, recordresponse);

            try
            {
                MessageProcessor mp = MessageProcessor.Instance;
                MessageProcessor.PurgePolicyCache();
                MessageProcessor.PurgeOutboundQueue();
                Assert.IsTrue(MessageProcessor.GetPolicyCacheSize() == 0);
                Assert.IsTrue(MessageProcessor.GetQueueSize() == 0);
                ServiceHost host = new ServiceHost(typeof(FGSMSNetServiceImpl));
                host.Description.Behaviors.Remove(typeof(org.miloss.fgsms.agent.wcf.AgentWCFServiceBehavior));
                host.Description.Behaviors.Add(new org.miloss.fgsms.agent.wcf.AgentWCFServiceBehavior());
                host.Open();
                IFGSMSNetService         svc = getproxyWithMonitor(url_mod);
                SomeComplexRequestObject req = new SomeComplexRequestObject();
                req.stdout = "hi";

                svc.getData(req);

                Thread.Sleep(5000);
                DateTime timeout = DateTime.Now.AddMinutes(2);
                Console.Out.WriteLine("message sent queue size" + MessageProcessor.GetQueueSize());
                while (MessageProcessor.GetQueueSize() > 0 && DateTime.Now < timeout)
                {
                    Thread.Sleep(1000);
                }
                ((IClientChannel)svc).Close();
                ((IClientChannel)svc).Dispose();
                host.Close();
            }
            catch (Exception ex)
            {
                string _err = "";
                while (ex != null)
                {
                    _err += ex.Message + " " + ex.StackTrace;
                    ex    = ex.InnerException;
                }
                CommonUtils.RemoveService(url_mod);
                Assert.Fail(_err);
            }

            Thread.Sleep(10000);
            string err = "";

            if (MessageProcessor.GetPolicyCacheSize() == 0)
            {
                err += "policy cache is empty, it should have at least one item in it";
            }
            if (!String.IsNullOrEmpty(MessageProcessor.LastErrorMessage))
            {
                err += "agent error " + MessageProcessor.LastErrorMessage;
            }

            TransactionalWebServicePolicy tp = MessageProcessor.GetPolicyIfAvailable(url_mod, true);

            if (tp == null)
            {
                err += "the policy for the service was not cached, which means something went wrong";
            }
            err += CommonUtils.VerifyLastMessagePayloads(url_mod, recordrequest, recordresponse, 2);
            err += CommonUtils.VerifyLastMessagePayloadsTwoAgentsOneTransaction(url_mod);
            CommonUtils.RemoveService(url_mod);
            if (!String.IsNullOrEmpty(err))
            {
                Assert.Fail(err);
            }
        }