Elffuss BraidHub

kikocis/java-driver public

Add test for JAVA-658.
Changeset48deaab8061a22265068c54e88c71c8d36e077fbf7e143aa8629c923b10e0306
Authorolim7t <omichallat+github@gmail.com> · 2015-08-09 22:30 +02:00
Committerolim7t <omichallat+github@gmail.com> · 2015-08-09 22:43 +02:00
Parents8e68cdab6bd1

Browse the files at this changeset

2 files changed

modified driver-core/src/test/java/com/datastax/driver/core/QueryOptionsTest.java +83 −2
@@ -16,6 +16,8 @@
1616 package com.datastax.driver.core;
1717
1818 import java.util.List;
19+import java.util.concurrent.TimeUnit;
20+
1921 import com.google.common.collect.Lists;
2022 import org.scassandra.http.client.PreparedStatementPreparation;
2123 import org.testng.annotations.*;
@@ -25,7 +27,7 @@
2527 public class QueryOptionsTest {
2628 SCassandraCluster scassandra;
2729
28- QueryOptions queryOptions = new QueryOptions();
30+ QueryOptions queryOptions;
2931
3032 SortingLoadBalancingPolicy loadBalancingPolicy;
3133
@@ -41,6 +43,7 @@
4143
4244 @BeforeMethod(groups = "short")
4345 public void beforeMethod() {
46+ queryOptions = new QueryOptions();
4447 loadBalancingPolicy = new SortingLoadBalancingPolicy();
4548 cluster = Cluster.builder()
4649 .addContactPoint(CCMBridge.ipOfNode(2))
@@ -55,7 +58,7 @@
5558 host3 = TestUtils.findHost(cluster, 3);
5659
5760 // Make sure there are no prepares
58- for(int host : Lists.newArrayList(1, 2, 3)) {
61+ for (int host : Lists.newArrayList(1, 2, 3)) {
5962 assertThat(scassandra.retrievePreparedStatementPreparations(host)).hasSize(0);
6063 }
6164 }
@@ -134,8 +137,86 @@
134137 validatePrepared(true);
135138 }
136139
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+
137215 @AfterMethod(groups = "short")
138216 public void afterMethod() {
217+ if (cluster != null)
218+ cluster.close();
219+
139220 scassandra.clearAllPrimes();
140221 scassandra.clearAllRecordedActivity();
141222 }
modified driver-core/src/test/java/com/datastax/driver/core/SCassandraCluster.java +10 −0
@@ -85,6 +85,16 @@
8585 scassandra.stop();
8686 }
8787
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+
8898 public SCassandraCluster prime(int node, PrimingRequest request) {
8999 primingClients.get(node - 1).prime(request);
90100 return this;