Search in sources :

Example 6 with ReadTimeoutException

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);
    }
}
Also used : ReadTimeoutException(com.datastax.driver.core.exceptions.ReadTimeoutException) ReadTimeoutException(com.datastax.driver.core.exceptions.ReadTimeoutException) Test(org.testng.annotations.Test)

Aggregations

ReadTimeoutException (com.datastax.driver.core.exceptions.ReadTimeoutException)6 Test (org.testng.annotations.Test)3 InvalidQueryException (com.datastax.driver.core.exceptions.InvalidQueryException)2 NoHostAvailableException (com.datastax.driver.core.exceptions.NoHostAvailableException)2 InetSocketAddress (java.net.InetSocketAddress)2 HashMap (java.util.HashMap)2 ProcessException (org.apache.nifi.processor.exception.ProcessException)2 Test (org.junit.Test)2 BatchStatement (com.datastax.driver.core.BatchStatement)1 ConsistencyLevel (com.datastax.driver.core.ConsistencyLevel)1 ResultSet (com.datastax.driver.core.ResultSet)1 SimpleStatement (com.datastax.driver.core.SimpleStatement)1 Statement (com.datastax.driver.core.Statement)1 DriverException (com.datastax.driver.core.exceptions.DriverException)1 UnavailableException (com.datastax.driver.core.exceptions.UnavailableException)1