private static SerializedMetric Serialize( string name, int status, int?timestamp = null, string hostname = null, string[] tags = null, string serviceCheckMessage = null, bool truncateIfTooLong = false) { var statsServiceCheck = new StatsServiceCheck { Name = name, Status = status, Timestamp = timestamp, Hostname = hostname, ServiceCheckMessage = serviceCheckMessage, TruncateIfTooLong = truncateIfTooLong, Tags = tags, }; var serializer = CreateSerializer(); var serializedMetric = new SerializedMetric(); serializer.SerializeTo(ref statsServiceCheck, serializedMetric); return(serializedMetric); }
private static void AssertSerialize( string expectValue, string title = null, string text = null, string alertType = null, string aggregationKey = null, string sourceType = null, int?dateHappened = null, string priority = null, string hostname = null, string[] tags = null, bool truncateIfTooLong = false) { var serializer = CreateSerializer(); var statsEvent = new StatsEvent { Title = title, Text = text, AlertType = alertType, AggregationKey = aggregationKey, SourceType = sourceType, DateHappened = dateHappened, Priority = priority, Hostname = hostname, TruncateIfTooLong = truncateIfTooLong, Tags = tags, }; var serializedMetric = new SerializedMetric(); serializer.SerializeTo(ref statsEvent, serializedMetric); Assert.AreEqual(expectValue, serializedMetric.ToString()); }
public void Add(SerializedMetric serializedMetric) { var length = serializedMetric.CopyToChars(_charsBuffers); if (length < 0) { throw new InvalidOperationException($"The metric size exceeds the internal buffer capacity {_charsBuffers.Length}: {serializedMetric.ToString()}"); } var byteCount = _encoding.GetByteCount(_charsBuffers, 0, length); if (byteCount > Capacity) { throw new InvalidOperationException($"The metric size exceeds the buffer capacity {Capacity}: {serializedMetric.ToString()}"); } if (Length != 0) { byteCount += _separator.Length; } if (Length + byteCount > Capacity) { this.HandleBufferAndReset(); } if (Length != 0) { Array.Copy(_separator, 0, _buffer, Length, _separator.Length); Length += _separator.Length; } // GetBytes requires the buffer to be big enough otherwise it throws, that is why we use GetByteCount. Length += _encoding.GetBytes(_charsBuffers, 0, length, _buffer, Length); }
private static SerializedMetric CreateSerializedMetric(char c, int count) { var serializedMetric = new SerializedMetric(); serializedMetric.Builder.Append(new string(c, count)); return(serializedMetric); }
public bool Send(SerializedMetric serializedMetric) { if (!this._worker.TryEnqueue(serializedMetric)) { serializedMetric.Dispose(); return(false); } return(true); }
private static void AssertSerialize( string expectValue, ref StatsMetric statsMetric, string prefix) { var serializerHelper = new SerializerHelper(null); var serializer = new MetricSerializer(serializerHelper, prefix); var serializedMetric = new SerializedMetric(); serializer.SerializeTo(ref statsMetric, serializedMetric); Assert.AreEqual(expectValue, serializedMetric.ToString()); }
public void StatsBufferize() { var handler = new BufferBuilderHandlerMock(); var bufferBuilder = new BufferBuilder(handler, 3, "\n"); using (var statsBufferize = new StatsBufferize(bufferBuilder, 10, null, TimeSpan.Zero)) { var serializedMetric = new SerializedMetric(new Pool <SerializedMetric>(p => new SerializedMetric(p), 10)); serializedMetric.Builder.Append("1"); statsBufferize.Send(serializedMetric); while (handler.Buffer == null) { Task.Delay(TimeSpan.FromMilliseconds(1)).Wait(); } // Sent because buffer is full. Assert.AreEqual("1", Encoding.UTF8.GetString(handler.Buffer)); } }
public bool Add(SerializedMetric serializedMetric) { var length = serializedMetric.CopyToChars(_charsBuffers); if (length < 0) { return(false); } var byteCount = _encoding.GetByteCount(_charsBuffers, 0, length); if (byteCount > Capacity) { return(false); } if (Length != 0) { byteCount += _separator.Length; } if (Length + byteCount > Capacity) { this.HandleBufferAndReset(); } if (Length != 0) { Array.Copy(_separator, 0, _buffer, Length, _separator.Length); Length += _separator.Length; } // GetBytes requires the buffer to be big enough otherwise it throws, that is why we use GetByteCount. Length += _encoding.GetBytes(_charsBuffers, 0, length, _buffer, Length); return(true); }