kikocis/java-driver public
Changesets · Branches · Tags · Compare
| Changeset | a01100bfa24bd3d87464c69e049e68cb9389773b124ed7e2ba13c93d6982f9a7 |
|---|---|
| Author | Andrew Tolbert <andrew.tolbert@datastax.com> · 2015-06-18 14:00 -05:00 |
| Committer | Andrew Tolbert <andrew.tolbert@datastax.com> · 2015-06-18 14:00 -05:00 |
| Parents | 8cda1ec45abb |
1 file changed
modified driver-core/src/test/java/com/datastax/driver/core/SpeculativeExecutionTest.java +34 −0
| @@ -18,6 +18,7 @@ | ||
| 18 | 18 | import java.util.*; |
| 19 | 19 | import java.util.concurrent.ConcurrentSkipListSet; |
| 20 | 20 | |
| 21 | +import com.datastax.driver.core.policies.SpeculativeExecutionPolicy; | |
| 21 | 22 | import com.google.common.collect.ImmutableList; |
| 22 | 23 | import com.google.common.collect.ImmutableMap; |
| 23 | 24 | import com.google.common.primitives.UnsignedBytes; |
| @@ -29,6 +30,9 @@ | ||
| 29 | 30 | import com.datastax.driver.core.policies.RetryPolicy; |
| 30 | 31 | |
| 31 | 32 | import static com.datastax.driver.core.Assertions.assertThat; |
| 33 | +import static org.mockito.Mockito.mock; | |
| 34 | +import static org.mockito.Mockito.times; | |
| 35 | +import static org.mockito.Mockito.verify; | |
| 32 | 36 | |
| 33 | 37 | public class SpeculativeExecutionTest { |
| 34 | 38 | SCassandraCluster scassandras; |
| @@ -171,6 +175,36 @@ | ||
| 171 | 175 | assertThat(rs.getExecutionInfo().getQueriedHost()).isEqualTo(host3); |
| 172 | 176 | } |
| 173 | 177 | |
| 178 | + /** | |
| 179 | + * Validates that when a Cluster is initialized that {@link SpeculativeExecutionPolicy#init(Cluster)} is called and | |
| 180 | + * that when a Cluster is closed {@link SpeculativeExecutionPolicy#close()} is called. | |
| 181 | + * | |
| 182 | + * @test_category queries:speculative_execution | |
| 183 | + * @expected_result init and close are called on cluster init and close. | |
| 184 | + * @jira_ticket JAVA-796 | |
| 185 | + * @since 2.0.11, 2.1.7, 2.2.1 | |
| 186 | + */ | |
| 187 | + @Test(groups="short") | |
| 188 | + public void should_init_and_close_policy_on_cluster() { | |
| 189 | + SpeculativeExecutionPolicy mockPolicy = mock(SpeculativeExecutionPolicy.class); | |
| 190 | + | |
| 191 | + Cluster cluster = Cluster.builder() | |
| 192 | + .addContactPoint(CCMBridge.ipOfNode(2)) | |
| 193 | + .withSpeculativeExecutionPolicy(mockPolicy) | |
| 194 | + .build(); | |
| 195 | + | |
| 196 | + verify(mockPolicy, times(0)).init(cluster); | |
| 197 | + verify(mockPolicy, times(0)).close(); | |
| 198 | + | |
| 199 | + try { | |
| 200 | + cluster.init(); | |
| 201 | + verify(mockPolicy, times(1)).init(cluster); | |
| 202 | + } finally { | |
| 203 | + cluster.close(); | |
| 204 | + verify(mockPolicy, times(1)).close(); | |
| 205 | + } | |
| 206 | + } | |
| 207 | + | |
| 174 | 208 | @AfterMethod(groups = "short") |
| 175 | 209 | public void afterMethod() { |
| 176 | 210 | scassandras.clearAllPrimes(); |