public void Publishing_state_supports_asynch_mode() { var host = Guid.NewGuid().ToString(); const string serviceNameRoot = "UdpClientAsync#"; Guid.NewGuid().ToString(); IEnumerable<EventRecord> results; var states = from idx in Enumerable.Range(1, 100) let state = new EventRecord(host: host, service: serviceNameRoot + idx, state: "ok", metric: idx, timeToLiveInSeconds: 10) group state by idx%10 into batches select batches; var udpClient = new CompositeClient(); var tasks = states.Select(s => udpClient.SendAsync(s.ToArray())).ToArray(); Task.WaitAll(tasks); Thread.Sleep(2000); using (var tcpClient = new CompositeClient()) { var query = string.Format("service=~ \"{0}%\"", serviceNameRoot); results = tcpClient.QueryAsync(query).Result.ToList(); } Assert.That(results.Count(), Is.EqualTo(100)); }
public void Publishing_state_is_written_to_riemann_index() { //TODO - tidy this up! var serviceName = "UdpClientTest#" + Guid.NewGuid(); var description = Guid.NewGuid().ToString(); var metric = DateTime.Now.Ticks; const float timeToLive = 110.5f; const string host = "udp_tests"; var tags = new[] {"tag1", "tag2"}; IEnumerable<EventRecord> results; using (var client = new CompositeClient()) { client.Send(timestamp: DateTime.UtcNow, host: host, service: serviceName, state: "ok", ttl: timeToLive, tags: tags, metric: metric, description: description); 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)); }
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); } } }
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)); }
public void Should_expose_connection_failures() { using (var client = new CompositeClient(port: 9999, hostname: "monkey-trumpets")) { Assert.Throws<SocketException>(() => client.Query("BANG!")); } }