Esempio n. 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"), "metrics-session");
            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());
            }

            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();

            Trace.Listeners.Remove(listener);

            var logText = log.ToString();

            Assert.IsTrue(logText.Contains("Latency message complete"), "did not find evidence of metrics being posted");
        }
Esempio n. 2
0
        static void Main(string[] args)
        {
            try
            {
                var curProcess = Process.GetCurrentProcess();
                var secondsOnStart = curProcess.TotalProcessorTime.TotalSeconds;
                var totalWatch = Stopwatch.StartNew();

                for (int i = 0; i < 20; i++)
                {
                    var client = new Client(Const.RPC_URI, Const.STREAMING_URI, "");
                    var recorder = new Recorder(client);
                    recorder.Start();

                    var loginWatch = Stopwatch.StartNew();
                    client.LogIn(Const.USERNAME, Const.PASSWORD);
                    loginWatch.Stop();

                    var accountInfoWatch = Stopwatch.StartNew();
                    var accountInfo = client.AccountInformation.GetClientAndTradingAccount();
                    accountInfoWatch.Stop();

                    var listSpreadMarketsWatch = Stopwatch.StartNew();
                    var resp = client.SpreadMarkets.ListSpreadMarkets("", "",
                        accountInfo.ClientAccountId, 100, false);
                    listSpreadMarketsWatch.Stop();

                    var logoutWatch = Stopwatch.StartNew();
                    client.LogOut();
                    logoutWatch.Stop();

                    var purgeHandle = client.ShutDown();
                    if (!purgeHandle.WaitOne(60000))
                        throw new ApplicationException();

                    var requests = recorder.GetRequests();
                    if (requests.Count != 4)
                        throw new ApplicationException();

                    AddResult(loginWatch, requests[0], "Login");
                    AddResult(accountInfoWatch, requests[1], "GetClientAndTradingAccount");
                    AddResult(listSpreadMarketsWatch, requests[2], "ListSpreadMarkets");
                    AddResult(logoutWatch, requests[3], "Logout");

                    recorder.Stop();
                    recorder.Dispose();
                    client.Dispose();
                }

                totalWatch.Stop();
                var secondsOnEnd = curProcess.TotalProcessorTime.TotalSeconds;
                Console.WriteLine("CPU time used, seconds: {0} total time: {1}", secondsOnEnd - secondsOnStart, totalWatch.Elapsed.TotalSeconds);
            }
            catch (Exception exc)
            {
                Console.WriteLine(exc);
            }

            Debugger.Break();
        }