Esempio n. 1
0
        public async Task BatchesMetrics()
        {
            var uploader = new EdgeRuntimeDiagnosticsUpload(this.mockConnection);

            // Doesn't batch small numbers of metrics
            Metric[] singleBatch = this.GetFakeMetrics(20);
            await uploader.PublishAsync(singleBatch, CancellationToken.None);

            Assert.Single(this.lastUploadResult);
            TestUtilities.OrderlessCompare(singleBatch, this.ParseLastUploadResult());

            // correctly batches even number of metrics
            Metric[] evenBatch = this.GetFakeMetrics(20000);
            await uploader.PublishAsync(evenBatch, CancellationToken.None);

            Assert.True(this.lastUploadResult.Count > 1, $"Expected more than 1 uploaded message. Got {this.lastUploadResult.Count}");
            TestUtilities.OrderlessCompare(evenBatch, this.ParseLastUploadResult());

            // correctly batches odd number of metrics
            Metric[] oddBatch = this.GetFakeMetrics(20001);
            await uploader.PublishAsync(oddBatch, CancellationToken.None);

            Assert.True(this.lastUploadResult.Count > 1, $"Expected more than 1 uploaded message. Got {this.lastUploadResult.Count}");
            TestUtilities.OrderlessCompare(oddBatch, this.ParseLastUploadResult());
        }
Esempio n. 2
0
        public async Task SendsMultipleMetrics()
        {
            var uploader = new EdgeRuntimeDiagnosticsUpload(this.mockConnection);

            Metric[] expectedMetrics = this.GetFakeMetrics(20);

            await uploader.PublishAsync(expectedMetrics, CancellationToken.None);

            Metric[] uploadedMetrics = this.ParseLastUploadResult();
            TestUtilities.OrderlessCompare(expectedMetrics, uploadedMetrics);
        }
        public async Task BasicFunctionality()
        {
            var uploader = new EdgeRuntimeDiagnosticsUpload(this.mockConnection);

            Metric expectedMetric = new Metric(DateTime.UtcNow, "test_metric", 10, new Dictionary <string, string> {
                { "tag1", "asdf" }, { "tag2", "fdsa" }
            });

            await uploader.PublishAsync(new Metric[] { expectedMetric }, CancellationToken.None);

            Message uploadResult = this.lastUploadResult.Single();

            Assert.Equal("application/x-azureiot-edgeruntimediagnostics", uploadResult.ContentType);

            Metric uploadedMetric = MetricsSerializer.BytesToMetrics(uploadResult.GetBytes()).Single();

            Assert.Equal(expectedMetric, uploadedMetric);
        }