public void TestMetricsSeriesSerializes() { Metric[] testMetrics = this.metrics.SelectMany(m => this.GenerateSeries(m.name, m.tags, this.rand.Next(10, 20))).ToArray(); byte[] data = MetricsSerializer.MetricsToBytes(testMetrics).ToArray(); Metric[] reconstructedValues = MetricsSerializer.BytesToMetrics(data).ToArray(); TestUtilities.OrderlessCompare(testMetrics, reconstructedValues); }
public void TestSingleMetricSeriesSerializes() { Metric[] testMetrics = this.GenerateSeries(this.metrics[0].name, this.metrics[0].tags).ToArray(); byte[] data = MetricsSerializer.MetricsToBytes(testMetrics).ToArray(); Metric[] reconstructedValues = MetricsSerializer.BytesToMetrics(data).ToArray(); TestUtilities.OrderlessCompare(testMetrics, reconstructedValues); }
public void TestSingleMetricSerializes() { Metric testMetric = new Metric(DateTime.UtcNow, this.metrics[0].name, this.rand.NextDouble() * 50, this.metrics[0].tags); byte[] data = MetricsSerializer.MetricsToBytes(new Metric[] { testMetric }).ToArray(); Metric[] reconstructedValues = MetricsSerializer.BytesToMetrics(data).ToArray(); Assert.Single(reconstructedValues); Assert.Equal(testMetric, reconstructedValues[0]); }
public void TestMetricsSeriesSerializes() { Metric[] testMetrics = this.metrics.SelectMany(m => this.GenerateSeries(m.name, m.tags, this.rand.Next(10, 20))).ToArray(); byte[] data = MetricsSerializer.MetricsToBytes(testMetrics).ToArray(); Metric[] reconstructedValues = MetricsSerializer.BytesToMetrics(data).ToArray(); var expected = testMetrics.OrderBy(m => m.Name).ThenBy(m => m.Tags).ThenBy(m => m.TimeGeneratedUtc).ToArray(); var actual = reconstructedValues.OrderBy(m => m.Name).ThenBy(m => m.Tags).ThenBy(m => m.TimeGeneratedUtc).ToArray(); Assert.Equal(expected, actual); }
public void TestSingleMetricSeriesSerializes() { Metric[] testMetrics = this.GenerateSeries(this.metrics[0].name, this.metrics[0].tags).ToArray(); byte[] data = MetricsSerializer.MetricsToBytes(testMetrics).ToArray(); Metric[] reconstructedValues = MetricsSerializer.BytesToMetrics(data).ToArray(); var expected = testMetrics.OrderBy(m => m.Name).ThenBy(m => m.Tags).ThenBy(m => m.TimeGeneratedUtc); var actual = reconstructedValues.OrderBy(m => m.Name).ThenBy(m => m.Tags).ThenBy(m => m.TimeGeneratedUtc); Assert.Equal(expected, actual); }
public async Task PublishAsync(IEnumerable <Metric> metrics, CancellationToken cancellationToken) { Preconditions.CheckNotNull(metrics, nameof(metrics)); byte[] data = MetricsSerializer.MetricsToBytes(metrics).ToArray(); byte[] compressedData = Compression.CompressToGzip(data); // TODO: add check for too big of a message if (compressedData.Length > 0) { Message message = new Message(compressedData); await this.moduleClient.SendEventAsync(message); } }
IEnumerable<Message> BatchAndBuildMessages(ArraySegment<Metric> metrics) { if (!metrics.Any()) { return Enumerable.Empty<Message>(); } byte[] data = MetricsSerializer.MetricsToBytes(metrics).ToArray(); if (data.Length > MaxMessageSize) { var part1 = this.BatchAndBuildMessages(metrics.Slice(0, metrics.Count / 2)); var part2 = this.BatchAndBuildMessages(metrics.Slice(metrics.Count / 2)); return part1.Concat(part2); } else { return new Message[] { this.BuildMessage(data) }; } }
public async Task <bool> PublishAsync(IEnumerable <Metric> metrics, CancellationToken cancellationToken) { Preconditions.CheckNotNull(metrics, nameof(metrics)); byte[] data = MetricsSerializer.MetricsToBytes(metrics).ToArray(); if (data.Length > 0) { Message message = this.BuildMessage(data); try { await this.edgeAgentConnection.SendEventAsync(message); } catch (Exception ex) when(ex.HasTimeoutException()) { Log.LogDebug(ex, "Send message to IoTHub"); return(false); } } return(true); }