private void advance(TimeControl time, MockTimer timer, int timeMs) { Duration duration = Duration.fromMilliseconds(timeMs); time.advance(duration); timer.tick(); }
@Override public void apply(TimeControl time) { MockTimer timer = new MockTimer(); MovingAverageRateFactory factory = new MovingAverageRateFactory(timer); MovingAverageRate avg60 = factory.create(60); avg60.add(1000); assertEquals(0, avg60.get(), 0); advance(time, timer, 1); assertEquals(0, avg60.get(), 0); advance(time, timer, 1); assertEquals(0, avg60.get(), 0); } });
@Override public void apply(TimeControl time) { MockTimer timer = new MockTimer(); MovingAverageRateFactory factory = new MovingAverageRateFactory(timer); MovingAverageRate avg60 = factory.create(60); MovingAverageRate avg30 = factory.create(30); // Can't test this precisely because the Rate class uses its own // ticker. So we can control when it gets sampled but not the time // value it uses. So, just do basic validation. for (int i = 0; i < 30; i++) { avg60.add(100); avg30.add(100); advance(time, timer, 1000); } double s1 = avg60.get(); assertTrue(avg30.get() > 0); for (int i = 0; i < 30; i++) { advance(time, timer, 1000); } assertTrue(avg60.get() > 0); assertTrue(avg60.get() < s1); assertEquals(0.0, avg30.get(), 0); } });
@Test public void flushesIncompleteSpans() throws Exception { advanceAndRecord(0, root, new Annotation.Rpc("GET")); advanceAndRecord(15, root, new Annotation.ServiceName("frontend")); advanceAndRecord(0, root, Annotation.ServerRecv$.MODULE$); // Note: there's no ServerSend() which would complete the span. time.advance(recorder.ttl.plus(Duration.fromMilliseconds(1))); // advance timer timer.tick(); // invokes a flush Span span = spansSent.take(); assertThat(span.id()).isEqualTo(root.spanId().toString()); assertThat(span.name()).isEqualTo("get"); assertThat(span.kind()).isEqualTo(Span.Kind.SERVER); assertThat(span.annotations()).extracting(zipkin2.Annotation::value).containsExactly( "finagle.flush" ); assertThat(span.duration()).isNull(); }