kikocis/java-driver public
Changesets · Branches · Tags · Compare
| Changeset | 4a805f55f1287ceebb0bfed58bbf920a90a734e0903d6ffc24947427114eac4f |
|---|---|
| Author | Andrew Tolbert <andrew.tolbert@datastax.com> · 2016-06-29 16:34 -05:00 |
| Committer | olim7t <omichallat+github@gmail.com> · 2016-07-13 13:12 -07:00 |
| Parents | 16435aedc323 |
1 file changed
modified driver-core/src/test/java/com/datastax/driver/core/SpeculativeExecutionIntegrationTest.java +25 −12
| @@ -20,7 +20,7 @@ | ||
| 20 | 20 | import org.mockito.Mockito; |
| 21 | 21 | import org.testng.annotations.Test; |
| 22 | 22 | |
| 23 | -import static org.assertj.core.api.Assertions.assertThat; | |
| 23 | +import static org.assertj.core.api.Assertions.fail; | |
| 24 | 24 | import static org.mockito.Mockito.times; |
| 25 | 25 | |
| 26 | 26 | /** |
| @@ -41,8 +41,7 @@ | ||
| 41 | 41 | timestampGenerator = Mockito.spy(ServerSideTimestampGenerator.INSTANCE); |
| 42 | 42 | return Cluster.builder() |
| 43 | 43 | .withTimestampGenerator(timestampGenerator) |
| 44 | - .withQueryOptions(new QueryOptions().setDefaultIdempotence(true)) | |
| 45 | - // Set an artificially low timeout to force speculative execution | |
| 44 | + // Set an artificially low timeout to force speculative execution | |
| 46 | 45 | .withSpeculativeExecutionPolicy(new ConstantSpeculativeExecutionPolicy(1, 2)); |
| 47 | 46 | } |
| 48 | 47 | |
| @@ -58,16 +57,30 @@ | ||
| 58 | 57 | public void should_use_same_default_timestamp_for_all_executions() { |
| 59 | 58 | Metrics.Errors errors = cluster().getMetrics().getErrorMetrics(); |
| 60 | 59 | |
| 61 | - Mockito.reset(timestampGenerator); | |
| 62 | - long execStartCount = errors.getSpeculativeExecutions().getCount(); | |
| 63 | - | |
| 64 | - BatchStatement batch = new BatchStatement(); | |
| 65 | - for (int k = 0; k < 1000; k++) { | |
| 66 | - batch.add(new SimpleStatement("insert into foo(k,v) values (?,1)", k)); | |
| 60 | + // The check is attempted up to 10 times to account for the small possibility that a | |
| 61 | + // scheduled execution is not needed/exercised. Even though the policy is set up | |
| 62 | + // to schedule an execution after 1ms, the timeout might not fire before the response is received. | |
| 63 | + int tryCount = 0; | |
| 64 | + int maxTries = 10; | |
| 65 | + while (tryCount++ < maxTries) { | |
| 66 | + Mockito.reset(timestampGenerator); | |
| 67 | + long execStartCount = errors.getSpeculativeExecutions().getCount(); | |
| 68 | + | |
| 69 | + BatchStatement batch = new BatchStatement(); | |
| 70 | + for (int k = 0; k < 1000; k++) { | |
| 71 | + batch.add(new SimpleStatement("insert into foo(k,v) values (?,1)", k).setIdempotent(true)); | |
| 72 | + } | |
| 73 | + batch.setIdempotent(true); | |
| 74 | + session().execute(batch); | |
| 75 | + | |
| 76 | + if (errors.getSpeculativeExecutions().getCount() == execStartCount + 1) { | |
| 77 | + Mockito.verify(timestampGenerator, times(1)).next(); | |
| 78 | + break; | |
| 79 | + } | |
| 67 | 80 | } |
| 68 | - session().execute(batch); | |
| 69 | 81 | |
| 70 | - assertThat(errors.getSpeculativeExecutions().getCount()).isEqualTo(execStartCount + 1); | |
| 71 | - Mockito.verify(timestampGenerator, times(1)).next(); | |
| 82 | + if (tryCount == maxTries) { | |
| 83 | + fail("Observed no speculative executions in 10 attempts"); | |
| 84 | + } | |
| 72 | 85 | } |
| 73 | 86 | } |