public void sends_multiple_metrics_at_once() { var metric1 = new Counting() { Name = "testMetric", ValueAsInt = 5 }; var metric2 = new Timing() { Name = "testtimer", ValueAsInt = 10 }; var sender = new BatchSender(); sender.StatsdUDP = _udp; sender.Send(metric1); sender.Send(metric2); sender.Flush(); IList <object[]> argsPerCall = _udp.GetArgumentsForCallsMadeOn(x => x.Send(Arg <string> .Is.Anything)); Assert.That(argsPerCall.Count, Is.EqualTo(1)); var packet = (string)argsPerCall[0][0]; var lines = packet.Split('\n'); Assert.That(lines.Length, Is.EqualTo(2)); Assert.That(lines[0], Is.EqualTo(metric1.Command)); Assert.That(lines[1], Is.EqualTo(metric2.Command)); }
//private bool _loginStarted = false; //private static readonly Object obj = new Object(); public D7ServicesClient(IFileSystemShim fsShim, ISerializer serializer) { _fsShim = fsShim; _serialzr = ForwardLogs(serializer); _client = ForwardLogs(new RestSharpClientShim()); _auth = ForwardLogs(new SessionAuth(fsShim, serializer)); _batchr = ForwardLogs(new BatchSender(_client, _auth)); _client.ResponseReceived += (s, e) => RaiseResponseReceived(e.Value); }
public void does_not_send_metric_immediately() { var metric = new Counting() { Name = "testMetric", ValueAsInt = 5 }; var sender = new BatchSender(); sender.StatsdUDP = _udp; sender.Send(metric); _udp.AssertWasNotCalled(x => x.Send(Arg <string> .Is.Anything)); }
protected internal override void Process(RelationshipRecord[] batch, BatchSender sender) { RelationshipCountsProcessor processor = processor(); foreach (RelationshipRecord record in batch) { if (record.InUse()) { processor.Process(record); } } _progressMonitor.progress(batch.Length); }
void ib_OnDone(BatchSender sender, DoneReason reason) { this.Log.PostHead("Emulator", "Stop sending image, reason: " + reason); this.ShowImageProgressBar(false); if (reason == DoneReason.Success) { this.Messages.Sent("Image sent success"); } else { this.Messages.Sent("Cannot sent image: " + reason); } }
public void does_not_blow_up_if_metric_command_throws() { var metric = MockRepository.GenerateStub <Counting>(); metric.Stub(x => x.Command).Throw(new Exception()); var sender = new BatchSender(); sender.StatsdUDP = _udp; sender.Send(metric); sender.Flush(); Assert.Pass(); }
public void does_not_blow_up_if_udp_send_throws() { var udpStub = MockRepository.GenerateStub <IStatsdUDP>(); udpStub.Stub(x => x.Send(Arg <string> .Is.Anything)).Throw(new Exception()); var metric = new Counting() { Name = "testMetric", ValueAsInt = 1 }; var sender = new BatchSender(); sender.StatsdUDP = udpStub; sender.Send(metric); sender.Flush(); Assert.Pass(); }
protected internal override void Process(RECORD[] batch, BatchSender sender) { System.Func <long, IdSequence> idSequence = _prepareIdSequence.apply(Store); int recordsUpdatedInThisBatch = 0; foreach (RECORD record in batch) { if (record != null && record.inUse() && !IdValidator.isReservedId(record.Id)) { Store.prepareForCommit(record, idSequence(record.Id)); Store.updateRecord(record); recordsUpdatedInThisBatch++; } } _recordsUpdated.add(recordsUpdatedInThisBatch); }
protected internal override void Process(object batch, BatchSender sender) { try { Thread.Sleep(ProcessingTime); } catch (InterruptedException e) { throw new Exception(e); } if (!EndOfLine) { sender.Send(batch); } }
public void sends_metric_on_flush() { var metric = new Counting() { Name = "testMetric", ValueAsInt = 5 }; var sender = new BatchSender(); sender.StatsdUDP = _udp; sender.Send(metric); sender.Flush(); IList <object[]> argsPerCall = _udp.GetArgumentsForCallsMadeOn(x => x.Send(Arg <string> .Is.Anything)); Assert.That(argsPerCall.Count, Is.EqualTo(1)); Assert.That(((string)argsPerCall[0][0]), Is.EqualTo(metric.Command)); }
public void send_oversized_udp_packets_are_split_if_possible_with_multiple_messages_in_one_packet() { var msg = new String('f', MetricsConfig.DefaultStatsdMaxUDPPacketSize / 2); listenThread.Start(3); var sender = new BatchSender(); var statsd = new Statsd(new Statsd.Configuration() { Udp = udp, Sender = sender }); statsd.Send <Statsd.Counting>("counter", 1); statsd.Send <Statsd.Counting>(msg, 2); statsd.Send <Statsd.Counting>(msg, 3); sender.Flush(); // Make sure that a split packet can contain mulitple metrics AssertWasReceived(String.Format("counter:1|c\n{0}:2|c", msg), 0); AssertWasReceived(String.Format("{0}:3|c", msg), 1); AssertWasReceived(null, 2); }
public void set_max_udp_packet_size() { // Make sure that we can set the max UDP packet size udp = new StatsdUDP(serverName, serverPort, 10); var msg = new String('f', 5); listenThread.Start(2); var sender = new BatchSender(); var statsd = new Statsd(new Statsd.Configuration() { Udp = udp, Sender = sender }); statsd.Send <Statsd.Counting>(msg, 1); statsd.Send <Statsd.Timing>(msg, 2); sender.Flush(); // Since our packet size limit is now 10, this (short) message should still be split AssertWasReceived(String.Format("{0}:1|c", msg), 0); AssertWasReceived(String.Format("{0}:2|ms", msg), 1); }
public void send_oversized_udp_packets_are_split_if_possible() { var msg = new String('f', MetricsConfig.DefaultStatsdMaxUDPPacketSize - 15); listenThread.Start(3); // Listen for 3 messages var sender = new BatchSender(); var statsd = new Statsd(new Statsd.Configuration() { Udp = udp, Sender = sender }); statsd.Send <Statsd.Counting>(msg, 1); statsd.Send <Statsd.Timing>(msg, 2); sender.Flush(); // These two metrics should be split as their combined lengths exceed the maximum packet size AssertWasReceived(String.Format("{0}:1|c", msg), 0); AssertWasReceived(String.Format("{0}:2|ms", msg), 1); // No extra metric should be sent at the end AssertWasReceived(null, 2); }
protected internal override void Process(RelationshipGroupRecord[] batch, BatchSender sender) { int groupStartIndex = 0; for (int i = 0; i < batch.Length; i++) { RelationshipGroupRecord group = batch[i]; // The iterator over the groups will not produce real next pointers, they are instead // a count meaning how many groups come after it. This encoder will set the real group ids. long count = group.Next; bool lastInChain = count == 0; group.Id = _nextId == -1 ? _nextId = _store.nextId() : _nextId; if (!lastInChain) { group.Next = _nextId = _store.nextId(); } else { group.Next = _nextId = -1; // OK so this group is the last in this chain, which means all the groups in this chain // are now fully populated. We can now prepare these groups so that their potential // secondary units ends up very close by. for (int j = groupStartIndex; j <= i; j++) { _store.prepareForCommit(batch[j]); } groupStartIndex = i + 1; } } Debug.Assert(groupStartIndex == batch.Length); sender.Send(batch); }
protected internal override void Process(object batch, BatchSender sender) { }
protected internal virtual void LastCallForEmittingOutstandingBatches(BatchSender sender) { // Nothing to emit, subclasses might have though }
protected internal override void Process(int?batch, BatchSender sender) { // No processing in this test NextExpected.incrementAndGet(); }
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#: //ORIGINAL LINE: protected void process(Void batch, BatchSender sender) throws Throwable protected internal override void Process(Void batch, BatchSender sender) { Latch.await(); }
protected internal override void Process(T batch, BatchSender sender) { _receivedBatches.Add(batch); }
/// <summary> /// Processes a <seealso cref="receive(long, object) received"/> batch. Any batch that should be sent downstream /// as part of processing the supplied batch should be done so using <seealso cref="BatchSender.send(object)"/>. /// /// The most typical implementation of this method is to process the received batch, either by /// creating a new batch object containing some derivative of the received batch, or the batch /// object itself with some modifications and <seealso cref="BatchSender.send(object) emit"/> that in the end of the method. /// </summary> /// <param name="batch"> batch to process. </param> /// <param name="sender"> <seealso cref="BatchSender"/> for sending zero or more batches downstream. </param> //JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#: //ORIGINAL LINE: protected abstract void process(T batch, BatchSender sender) throws Throwable; protected internal abstract void Process(T batch, BatchSender sender);
void ib_OnProcess(BatchSender sender, double process_stage) { this.SetImageSendPBValue((int)(process_stage * this.pbSendImage.Maximum)); }
protected internal override void Process(RelationshipGroupRecord[] batch, BatchSender sender) { long lastOwningNode = LastBatchLastOwningNode; foreach (RelationshipGroupRecord record in batch) { assertTrue(record.OwningNode >= lastOwningNode); assertTrue(record.OwningNode > LastBatchLastOwningNode); } ProcessCounter.incrementAndGet(); if (batch.Length > 0) { LastBatchLastOwningNode = batch[batch.Length - 1].OwningNode; } }
void ib_OnDone(BatchSender sender, DoneReason reason) { this.Log.PostHead("Emulator", "Stop sending image, reason: " + reason); this.ShowImageProgressBar(false); if (reason == DoneReason.Success) this.Messages.Sent("Image sent success"); else this.Messages.Sent("Cannot sent image: " + reason); }
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#: //ORIGINAL LINE: protected void process(System.Nullable<long> batch, BatchSender sender) throws Throwable protected internal override void process(long?batch, BatchSender sender) { Thread.Sleep(0, ThreadLocalRandom.current().Next(100_000)); sender.Send(batch); }