public void ExporterIsSlowerThanDelay()
        {
            var exportStartTimes = new List <long>();
            var exportEndTimes   = new List <long>();
            var spanExporter     = new TestExporter(_ =>
            {
                exportStartTimes.Add(Stopwatch.GetTimestamp());
                Thread.Sleep(50);
                exportEndTimes.Add(Stopwatch.GetTimestamp());
            });

            using var spanProcessor = new BatchingSpanProcessor(spanExporter, 128, TimeSpan.FromMilliseconds(30), 2);
            var spans = new List <SpanSdk>();

            for (int i = 0; i < 20; i++)
            {
                spans.Add(this.CreateSampledEndedSpan(i.ToString(), spanProcessor));
            }

            var exported = this.WaitForSpans(spanExporter, 20, TimeSpan.FromSeconds(2));

            Assert.Equal(spans.Count, exported.Length);
            Assert.InRange(exportStartTimes.Count, 10, 20);

            for (int i = 1; i < exportStartTimes.Count - 1; i++)
            {
                Assert.InRange(exportStartTimes[i], exportEndTimes[i - 1] + 1, exportStartTimes[i + 1] - 1);
            }
        }
        public void ProcessorDoesNotBlockOnExporter()
        {
            var resetEvent   = new ManualResetEvent(false);
            var spanExporter = new TestExporter(_ => resetEvent.WaitOne(TimeSpan.FromSeconds(10)));

            using var factory = TracerFactory.Create(b => b
                                                     .AddProcessorPipeline(p => p
                                                                           .SetExporter(spanExporter)
                                                                           .SetExportingProcessor(e => new BatchingSpanProcessor(e, 128, DefaultDelay, 128))));
            var tracer = factory.GetTracer(null);

            var context = new SpanContext(ActivityTraceId.CreateRandom(), ActivitySpanId.CreateRandom(), ActivityTraceFlags.Recorded);
            var span    = (SpanSdk)tracer.StartSpan("foo", context);

            // does not block
            var sw = Stopwatch.StartNew();

            span.End();
            sw.Stop();

            Assert.InRange(sw.Elapsed, TimeSpan.Zero, TimeSpan.FromMilliseconds(100));

            resetEvent.Set();

            var exported = this.WaitForSpans(spanExporter, 1, DefaultTimeout);

            Assert.Single(exported);
        }
        public void ProcessorDoesNotBlockOnExporter()
        {
            var spanExporter = new TestExporter(_ => Thread.Sleep(500));

            using (var spanProcessor = new BatchingSpanProcessor(spanExporter, 128, DefaultDelay, 128))
            {
                var tracer = TracerFactory.Create(b => b
                                                  .SetProcessor(e => spanProcessor))
                             .GetTracer(null);

                var context = new SpanContext(ActivityTraceId.CreateRandom(), ActivitySpanId.CreateRandom(), ActivityTraceFlags.Recorded);
                var span    = (Span)tracer.StartSpan("foo", context);

                // does not block
                var sw = Stopwatch.StartNew();
                span.End();
                sw.Stop();

                Assert.InRange(sw.Elapsed, TimeSpan.Zero, TimeSpan.FromMilliseconds(100));

                var exported = WaitForSpans(spanExporter, 1, DefaultTimeout);

                Assert.Single(exported);
            }
        }
