use of com.datastax.driver.core.exceptions.ReadTimeoutException in project java-driver by datastax.
the class PerHostPercentileTrackerTest method should_track_measurements_by_host.
@Test(groups = "unit")
public void should_track_measurements_by_host() {
// given - a per host percentile tracker.
Cluster cluster0 = mock(Cluster.class);
PerHostPercentileTracker tracker = builder().withInterval(1, TimeUnit.SECONDS).withMinRecordedValues(100).build();
tracker.onRegister(cluster0);
List<Host> hosts = Lists.newArrayList(mock(Host.class), mock(Host.class), mock(Host.class));
List<Statement> statements = Lists.newArrayList(mock(Statement.class), mock(Statement.class));
List<Exception> exceptions = Lists.newArrayList(new Exception(), null, new ReadTimeoutException(ConsistencyLevel.ANY, 1, 1, true), null, null);
// when - recording latencies over a linear progression with varying hosts, statements and exceptions.
for (int i = 0; i < 100; i++) {
tracker.update(hosts.get(0), statements.get(i % statements.size()), exceptions.get(i % exceptions.size()), TimeUnit.NANOSECONDS.convert(i + 1, TimeUnit.MILLISECONDS));
tracker.update(hosts.get(1), statements.get(i % statements.size()), exceptions.get(i % exceptions.size()), TimeUnit.NANOSECONDS.convert((i + 1) * 2, TimeUnit.MILLISECONDS));
tracker.update(hosts.get(2), statements.get(i % statements.size()), exceptions.get(i % exceptions.size()), TimeUnit.NANOSECONDS.convert((i + 1) * 3, TimeUnit.MILLISECONDS));
}
Uninterruptibles.sleepUninterruptibly(2000, TimeUnit.MILLISECONDS);
// host2: (x percentile == 3x)
for (int i = 1; i <= 99; i++) {
assertThat(tracker.getLatencyAtPercentile(hosts.get(0), null, null, i)).isEqualTo(i);
assertThat(tracker.getLatencyAtPercentile(hosts.get(1), null, null, i)).isEqualTo(i * 2);
assertThat(tracker.getLatencyAtPercentile(hosts.get(2), null, null, i)).isEqualTo(i * 3);
}
}
Aggregations