@Test
public void rotate() {

    final Set<Double> latencies = Collections.singleton(95D);
    SearchLatencyListener listener = newListener();
    long tookInNanos = 12345678;
    listener.onQueryPhase(mockSearchContext(Collections.singletonList("foo")), tookInNanos);
    assertEquals(1, listener.getLatencyStats(latencies).size());
    SearchLatencyProbe.LatencyStat stat = listener.getLatencyStats(latencies).get(0);
    assertNotNull(stat);
    assertEquals("foo", stat.getBucket());
    assertEquals(95D, stat.getPercentile(), Math.ulp(95D));
    // Without rotation this must still be 0
    assertEquals(0D, stat.getLatency().nanos(), Math.ulp(0D));
    listener.rotate();
    assertEquals(1, listener.getLatencyStats(latencies).size());
    stat = listener.getLatencyStats(latencies).get(0);
    assertNotNull(stat);
    assertEquals("foo", stat.getBucket());
    assertEquals(95D, stat.getPercentile(), Math.ulp(95D));
    assertEquals(tookInNanos, stat.getLatency().nanos(), delta(tookInNanos));
    listener.rotate();
    assertEquals(1, listener.getLatencyStats(latencies).size());
    stat = listener.getLatencyStats(latencies).get(0);
    assertNotNull(stat);
    assertEquals("foo", stat.getBucket());
    assertEquals(95D, stat.getPercentile(), Math.ulp(95D));
    // rotating without any data should not change the latency
    assertEquals(tookInNanos, stat.getLatency().nanos(), delta(tookInNanos));
}