Esempio n. 1
0
        public void SendLogEventsToAirlock_GotItAtElastic()
        {
            const int eventCount = 10;
            var       log        = IntegrationTestsEnvironment.Log;
            var       logEvents  = GenerateLogEvens(eventCount);

            PushToAirlock(logEvents);

            var connectionPool = new StickyConnectionPool(new[] { new Uri("http://localhost:9200") });
            var elasticConfig  = new ConnectionConfiguration(connectionPool, cfg =>
            {
                cfg.EnableDebugMode();
                return(null);
            });
            var elasticClient = new ElasticLowLevelClient(elasticConfig);
            var indexName     = $"{IntegrationTestsEnvironment.Project}-{IntegrationTestsEnvironment.Environment}-{logEvents.First().Timestamp:yyyy.MM.dd}";

            var testId = logEvents.First().Properties["testId"];
            var expectedLogMessages = new HashSet <string>(logEvents.Select(x => x.Message));

            WaitHelper.WaitSafe(
                () =>
            {
                var elasticsearchResponse = elasticClient.Search <string>(
                    indexName,
                    "LogEvent",
                    new
                {
                    from  = 0,
                    size  = eventCount,
                    query = new
                    {
                        match = new
                        {
                            testId,
                        }
                    }
                });
                log.Debug(elasticsearchResponse.DebugInformation);
                if (!elasticsearchResponse.Success)
                {
                    log.Error(elasticsearchResponse.OriginalException);
                    return(WaitAction.ContinueWaiting);
                }

                var hits = (JArray)((dynamic)JObject.Parse(elasticsearchResponse.Body)).hits.hits;
                if (expectedLogMessages.Count != hits.Count)
                {
                    log.Error($"Invalid event count: {hits.Count}, expected: {expectedLogMessages.Count}");
                    return(WaitAction.ContinueWaiting);
                }

                foreach (dynamic hit in hits)
                {
                    string message = hit._source.Message;
                    Assert.True(expectedLogMessages.Contains(message));
                }
                return(WaitAction.StopWaiting);
            });
        }
Esempio n. 2
0
        public void SendTraceEventsToAirlock_GotItAtCassandra()
        {
            const int eventCount = 10;
            var       spans      = GenerateSpans(eventCount);

            PushToAirlock(spans);

            var contrailsClient = new ContrailsClient(new ContrailsClientSettings
            {
                CassandraNodes = new[] { "localhost:9042" },
                Keyspace       = "airlock",
                CassandraRetryExecutionStrategySettings = new CassandraRetryExecutionStrategySettings(),
            }, IntegrationTestsEnvironment.Log);

            WaitHelper.Wait(
                () =>
            {
                foreach (var span in spans)
                {
                    var tracesById = contrailsClient.GetTracesById(span.TraceId, null, null, null, null, true).GetAwaiter().GetResult().ToArray();
                    if (tracesById.Length == 0)
                    {
                        return(false);
                    }
                    var spanResult = tracesById[0];

                    IntegrationTestsEnvironment.Log.Debug("got span " + spanResult.ToJson());
                    Assert.AreEqual(1, tracesById.Length);
                    Assert.AreEqual(span.SpanId, spanResult.SpanId);
                }
                return(true);
            });
        }