kikocis/java-driver public
Changesets · Branches · Tags · Compare
| Changeset | cc705dbd0878528bf7d1241c2eda492853b2d52de54dbf7295a45a6e7db0cfe3 |
|---|---|
| Author | Andrew Tolbert <andrew.tolbert@datastax.com> · 2016-03-01 16:29 -06:00 |
| Committer | olim7t <omichallat+github@gmail.com> · 2016-03-03 16:54 +01:00 |
| Parents | 65fa7c30289c |
1 file changed
modified driver-core/src/test/java/com/datastax/driver/core/QueryLoggerErrorsTest.java +53 −1
| @@ -16,6 +16,7 @@ | ||
| 16 | 16 | package com.datastax.driver.core; |
| 17 | 17 | |
| 18 | 18 | import com.datastax.driver.core.exceptions.*; |
| 19 | +import com.google.common.util.concurrent.Uninterruptibles; | |
| 19 | 20 | import org.apache.log4j.Level; |
| 20 | 21 | import org.apache.log4j.Logger; |
| 21 | 22 | import org.scassandra.http.client.PrimingRequest; |
| @@ -24,6 +25,8 @@ | ||
| 24 | 25 | import org.testng.annotations.DataProvider; |
| 25 | 26 | import org.testng.annotations.Test; |
| 26 | 27 | |
| 28 | +import java.util.concurrent.TimeUnit; | |
| 29 | + | |
| 27 | 30 | import static com.datastax.driver.core.QueryLogger.builder; |
| 28 | 31 | import static org.apache.log4j.Level.DEBUG; |
| 29 | 32 | import static org.apache.log4j.Level.INFO; |
| @@ -82,7 +85,7 @@ | ||
| 82 | 85 | } |
| 83 | 86 | |
| 84 | 87 | @Test(groups = "short") |
| 85 | - public void should_log_slow_queries() throws Exception { | |
| 88 | + public void should_log_queries_beyond_constant_threshold() throws Exception { | |
| 86 | 89 | // given |
| 87 | 90 | slow.setLevel(DEBUG); |
| 88 | 91 | queryLogger = builder(cluster) |
| @@ -106,6 +109,55 @@ | ||
| 106 | 109 | .contains(query); |
| 107 | 110 | } |
| 108 | 111 | |
| 112 | + @Test(groups = "short") | |
| 113 | + public void should_log_queries_beyond_dynamic_threshold() throws Exception { | |
| 114 | + // given | |
| 115 | + slow.setLevel(DEBUG); | |
| 116 | + queryLogger = builder(cluster) | |
| 117 | + .withDynamicThreshold(ClusterWidePercentileTracker.builder(1000) | |
| 118 | + .withMinRecordedValues(100) | |
| 119 | + .withInterval(1, TimeUnit.SECONDS).build(), 99) | |
| 120 | + .build(); | |
| 121 | + cluster.register(queryLogger); | |
| 122 | + | |
| 123 | + // prime a fast query to respond right away. | |
| 124 | + String fastQuery = "SELECT foo FROM bar"; | |
| 125 | + primingClient.prime( | |
| 126 | + queryBuilder() | |
| 127 | + .withQuery(fastQuery) | |
| 128 | + .build() | |
| 129 | + ); | |
| 130 | + | |
| 131 | + // prime a slow query to respond after 100ms. | |
| 132 | + String slowQuery = "SELECT bar from foo"; | |
| 133 | + primingClient.prime( | |
| 134 | + queryBuilder() | |
| 135 | + .withQuery(slowQuery) | |
| 136 | + .withThen(then().withFixedDelay(100L)) | |
| 137 | + .build() | |
| 138 | + ); | |
| 139 | + | |
| 140 | + // submit 100 fast queries to prime to the histogram. | |
| 141 | + long startTime = System.currentTimeMillis(); | |
| 142 | + for (int i = 0; i < 100; i++) { | |
| 143 | + session.execute(fastQuery); | |
| 144 | + } | |
| 145 | + | |
| 146 | + // Wait up to 1 second to allow initial histogram to be cached. | |
| 147 | + long waitTime = 1000 - (System.currentTimeMillis() - startTime); | |
| 148 | + Uninterruptibles.sleepUninterruptibly(waitTime, TimeUnit.MILLISECONDS); | |
| 149 | + | |
| 150 | + // when | |
| 151 | + session.execute(slowQuery); | |
| 152 | + // then | |
| 153 | + String line = slowAppender.waitAndGet(5000); | |
| 154 | + assertThat(line) | |
| 155 | + .contains("Query too slow") | |
| 156 | + .contains(ip) | |
| 157 | + .contains(slowQuery) | |
| 158 | + .doesNotContain(fastQuery); | |
| 159 | + } | |
| 160 | + | |
| 109 | 161 | @Test(groups = "short") |
| 110 | 162 | public void should_log_timed_out_queries() throws Exception { |
| 111 | 163 | // given |