Пример #4
0
        //RB: This function below bulk fill the results and add comments
        public static void FillTheResultsBulkAndCloseTheRun(JObject tr, JArray getRun, Dictionary <string, Tuple <int, string> > dict)
        {
            var st = tr.First;

            string[] ids     = (st.ToString()).Split(':');
            var      runId   = ids[1].TrimStart(); // RunID
            var      request = new AddResultsRequest();

            foreach (var item in getRun.Children())
            {
                var obj     = JObject.Parse(item.ToString());
                var title   = (string)obj.SelectToken("title");
                var id      = (string)obj.SelectToken("id");
                int res     = (int)obj.SelectToken("status_id");
                var comment = (string)obj.SelectToken("comment");
                if (dict.ContainsKey(title))
                {
                    var tupleStatusComment = dict[title];
                    res     = tupleStatusComment.Item1;
                    comment = tupleStatusComment.Item2;
                    AddResultsRequest.AddResultsItem addItem = new AddResultsRequest.AddResultsItem();
                    addItem.test_id   = id;
                    addItem.status_id = res;
                    addItem.comment   = comment;
                    request.results.Add(addItem);
                }
            }
            TestExporter.AddTestResults("add_results/" + runId, request);
            TestExporter.Post("close_run/" + runId);
        }
        public void ExportMoreSpansThanTheMaxBatchSize()
        {
            int exportCalledCount = 0;
            var spanExporter      = new TestExporter(_ => Interlocked.Increment(ref exportCalledCount));

            using (var spanProcessor = new BatchingSpanProcessor(spanExporter, 128, DefaultDelay, 3))
            {
                var span1 = CreateSampledEndedSpan(SpanName1, spanProcessor);
                var span2 = CreateSampledEndedSpan(SpanName1, spanProcessor);
                var span3 = CreateSampledEndedSpan(SpanName1, spanProcessor);
                var span4 = CreateSampledEndedSpan(SpanName1, spanProcessor);
                var span5 = CreateSampledEndedSpan(SpanName1, spanProcessor);
                var span6 = CreateSampledEndedSpan(SpanName1, spanProcessor);

                var exported = WaitForSpans(spanExporter, 6, DefaultTimeout);
                Assert.InRange(exportCalledCount, 2, 6);

                Assert.Equal(6, exported.Count());
                Assert.Contains(span1, exported);
                Assert.Contains(span2, exported);
                Assert.Contains(span3, exported);
                Assert.Contains(span4, exported);
                Assert.Contains(span5, exported);
                Assert.Contains(span6, exported);
            }
        }
        public void Exporters_XlsExporter_insertRowLinks_NoLink()
        {
            FileInfo outfile = new FileInfo(@"X:\noWhere.xlsx");

            string[] exportFields        = new string[] { "DOCID", "BEGATT", "VOLUME", "NATIVE" };
            Representative.FileType type = Representative.FileType.Native;
            string        display        = null;
            int           index          = 3;
            HyperLinkInfo link           = new HyperLinkInfo(type, display, index);

            HyperLinkInfo[] links   = new HyperLinkInfo[] { link };
            TestExporter    tester  = new TestExporter(outfile, exportFields, links);
            DataTable       dt      = tester.getMetaDataTable(this.docs);
            FileInfo        file    = new FileInfo("test.xlsx");
            ExcelPackage    package = new ExcelPackage(file);
            ExcelWorksheet  ws      = package.Workbook.Worksheets.Add("Sheet1");

            ws.Cells[1, 1].LoadFromDataTable(dt, true);
            Document doc = docs[1];
            int      row = 0;
            int      col = 3;

            tester.insertRowLinks(ws, dt, doc, row);
            string expected = String.Empty;
            string actual   = ws.Cells[row + 2, col + 1].Formula;

            Assert.AreEqual(expected, actual);
        }
        public void ExportMoreSpansThanTheMaxBatchSize()
        {
            var exporterCalled    = new ManualResetEvent(false);
            int exportCalledCount = 0;
            var spanExporter      = new TestExporter(_ =>
            {
                exporterCalled.Set();
                Interlocked.Increment(ref exportCalledCount);
            });

            using var spanProcessor = new BatchingSpanProcessor(spanExporter, 128, DefaultDelay, 3);
            var span1 = this.CreateSampledEndedSpan(SpanName1, spanProcessor);
            var span2 = this.CreateSampledEndedSpan(SpanName1, spanProcessor);
            var span3 = this.CreateSampledEndedSpan(SpanName1, spanProcessor);
            var span4 = this.CreateSampledEndedSpan(SpanName1, spanProcessor);
            var span5 = this.CreateSampledEndedSpan(SpanName1, spanProcessor);
            var span6 = this.CreateSampledEndedSpan(SpanName1, spanProcessor);

            // wait for exporter to be called to stabilize tests on the build server
            exporterCalled.WaitOne(TimeSpan.FromSeconds(10));

            var exported = this.WaitForSpans(spanExporter, 6, DefaultTimeout);

            Assert.InRange(exportCalledCount, 2, 6);

            Assert.Equal(6, exported.Count());
            Assert.Contains(new SpanData(span1), exported);
            Assert.Contains(new SpanData(span2), exported);
            Assert.Contains(new SpanData(span3), exported);
            Assert.Contains(new SpanData(span4), exported);
            Assert.Contains(new SpanData(span5), exported);
            Assert.Contains(new SpanData(span6), exported);
        }
        public void Exporters_XlsExporter_getMetaDataTable()
        {
            FileInfo outfile = new FileInfo(@"X:\noWhere.xlsx");

            string[]        exportFields = new string[] { "DOCID", "BEGATT", "VOLUME", "NATIVE" };
            HyperLinkInfo[] links        = new HyperLinkInfo[] { };
            TestExporter    tester       = new TestExporter(outfile, exportFields, links);
            DataTable       dt           = tester.getMetaDataTable(this.docs);

            for (int i = 0; i < dt.Columns.Count; i++)
            {
                string expected = exportFields[i];
                string actual   = dt.Columns[i].ColumnName;
                Assert.AreEqual(expected, actual);
            }

            for (int row = 0; row < dt.Rows.Count; row++)
            {
                for (int col = 0; col < dt.Columns.Count; col++)
                {
                    string expected = docs[row].Metadata[dt.Columns[col].ColumnName];
                    string actual   = dt.Rows[row][col].ToString();
                    Assert.AreEqual(expected, actual);
                }
            }
        }
        public void Exporters_XlsExporter_insertRowLinks_RelativeLink()
        {
            FileInfo outfile = new FileInfo(@"X:\noWhere.xlsx");

            string[] exportFields        = new string[] { "DOCID", "BEGATT", "VOLUME", "NATIVE" };
            Representative.FileType type = Representative.FileType.Native;
            string display = null;
            int    index   = 3;

            docs.First().Metadata["NATIVE"] = @"\NATIVE\0001\DOC000001.XLSX";
            docs.First().Representatives.First().Files["DOC000001"] = @"\NATIVE\0001\DOC000001.XLSX";
            HyperLinkInfo link = new HyperLinkInfo(type, display, index);

            HyperLinkInfo[] links  = new HyperLinkInfo[] { link };
            TestExporter    tester = new TestExporter(outfile, exportFields, links);
            DataTable       dt      = tester.getMetaDataTable(this.docs);
            FileInfo        file    = new FileInfo("test.xlsx");
            ExcelPackage    package = new ExcelPackage(file);
            ExcelWorksheet  ws      = package.Workbook.Worksheets.Add("Sheet1");

            ws.Cells[1, 1].LoadFromDataTable(dt, true);
            Document doc       = docs.First();
            int      row       = 0;
            int      col       = 3;
            string   linkValue = @".\NATIVE\0001\DOC000001.XLSX";

            tester.insertRowLinks(ws, dt, doc, row);
            string expected = String.Format(
                "HYPERLINK(\"{0}\", \"{1}\")", linkValue, "\\NATIVE\\0001\\DOC000001.XLSX");
            string actual = ws.Cells[row + 2, col + 1].Formula;

            Assert.AreEqual(expected, actual);
        }
        public void ProcessorDoesNotBlockOnExporter()
        {
            spanExporter = new TestExporter(_ => Thread.Sleep(500));

            spanProcessor = new BatchingSpanProcessor(spanExporter);

            var sampledActivity = new Activity("foo");

            sampledActivity.ActivityTraceFlags |= ActivityTraceFlags.Recorded;
            sampledActivity.SetIdFormat(ActivityIdFormat.W3C);
            sampledActivity.Start();
            var span =
                new Span(
                    sampledActivity,
                    Tracestate.Empty,
                    SpanKind.Internal,
                    TraceConfig.Default,
                    spanProcessor,
                    PreciseTimestamp.GetUtcNow(),
                    default);

            // does not block
            var sw = Stopwatch.StartNew();

            span.End();
            sw.Stop();

            Assert.InRange(sw.Elapsed, TimeSpan.Zero, TimeSpan.FromMilliseconds(100));

            var exported = WaitForSpans(spanExporter, 1, TimeSpan.FromMilliseconds(600));

            Assert.Single(exported);
        }
        public void ExportMoreSpansThanTheMaxBatchSize()
        {
            int exportCalledCount = 0;

            spanExporter  = new TestExporter(_ => Interlocked.Increment(ref exportCalledCount));
            spanProcessor = new BatchingSpanProcessor(spanExporter, 128, DefaultDelay, 3);
            var span1 = CreateSampledEndedSpan(SpanName1);
            var span2 = CreateSampledEndedSpan(SpanName1);
            var span3 = CreateSampledEndedSpan(SpanName1);
            var span4 = CreateSampledEndedSpan(SpanName1);
            var span5 = CreateSampledEndedSpan(SpanName1);
            var span6 = CreateSampledEndedSpan(SpanName1);

            var exported = WaitForSpans(spanExporter, 6, TimeSpan.FromMilliseconds(100));

            Assert.Equal(2, exportCalledCount);

            Assert.Equal(6, exported.Count());
            Assert.Contains(span1, exported);
            Assert.Contains(span2, exported);
            Assert.Contains(span3, exported);
            Assert.Contains(span4, exported);
            Assert.Contains(span5, exported);
            Assert.Contains(span6, exported);
        }
        public void Exporters_XrefExporter_isFlagNeeded()
        {
            Document parent = new Document("DOC122", null, null, new Dictionary <string, string>()
            {
                { "TEST", "abc123" }
            }, null);
            Document doc = new Document("DOC123", parent, null, new Dictionary <string, string>()
            {
                { "TEST", "XYZ321" }
            }, null);
            Trigger trigger = new Trigger();

            trigger.Type = Switch.SwitchType.None;
            TestExporter exporter = new TestExporter();

            Assert.IsFalse(exporter.isFlagNeeded(doc, trigger.ToSwitch(), parent));
            trigger.Type = Switch.SwitchType.Family;
            Assert.IsTrue(exporter.isFlagNeeded(parent, trigger.ToSwitch(), null));
            Assert.IsFalse(exporter.isFlagNeeded(doc, trigger.ToSwitch(), parent));
            trigger.Type         = Switch.SwitchType.Regex;
            trigger.FieldName    = "TEST";
            trigger.RegexPattern = "[a-zA-Z]+\\d+";
            Assert.IsTrue(exporter.isFlagNeeded(parent, trigger.ToSwitch(), null));
            Assert.IsTrue(exporter.isFlagNeeded(doc, trigger.ToSwitch(), parent));
            doc.Metadata["TEST"] = "123nope";
            Assert.IsFalse(exporter.isFlagNeeded(doc, trigger.ToSwitch(), parent));
        }
        public async Task ShutdownOnNotEmptyQueueNotFullFlush()
        {
            const int batchSize         = 2;
            int       exportCalledCount = 0;

            // we'll need about 1.5 sec to export all spans
            // we export 100 spans in batches of 2, each export takes 30ms, in one thread
            var spanExporter = new TestExporter(_ =>
            {
                Interlocked.Increment(ref exportCalledCount);
                Thread.Sleep(30);
            });

            using var spanProcessor =
                      new BatchingSpanProcessor(spanExporter, 128, TimeSpan.FromMilliseconds(100), batchSize);
            var spans = new List <SpanSdk>();

            for (int i = 0; i < 100; i++)
            {
                spans.Add(this.CreateSampledEndedSpan(i.ToString(), spanProcessor));
            }

            Assert.True(spanExporter.ExportedSpans.Length < spans.Count);

            // we won't bs able to export all before cancellation will fire
            using (var cts = new CancellationTokenSource(TimeSpan.FromMilliseconds(200)))
            {
                await spanProcessor.ShutdownAsync(cts.Token);
            }

            var exportedCount = spanExporter.ExportedSpans.Length;

            Assert.True(exportedCount < spans.Count);
        }
        public async Task ShutdownOnNotEmptyQueueFullFlush()
        {
            const int batchSize         = 2;
            int       exportCalledCount = 0;
            var       spanExporter      = new TestExporter(_ => Interlocked.Increment(ref exportCalledCount));

            using var spanProcessor =
                      new BatchingSpanProcessor(spanExporter, 128, TimeSpan.FromMilliseconds(100), batchSize);
            var spans = new List <SpanSdk>();

            for (int i = 0; i < 100; i++)
            {
                spans.Add(this.CreateSampledEndedSpan(i.ToString(), spanProcessor));
            }

            Assert.True(spanExporter.ExportedSpans.Length < spans.Count);
            using (var cts = new CancellationTokenSource(DefaultTimeout))
            {
                await spanProcessor.ShutdownAsync(cts.Token);
            }

            Assert.True(spanExporter.WasShutDown);
            Assert.Equal(spans.Count, spanExporter.ExportedSpans.Length);
            Assert.InRange(exportCalledCount, spans.Count / batchSize, spans.Count);
        }
