kikocis/java-driver public
Changesets · Branches · Tags · Compare
| Changeset | 48deaab8061a22265068c54e88c71c8d36e077fbf7e143aa8629c923b10e0306 |
|---|---|
| Author | olim7t <omichallat+github@gmail.com> · 2015-08-09 22:30 +02:00 |
| Committer | olim7t <omichallat+github@gmail.com> · 2015-08-09 22:43 +02:00 |
| Parents | 8e68cdab6bd1 |
2 files changed
modified driver-core/src/test/java/com/datastax/driver/core/QueryOptionsTest.java +83 −2
| @@ -16,6 +16,8 @@ | ||
| 16 | 16 | package com.datastax.driver.core; |
| 17 | 17 | |
| 18 | 18 | import java.util.List; |
| 19 | +import java.util.concurrent.TimeUnit; | |
| 20 | + | |
| 19 | 21 | import com.google.common.collect.Lists; |
| 20 | 22 | import org.scassandra.http.client.PreparedStatementPreparation; |
| 21 | 23 | import org.testng.annotations.*; |
| @@ -25,7 +27,7 @@ | ||
| 25 | 27 | public class QueryOptionsTest { |
| 26 | 28 | SCassandraCluster scassandra; |
| 27 | 29 | |
| 28 | - QueryOptions queryOptions = new QueryOptions(); | |
| 30 | + QueryOptions queryOptions; | |
| 29 | 31 | |
| 30 | 32 | SortingLoadBalancingPolicy loadBalancingPolicy; |
| 31 | 33 | |
| @@ -41,6 +43,7 @@ | ||
| 41 | 43 | |
| 42 | 44 | @BeforeMethod(groups = "short") |
| 43 | 45 | public void beforeMethod() { |
| 46 | + queryOptions = new QueryOptions(); | |
| 44 | 47 | loadBalancingPolicy = new SortingLoadBalancingPolicy(); |
| 45 | 48 | cluster = Cluster.builder() |
| 46 | 49 | .addContactPoint(CCMBridge.ipOfNode(2)) |
| @@ -55,7 +58,7 @@ | ||
| 55 | 58 | host3 = TestUtils.findHost(cluster, 3); |
| 56 | 59 | |
| 57 | 60 | // Make sure there are no prepares |
| 58 | - for(int host : Lists.newArrayList(1, 2, 3)) { | |
| 61 | + for (int host : Lists.newArrayList(1, 2, 3)) { | |
| 59 | 62 | assertThat(scassandra.retrievePreparedStatementPreparations(host)).hasSize(0); |
| 60 | 63 | } |
| 61 | 64 | } |
| @@ -134,8 +137,86 @@ | ||
| 134 | 137 | validatePrepared(true); |
| 135 | 138 | } |
| 136 | 139 | |
| 140 | + private void valideReprepareOnUp(boolean expectReprepare) { | |
| 141 | + String query = "select sansa_stark from the_known_world"; | |
| 142 | + session.prepare(query); | |
| 143 | + | |
| 144 | + List<PreparedStatementPreparation> preparationOne = scassandra.retrievePreparedStatementPreparations(1); | |
| 145 | + | |
| 146 | + assertThat(preparationOne).hasSize(1); | |
| 147 | + assertThat(preparationOne.get(0).getPreparedStatementText()).isEqualTo(query); | |
| 148 | + | |
| 149 | + scassandra.clearAllRecordedActivity(); | |
| 150 | + scassandra.stop(1); | |
| 151 | + assertThat(cluster).host(1).goesDownWithin(10, TimeUnit.SECONDS); | |
| 152 | + | |
| 153 | + scassandra.start(1); | |
| 154 | + assertThat(cluster).host(1).comesUpWithin(60, TimeUnit.SECONDS); | |
| 155 | + | |
| 156 | + preparationOne = scassandra.retrievePreparedStatementPreparations(1); | |
| 157 | + if (expectReprepare) { | |
| 158 | + assertThat(preparationOne).hasSize(1); | |
| 159 | + assertThat(preparationOne.get(0).getPreparedStatementText()).isEqualTo(query); | |
| 160 | + } else { | |
| 161 | + assertThat(preparationOne).isEmpty(); | |
| 162 | + } | |
| 163 | + } | |
| 164 | + | |
| 165 | + /** | |
| 166 | + * <p> | |
| 167 | + * Validates that statements are reprepared when a node comes back up when | |
| 168 | + * {@link QueryOptions#setReprepareOnUp(boolean)} is set to true. | |
| 169 | + * </p> | |
| 170 | + * | |
| 171 | + * @test_category prepared_statements:prepared | |
| 172 | + * @expected_result reprepare query on the restarted node. | |
| 173 | + * @jira_ticket JAVA-658 | |
| 174 | + * @since 2.0.11, 2.1.8, 2.2.1 | |
| 175 | + */ | |
| 176 | + @Test(groups = "short") | |
| 177 | + public void should_reprepare_on_up_when_enabled() { | |
| 178 | + queryOptions.setReprepareOnUp(true); | |
| 179 | + valideReprepareOnUp(true); | |
| 180 | + } | |
| 181 | + | |
| 182 | + /** | |
| 183 | + * <p> | |
| 184 | + * Validates that statements are reprepared when a node comes back up with | |
| 185 | + * the default configuration. | |
| 186 | + * </p> | |
| 187 | + * | |
| 188 | + * @test_category prepared_statements:prepared | |
| 189 | + * @expected_result reprepare query on the restarted node. | |
| 190 | + * @jira_ticket JAVA-658 | |
| 191 | + * @since 2.0.11, 2.1.8, 2.2.1 | |
| 192 | + */ | |
| 193 | + @Test(groups = "short") | |
| 194 | + public void should_reprepare_on_up_by_default() { | |
| 195 | + valideReprepareOnUp(true); | |
| 196 | + } | |
| 197 | + | |
| 198 | + /** | |
| 199 | + * <p> | |
| 200 | + * Validates that statements are not reprepared when a node comes back up when | |
| 201 | + * {@link QueryOptions#setReprepareOnUp(boolean)} is set to false. | |
| 202 | + * </p> | |
| 203 | + * | |
| 204 | + * @test_category prepared_statements:prepared | |
| 205 | + * @expected_result do not reprepare query on the restarted node. | |
| 206 | + * @jira_ticket JAVA-658 | |
| 207 | + * @since 2.0.11, 2.1.8, 2.2.1 | |
| 208 | + */ | |
| 209 | + @Test(groups = "short") | |
| 210 | + public void should_not_reprepare_on_up_when_disabled() { | |
| 211 | + queryOptions.setReprepareOnUp(false); | |
| 212 | + valideReprepareOnUp(false); | |
| 213 | + } | |
| 214 | + | |
| 137 | 215 | @AfterMethod(groups = "short") |
| 138 | 216 | public void afterMethod() { |
| 217 | + if (cluster != null) | |
| 218 | + cluster.close(); | |
| 219 | + | |
| 139 | 220 | scassandra.clearAllPrimes(); |
| 140 | 221 | scassandra.clearAllRecordedActivity(); |
| 141 | 222 | } |
modified driver-core/src/test/java/com/datastax/driver/core/SCassandraCluster.java +10 −0
| @@ -85,6 +85,16 @@ | ||
| 85 | 85 | scassandra.stop(); |
| 86 | 86 | } |
| 87 | 87 | |
| 88 | + public void start(int node) { | |
| 89 | + int i = node - 1; | |
| 90 | + scassandras.get(i).start(); | |
| 91 | + primePeers(primingClients.get(i), scassandras.get(i)); | |
| 92 | + } | |
| 93 | + | |
| 94 | + public void stop(int node) { | |
| 95 | + scassandras.get(node - 1).stop(); | |
| 96 | + } | |
| 97 | + | |
| 88 | 98 | public SCassandraCluster prime(int node, PrimingRequest request) { |
| 89 | 99 | primingClients.get(node - 1).prime(request); |
| 90 | 100 | return this; |