Esempio n. 1
0
        public void SendMessage()
        {
            const String key      = "test";
            const Int32  value    = 2;
            const String expected = "result";

            var    @event = new ManualResetEvent(false);
            String result = null;

            var formatter = new Mock <IFormatter>();

            formatter.Setup(_ => _.Format(key, value)).Returns(expected);
            TcpMetricsClient.StartAsync(OutbountChannel.From(IPAddress.Loopback,
                                                             MetricsOptions.GraphiteDefaultServerPort)
                                        .BuildAutoRecoverable(),
                                        formatter.Object)
            .ContinueWith(_ =>
            {
                _.Result.OnMessageSent += (sender, args) =>
                {
                    result = args.Message;
                    @event.Set();
                };
                _.Result.Send(key, value);
            });

            if ([email protected](TimeSpan.FromSeconds(10d)))
            {
                throw new Exception("timed out");
            }

            Assert.Equal(expected, result);
        }
Esempio n. 2
0
        public static void StartAutoRecoverable(MetricsOptions options, TimeSpan recoverySlice)
        {
            if (options == null)
            {
                throw new ArgumentNullException(nameof(options));
            }

            lock (Sync)
            {
                if (!(MetricsClient is NullMetricsClient))
                {
                    return;
                }

                StopInternal();
                TcpMetricsClient.StartAsync(OutbountChannel.From(options.HostName, options.Port).BuildAutoRecoverable(recoverySlice))
                .ContinueWith(_ => MetricsClient = _.Result)
                .Wait();
            }
        }