Пример #15
0
 public SimpleSpanProcessorTest()
 {
     spanExporter = new TestExporter(null);
     tracer       = TracerFactory.Create(b => b
                                         .SetExporter(spanExporter)
                                         .SetProcessor(e => new SimpleSpanProcessor(e)))
                    .GetTracer(null);
 }
        public void TracerBuilder_ValidArgs()
        {
            var builder = new TracerBuilder();

            bool processorFactoryCalled = false;
            bool collectorFactoryCalled = true;

            var sampler      = new ProbabilitySampler(0.1);
            var exporter     = new TestExporter(_ => { });
            var options      = new TracerConfiguration(1, 1, 1);
            var binaryFormat = new BinaryFormat();
            var textFormat   = new TraceContextFormat();

            builder
            .SetSampler(sampler)
            .AddProcessorPipeline(p => p
                                  .SetExporter(exporter)
                                  .SetExportingProcessor(e =>
            {
                processorFactoryCalled = true;
                Assert.Same(e, exporter);
                return(new SimpleSpanProcessor(e));
            }))
            .SetTracerOptions(options)
            .SetBinaryFormat(binaryFormat)
            .SetTextFormat(textFormat)
            .AddCollector(t =>
            {
                Assert.NotNull(t);
                return(new TestCollector(t));
            });

            Assert.Same(sampler, builder.Sampler);

            Assert.NotNull(builder.ProcessingPipelines);
            Assert.Single(builder.ProcessingPipelines);
            Assert.Same(exporter, builder.ProcessingPipelines[0].Exporter);

            Assert.NotNull(builder.ProcessingPipelines[0].Build());
            Assert.True(processorFactoryCalled);

            Assert.Same(options, builder.TracerConfigurationOptions);
            Assert.Same(binaryFormat, builder.BinaryFormat);
            Assert.Same(textFormat, builder.TextFormat);
            Assert.Single(builder.CollectorFactories);

            var collectorFactory = builder.CollectorFactories.Single();

            Assert.Equal(nameof(TestCollector), collectorFactory.Name);
            Assert.Equal("semver:" + typeof(TestCollector).Assembly.GetName().Version, collectorFactory.Version);

            Assert.NotNull(collectorFactory.Factory);
            collectorFactory.Factory(new Tracer(new SimpleSpanProcessor(exporter), new AlwaysSampleSampler(), options, binaryFormat, textFormat,
                                                Resource.Empty));

            Assert.True(collectorFactoryCalled);
        }
