public void Should_expose_connection_failures()
 {
     using (var client = new CompositeClient(port: 9999, hostname: "monkey-trumpets"))
     {
         Assert.Throws <SocketException>(() => client.Query("BANG!"));
     }
 }
        public void Publishing_state_is_written_to_riemann_index()
        {
            var          serviceName = "TcpClientTest#" + Guid.NewGuid();
            var          description = Guid.NewGuid().ToString();
            var          metric      = DateTime.Now.Ticks;
            const float  timeToLive  = 110.5f;
            const string host        = "tests";
            var          tags        = new[] { "tag1", "tag2" };

            IEnumerable <EventRecord> results;

            using (var client = new CompositeClient(maxDatagramSize: 0))
            {
                client.Send(tags: tags,
                            host: host,
                            service: serviceName,
                            state: "ok",
                            description: description,
                            metric: metric,
                            ttl: timeToLive);

                results = client.Query(string.Format("service=\"{0}\"", serviceName)).ToList();
            }
            Assert.That(results.Any());
            Assert.That(results.Single().Host, Is.EqualTo(host));
            Assert.That(results.Single().Description, Is.EqualTo(description));
            Assert.That(results.Single().Service, Is.EqualTo(serviceName));
            Assert.That(results.Single().State, Is.EqualTo("ok"));
            Assert.That(results.Single().Tags, Is.EquivalentTo(tags));
            Assert.That(results.Single().metric_f, Is.EqualTo(metric));
            Assert.That(results.Single().TTL, Is.EqualTo(timeToLive));
        }
        public void Should_convert_time_to_unix_epoch_seconds()
        {
            var time = DateTime.UtcNow;
            int expectedTimestamp = (int)(time - new DateTime(1970, 1, 1)).TotalSeconds;

            List <EventRecord> results;

            using (var client = new CompositeClient(maxDatagramSize: 0))
            {
                const string serviceName = "Should_convert_time_to_unix_epoch_seconds";
                client.SendAsync(host: "tests",
                                 service: serviceName,
                                 state: "ok",
                                 timestamp: time).Wait();

                results = client.Query(string.Format("service=\"{0}\"", serviceName)).ToList();
            }
            Assert.That(results.Any());
            Assert.That(results.Single().Time, Is.EqualTo(expectedTimestamp));
        }
Пример #4
0
        static void Main()
        {
            var rand = new Random();

            using (var client = new CompositeClient())
            {
                client.Send(service: "Demo Client", state: "warn", description: "Simple event description");

                client.Send(new EventRecord {
                    Host = "c#", Service = "Demo Client (1)", State = "ok", metric_f = 34.5f
                },
                            new EventRecord {
                    Service = "Demo Client (2)", metric_f = rand.Next(100)
                });

                var results = client.Query("service =~ \"Demo%\"");

                foreach (var eventRecord in results)
                {
                    Console.WriteLine("Host:{0}|Service:{1}|Metric:{2}|State:{3}",
                                      eventRecord.Host, eventRecord.Service, eventRecord.metric_f, eventRecord.State);
                }
            }
        }