示例#1
0
        public void CanSendMetrics()
        {

            // set up a listener
            var log = new StringBuilder();
            var writer = new StringWriter(log);
            var listener = new TextWriterTraceListener(writer);
            Trace.Listeners.Add(listener);

            var rpcClient = new Client(Settings.RpcUri, Settings.StreamingUri, "my-test-appkey");
            var metricsRecorder = new MetricsRecorder(rpcClient, new Uri("http://metrics.labs.cityindex.com/LogEvent.ashx"));
            metricsRecorder.Start();

            rpcClient.LogIn(Settings.RpcUserName, Settings.RpcPassword);

            var headlines = rpcClient.News.ListNewsHeadlinesWithSource("dj", "UK", 100);

            foreach (var item in headlines.Headlines)
            {
                rpcClient.News.GetNewsDetail("dj", item.StoryId.ToString());
            }

            new AutoResetEvent(false).WaitOne(10000);

            rpcClient.LogOut();

            metricsRecorder.Stop();
            rpcClient.Dispose();

            Trace.Listeners.Remove(listener);

            var logText = log.ToString();

            Assert.IsTrue(logText.Contains("Latency message complete"), "did not find evidence of metrics being posted");
        }
示例#2
0
        public void CanSendMetrics()
        {



            var rpcClient = BuildUnauthenticatedRpcClient();
            Uri metricsUrl = BuildUri("http://metrics.labs.cityindex.com/LogEvent.ashx", 1);
            var metricsRecorder = new MetricsRecorder(rpcClient, metricsUrl, "metrics-session");
            metricsRecorder.Start();

            rpcClient.LogIn(UserName, Password);

            var headlines = rpcClient.News.ListNewsHeadlinesWithSource("dj", "UK", 100);

            foreach (var item in headlines.Headlines)
            {
                rpcClient.News.GetNewsDetail("dj", item.StoryId.ToString());
            }

            Thread.Sleep(1000);

            rpcClient.LogOut();

            metricsRecorder.Stop();

            var purgeHandle = rpcClient.ShutDown();

            if (!purgeHandle.WaitOne(60000))
            {
                throw new Exception("timed out waiting for client to purge");
            }

            rpcClient.Dispose();
            var tape = this.TrafficLog.List()[0];
            //metrics-session

            var metricssent = tape.log.entries.Any(e => e.request.url.IndexOf("metrics.labs.cityindex.com", StringComparison.CurrentCultureIgnoreCase) > -1 && e.request.postData.@params[1].value.Length > 0);

            Assert.IsTrue(metricssent, "did not find evidence of metrics being posted");
        }
示例#3
0
        public void MetricsAreSentWithSelectedSessionIdentifier()
        {
            var startTime = DateTime.UtcNow;
            var metricsSession = "MetricsAreSentWithSelectedSessionIdentifier_" + Guid.NewGuid();

            // set up a listener
            var log = new StringBuilder();
            var writer = new StringWriter(log);
            var listener = new TextWriterTraceListener(writer);
            Trace.Listeners.Add(listener);

            var rpcClient = new Client(Settings.RpcUri, Settings.StreamingUri, "my-test-appkey");

            var metricsRecorder = new MetricsRecorder(rpcClient, new Uri(MetricsUrl + "LogEvent.ashx"), metricsSession, Settings.AppMetrics_AccessKey);
            metricsRecorder.Start();

            rpcClient.LogIn(Settings.RpcUserName, Settings.RpcPassword);

            rpcClient.LogOut();

            metricsRecorder.Stop();
            rpcClient.Dispose();

            Trace.Listeners.Remove(listener);

            using (var client = new WebClient())
            {
                client.Credentials = new NetworkCredential(Settings.AppMetrics_UserName, Settings.AppMetrics_Password);
                client.QueryString["AppKey"] = "my-test-appkey";
                client.QueryString["StartTime"] = startTime.ToString("u");

                var response = client.DownloadString(MetricsUrl + "GetSessions.ashx");

                Assert.IsTrue(response.Contains(metricsSession));
            }
        }