Пример #17
0
 public SimpleSpanProcessorTest()
 {
     spanExporter = new TestExporter(null);
     tracer       = TracerFactory.Create(b => b
                                         .AddProcessorPipeline(p => p
                                                               .SetExporter(spanExporter)
                                                               .SetExportingProcessor(e => new SimpleSpanProcessor(e))))
                    .GetTracer(null);
 }
Пример #18
0
        //RB: This function below gets the tests run id
        public static JArray GetTestsRunId(JObject tr)
        {
            var st = tr.First;

            string[] id     = (st.ToString()).Split(':');
            JArray   getRun = TestExporter.Get1("get_tests/" + id[1].TrimStart());

            return(getRun);
        }
        public async Task RequestMetricIsCaptured()
        {
            var metricItems    = new List <MetricItem>();
            var metricExporter = new TestExporter <MetricItem>(ProcessExport);

            void ProcessExport(Batch <MetricItem> batch)
            {
                foreach (var metricItem in batch)
                {
                    metricItems.Add(metricItem);
                }
            }

            var processor = new PullMetricProcessor(metricExporter, true);

            this.meterProvider = Sdk.CreateMeterProviderBuilder()
                                 .AddAspNetCoreInstrumentation()
                                 .AddMetricProcessor(processor)
                                 .Build();

            using (var client = this.factory.CreateClient())
            {
                var response = await client.GetAsync("/api/values");

                response.EnsureSuccessStatusCode();
            }

            // We need to let End callback execute as it is executed AFTER response was returned.
            // In unit tests environment there may be a lot of parallel unit tests executed, so
            // giving some breezing room for the End callback to complete
            await Task.Delay(TimeSpan.FromSeconds(1));

            // Invokes the TestExporter which will invoke ProcessExport
            processor.PullRequest();

            this.meterProvider.Dispose();

            var requestMetrics = metricItems
                                 .SelectMany(item => item.Metrics.Where(metric => metric.Name == "http.server.duration"))
                                 .ToArray();

            Assert.True(requestMetrics.Length == 1);

            var metric = requestMetrics[0] as IHistogramMetric;

            Assert.NotNull(metric);
            Assert.Equal(1L, metric.PopulationCount);
            Assert.True(metric.PopulationSum > 0);

            var bucket = metric.Buckets
                         .Where(b =>
                                metric.PopulationSum > b.LowBoundary &&
                                metric.PopulationSum <= b.HighBoundary)
                         .FirstOrDefault();

            Assert.NotEqual(default, bucket);
        public void Setup()
        {
            var metricExporter = new TestExporter <Metric>(ProcessExport);

            void ProcessExport(Batch <Metric> batch)
            {
                double sum = 0;

                foreach (var metric in batch)
                {
                    if (this.UseWithRef)
                    {
                        // The performant way of iterating.
                        foreach (ref var metricPoint in metric.GetMetricPoints())
                        {
                            sum += metricPoint.GetCounterSumDouble();
                        }
                    }
                    else
                    {
                        // The non-performant way of iterating.
                        // This is still "correct", but less performant.
                        foreach (var metricPoint in metric.GetMetricPoints())
                        {
                            sum += metricPoint.GetCounterSumDouble();
                        }
                    }
                }
            }

            this.reader = new BaseExportingMetricReader(metricExporter)
            {
                Temporality = AggregationTemporality.Cumulative,
            };

            this.meter = new Meter(Utils.GetCurrentMethodName());

            this.provider = Sdk.CreateMeterProviderBuilder()
                            .AddMeter(this.meter.Name)
                            .AddReader(this.reader)
                            .Build();

            this.counter         = this.meter.CreateCounter <double>("counter");
            this.token           = new CancellationTokenSource();
            this.writeMetricTask = new Task(() =>
            {
                while (!this.token.IsCancellationRequested)
                {
                    var tag1 = new KeyValuePair <string, object>("DimName1", this.dimensionValues[this.random.Next(0, 10)]);
                    var tag2 = new KeyValuePair <string, object>("DimName2", this.dimensionValues[this.random.Next(0, 10)]);
                    var tag3 = new KeyValuePair <string, object>("DimName3", this.dimensionValues[this.random.Next(0, 10)]);
                    this.counter.Add(100.00, tag1, tag2, tag3);
                }
            });
            this.writeMetricTask.Start();
        }
        public void Test()
        {
            var testExporter = new TestExporter();
            var config = DefaultConfig.Instance.With(testExporter);
            BenchmarkTestExecutor.CanExecute<BaselineDeltaResultExtenderNoBaselineTest>(config);

            // Ensure that when the TestBenchmarkExporter() was run, it wasn't passed an instance of "BenchmarkBaselineDeltaResultExtender"
            Assert.False(testExporter.ExportCalled);
            Assert.True(testExporter.ExportToFileCalled);
        }
Пример #22
0
        public void CustomExportContextUsedDuringRequestProcessing()
        {
            JsonRpcDispatcher dispatcher = new JsonRpcDispatcher(new TestService());
            TestExporter      exporter   = new TestExporter();

            Assert.IsFalse(exporter.ExportCalled);
            dispatcher.JsonExporter = new JsonExportHandler(exporter.Export);
            dispatcher.Process("{ id: 1, method: Dummy }");
            Assert.IsTrue(exporter.ExportCalled);
        }
 public SimpleSpanProcessorTest()
 {
     this.spanExporter = new TestExporter(null);
     this.tracer       = TracerFactory.Create(b => b
                                              .AddProcessorPipeline(p => p
                                                                    .SetExporter(this.spanExporter)
                                                                    .SetExportingProcessor(e => new SimpleSpanProcessor(e)))
                                              .SetSampler(new AlwaysParentSampler()))
                         .GetTracer(null);
 }
Пример #24
0
        public void TestMetricPointCap(AggregationTemporality temporality)
        {
            var metricItems      = new List <Metric>();
            int metricPointCount = 0;
            var metricExporter   = new TestExporter <Metric>(ProcessExport);

            void ProcessExport(Batch <Metric> batch)
            {
                foreach (var metric in batch)
                {
                    foreach (ref var metricPoint in metric.GetMetricPoints())
                    {
                        metricPointCount++;
                    }
                }
            }

            var metricReader = new BaseExportingMetricReader(metricExporter)
            {
                PreferredAggregationTemporality = temporality,
            };

            using var meter = new Meter("TestPointCapMeter");
            var counterLong = meter.CreateCounter <long>("mycounterCapTest");

            using var meterProvider = Sdk.CreateMeterProviderBuilder()
                                      .AddMeter("TestPointCapMeter")
                                      .AddReader(metricReader)
                                      .Build();

            // Make one Add with no tags.
            // as currently we reserve 0th index
            // for no tag point!
            // This may be changed later.
            counterLong.Add(10);
            for (int i = 0; i < AggregatorStore.MaxMetricPoints + 1; i++)
            {
                counterLong.Add(10, new KeyValuePair <string, object>("key", "value" + i));
            }

            metricReader.Collect();
            Assert.Equal(AggregatorStore.MaxMetricPoints, metricPointCount);

            metricPointCount = 0;
            metricReader.Collect();
            Assert.Equal(AggregatorStore.MaxMetricPoints, metricPointCount);

            // These updates would be dropped.
            counterLong.Add(10, new KeyValuePair <string, object>("key", "valueA"));
            counterLong.Add(10, new KeyValuePair <string, object>("key", "valueB"));
            counterLong.Add(10, new KeyValuePair <string, object>("key", "valueC"));
            metricPointCount = 0;
            metricReader.Collect();
            Assert.Equal(AggregatorStore.MaxMetricPoints, metricPointCount);
        }
Пример #25
0
 //RB: This function gets the test cases and add it to the specific run
 public static JObject GetCasesandAddtoRun(Dictionary <string, Tuple <int, string> > dict, Dictionary <string, string> dictNameSuite, Dictionary <string, string> dictNameSections, string testTypes, object project, object suiteName, object sectionName)
 {
     RArray = TestExporter.Get1("get_cases/" +
                                AppSettings[project.ToString()] + "&suite_id=" +
                                dictNameSuite[suiteName.ToString()] + "&section_id=" +
                                dictNameSections[sectionName.ToString()]);
     SuiteId = int.Parse(dictNameSuite[suiteName.ToString()]);
     RunName = suiteName + " " + System.DateTime.Now;
     Tr      = TestExporter.CreateTestRunAddAllCases("add_run/" + AppSettings[project.ToString()], SuiteId, RunName);
     return(Tr);
 }
Пример #26
0
        public void Test()
        {
            var testExporter = new TestExporter();
            var config       = DefaultConfig.Instance.With(testExporter);

            BenchmarkTestExecutor.CanExecute <BaselineDeltaResultExtenderNoBaselineTest>(config);

            // Ensure that when the TestBenchmarkExporter() was run, it wasn't passed an instance of "BenchmarkBaselineDeltaResultExtender"
            Assert.False(testExporter.ExportCalled);
            Assert.True(testExporter.ExportToFileCalled);
        }
        public void Test()
        {
            var logger = new AccumulationLogger();
            var testExporter = new TestExporter();
            var config = DefaultConfig.Instance.With(logger).With(testExporter);
            BenchmarkRunner.Run(this.GetType(), config);

            // Ensure that when the TestBenchmarkExporter() was run, it wasn't passed an instance of "BenchmarkBaselineDeltaResultExtender"
            Assert.False(testExporter.ExportCalled);
            Assert.True(testExporter.ExportToFileCalled);
        }
        public void Test()
        {
            var testExporter = new TestExporter();
            var config = CreateSimpleConfig().With(testExporter);

            CanExecute<BaselineScaledResultExtenderNoBaseline>(config);

            // Ensure that when the TestBenchmarkExporter() was run, it wasn't passed an instance of "BenchmarkBaselineDeltaResultExtender"
            Assert.False(testExporter.ExportCalled);
            Assert.True(testExporter.ExportToFileCalled);
        }
Пример #29
0
        public void Test()
        {
            var testExporter = new TestExporter();
            var config       = CreateSimpleConfig().With(testExporter);

            CanExecute <BaselineRatioResultExtenderNoBaseline>(config);

            // Ensure that when the TestBenchmarkExporter() was run, it wasn't passed an instance of "BenchmarkBaselineDeltaResultExtender"
            Assert.False(testExporter.ExportCalled);
            Assert.True(testExporter.ExportToFileCalled);
        }
Пример #30
0
        public void StreamNamesDuplicatesAreNotAllowedTest(AggregationTemporality temporality)
        {
            var metricItems    = new List <Metric>();
            int metricCount    = 0;
            var metricExporter = new TestExporter <Metric>(ProcessExport);

            void ProcessExport(Batch <Metric> batch)
            {
                foreach (var metric in batch)
                {
                    metricCount++;
                }
            }

            var metricReader = new BaseExportingMetricReader(metricExporter)
            {
                PreferredAggregationTemporality = temporality,
            };

            using var meter1        = new Meter("TestDuplicateMetricName1");
            using var meter2        = new Meter("TestDuplicateMetricName2");
            using var meterProvider = Sdk.CreateMeterProviderBuilder()
                                      .AddMeter("TestDuplicateMetricName1")
                                      .AddMeter("TestDuplicateMetricName2")
                                      .AddReader(metricReader)
                                      .Build();

            // Expecting one metric stream.
            var counterLong = meter1.CreateCounter <long>("name1");

            counterLong.Add(10);
            metricReader.Collect();
            Assert.Equal(1, metricCount);

            // The following will be ignored as
            // metric of same name exists.
            // Metric stream will remain one.
            var anotherCounterSameName = meter1.CreateCounter <long>("name1");

            anotherCounterSameName.Add(10);
            metricCount = 0;
            metricReader.Collect();
            Assert.Equal(1, metricCount);

            // The following will also be ignored
            // as the name is same.
            // (the Meter name is not part of stream name)
            var anotherCounterSameNameDiffMeter = meter2.CreateCounter <long>("name1");

            anotherCounterSameNameDiffMeter.Add(10);
            metricCount = 0;
            metricReader.Collect();
            Assert.Equal(1, metricCount);
        }
        private SpanData[] WaitForSpans(TestExporter exporter, int spanCount, TimeSpan timeout)
        {
            Assert.True(
                SpinWait.SpinUntil(() =>
            {
                Thread.Sleep(0);
                return(exporter.ExportedSpans.Length >= spanCount);
            }, timeout + TimeSpan.FromMilliseconds(20)));

            return(exporter.ExportedSpans);
        }
        public void Exporters_XrefExporter_getNextImageKey()
        {
            var          docs     = GetDocs();
            TestExporter exporter = new TestExporter();

            exporter.SetDocs(docs);
            Assert.AreEqual("DOC000002", exporter.getNextImageKey(0, 0));
            Assert.AreEqual("DOC000003", exporter.getNextImageKey(0, 1));
            Assert.AreEqual(null, exporter.getNextImageKey(1, 1));
            Assert.AreEqual(null, exporter.getNextImageKey(2, 1));
        }
Пример #33
0
        //RB: This function gets the sections name and ID for a specific suite
        public static Dictionary <string, string> GetSections(object project, Dictionary <string, string> dictNameSuite, string suiteName)
        {
            RArray = TestExporter.Get1("get_sections/" + AppSettings[project.ToString()] + "&suite_id=" + dictNameSuite[suiteName]);
            Dictionary <string, string> dictNameSections = new Dictionary <string, string>();

            foreach (var item in RArray.Children())
            {
                var obj = JObject.Parse(item.ToString());
                dictNameSections.Add((string)obj.SelectToken("name"), (string)obj.SelectToken("id"));
            }
            return(dictNameSections);
        }
Пример #34
0
 public void CustomExportContextUsedDuringRequestProcessing()
 {
     JsonRpcDispatcher dispatcher = new JsonRpcDispatcher(new TestService());
     TestExporter exporter = new TestExporter();
     Assert.IsFalse(exporter.ExportCalled);
     dispatcher.JsonExporter = new JsonExportHandler(exporter.Export);
     dispatcher.Process("{ id: 1, method: Dummy }");
     Assert.IsTrue(exporter.ExportCalled);
 }