Skip to content

Commit c39a182

Browse files
Add back test removed in fef62b5 after clearer testing.
1 parent ae73bcb commit c39a182

2 files changed

Lines changed: 106 additions & 92 deletions

File tree

driver-core/src/test/java/com/datastax/driver/core/AbstractPoliciesTest.java

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -120,18 +120,33 @@ protected void failDebug(String message) {
120120
* Init methods that handle writes using batch and consistency options.
121121
*/
122122
protected void init(CCMBridge.CCMCluster c, int n) {
123-
init(c, n, false, ConsistencyLevel.ONE);
123+
write(c, n, false, ConsistencyLevel.ONE);
124+
prepared = c.session.prepare("SELECT * FROM " + SIMPLE_TABLE + " WHERE k = ?").setConsistencyLevel(ConsistencyLevel.ONE);
124125
}
125126

126127
protected void init(CCMBridge.CCMCluster c, int n, boolean batch) {
127-
init(c, n, batch, ConsistencyLevel.ONE);
128+
write(c, n, batch, ConsistencyLevel.ONE);
129+
prepared = c.session.prepare("SELECT * FROM " + SIMPLE_TABLE + " WHERE k = ?").setConsistencyLevel(ConsistencyLevel.ONE);
128130
}
129131

130132
protected void init(CCMBridge.CCMCluster c, int n, ConsistencyLevel cl) {
131-
init(c, n, false, cl);
133+
write(c, n, false, cl);
134+
prepared = c.session.prepare("SELECT * FROM " + SIMPLE_TABLE + " WHERE k = ?").setConsistencyLevel(cl);
135+
}
136+
137+
protected void write(CCMBridge.CCMCluster c, int n) {
138+
write(c, n, false, ConsistencyLevel.ONE);
139+
}
140+
141+
protected void write(CCMBridge.CCMCluster c, int n, boolean batch) {
142+
write(c, n, batch, ConsistencyLevel.ONE);
132143
}
133144

134-
protected void init(CCMBridge.CCMCluster c, int n, boolean batch, ConsistencyLevel cl) {
145+
protected void write(CCMBridge.CCMCluster c, int n, ConsistencyLevel cl) {
146+
write(c, n, false, cl);
147+
}
148+
149+
protected void write(CCMBridge.CCMCluster c, int n, boolean batch, ConsistencyLevel cl) {
135150
// We don't use insert for our test because the resultSet don't ship the queriedHost
136151
// Also note that we don't use tracing because this would trigger requests that screw up the test
137152
for (int i = 0; i < n; ++i)
@@ -142,8 +157,6 @@ protected void init(CCMBridge.CCMCluster c, int n, boolean batch, ConsistencyLev
142157
.setConsistencyLevel(cl));
143158
else
144159
c.session.execute(new SimpleStatement(String.format("INSERT INTO %s(k, i) VALUES (0, 0)", SIMPLE_TABLE)).setConsistencyLevel(cl));
145-
146-
prepared = c.session.prepare("SELECT * FROM " + SIMPLE_TABLE + " WHERE k = ?").setConsistencyLevel(cl);
147160
}
148161

149162

driver-core/src/test/java/com/datastax/driver/core/RetryPolicyTest.java

Lines changed: 87 additions & 86 deletions
Original file line numberDiff line numberDiff line change
@@ -158,92 +158,93 @@ public void defaultPolicyTest(Cluster.Builder builder) throws Throwable {
158158

159159
resetCoordinators();
160160

161-
// Remove running code that still does have proper tests setup
162-
// TODO: Change testing format to ensure that nodes were written to
163-
//// Test writes
164-
//successfulQuery = false;
165-
//boolean writeTimeoutOnce = false;
166-
//unavailableOnce = false;
167-
//restartOnce = false;
168-
//for (int i = 0; i < 100; ++i) {
169-
// try {
170-
// // Force a WriteTimeoutException to be performed once
171-
// if (!writeTimeoutOnce) {
172-
// c.cassandraCluster.forceStop(2);
173-
// }
174-
//
175-
// // Force an UnavailableException to be performed once
176-
// if (writeTimeoutOnce && !unavailableOnce) {
177-
// waitForDownWithWait(CCMBridge.IP_PREFIX + "2", c.cluster, 5);
178-
// }
179-
//
180-
// // Bring back node to ensure other errors are not thrown on restart
181-
// if (unavailableOnce && !restartOnce) {
182-
// c.cassandraCluster.start(2);
183-
// restartOnce = true;
184-
// }
185-
//
186-
// init(c, 12);
187-
//
188-
// if (restartOnce)
189-
// successfulQuery = true;
190-
// } catch (UnavailableException e) {
191-
// assertEquals("Not enough replica available for query at consistency ONE (1 required but only 0 alive)", e.getMessage());
192-
// unavailableOnce = true;
193-
// } catch (WriteTimeoutException e) {
194-
// assertEquals("Cassandra timeout during write query at consistency ONE (1 replica were required but only 0 acknowledged the write)", e.getMessage());
195-
// writeTimeoutOnce = true;
196-
// }
197-
//}
198-
//// Ensure the full cycle was completed
199-
//assertTrue(successfulQuery, "Hit testing race condition. [Never completed successfully.] (Shouldn't be an issue.):\n");
200-
//assertTrue(writeTimeoutOnce, "Hit testing race condition. [Never encountered a ReadTimeoutException.] (Shouldn't be an issue.):\n");
201-
//assertTrue(unavailableOnce, "Hit testing race condition. [Never encountered an UnavailableException.] (Shouldn't be an issue.):\n");
202-
//
203-
//// TODO: Missing test to see if nodes were written to
204-
//
205-
//
206-
//// Test batch writes
207-
//successfulQuery = false;
208-
//writeTimeoutOnce = false;
209-
//unavailableOnce = false;
210-
//restartOnce = false;
211-
//for (int i = 0; i < 100; ++i) {
212-
// try {
213-
// // Force a WriteTimeoutException to be performed once
214-
// if (!writeTimeoutOnce) {
215-
// c.cassandraCluster.forceStop(2);
216-
// }
217-
//
218-
// // Force an UnavailableException to be performed once
219-
// if (writeTimeoutOnce && !unavailableOnce) {
220-
// waitForDownWithWait(CCMBridge.IP_PREFIX + "2", c.cluster, 5);
221-
// }
222-
//
223-
// // Bring back node to ensure other errors are not thrown on restart
224-
// if (unavailableOnce && !restartOnce) {
225-
// c.cassandraCluster.start(2);
226-
// restartOnce = true;
227-
// }
228-
//
229-
// init(c, 12, true);
230-
//
231-
// if (restartOnce)
232-
// successfulQuery = true;
233-
// } catch (UnavailableException e) {
234-
// assertEquals("Not enough replica available for query at consistency ONE (1 required but only 0 alive)", e.getMessage());
235-
// unavailableOnce = true;
236-
// } catch (WriteTimeoutException e) {
237-
// assertEquals("Cassandra timeout during write query at consistency ONE (1 replica were required but only 0 acknowledged the write)", e.getMessage());
238-
// writeTimeoutOnce = true;
239-
// }
240-
//}
241-
//// Ensure the full cycle was completed
242-
//assertTrue(successfulQuery, "Hit testing race condition. [Never completed successfully.] (Shouldn't be an issue.):\n");
243-
//assertTrue(writeTimeoutOnce, "Hit testing race condition. [Never encountered a ReadTimeoutException.] (Shouldn't be an issue.):\n");
244-
//assertTrue(unavailableOnce, "Hit testing race condition. [Never encountered an UnavailableException.] (Shouldn't be an issue.):\n");
245-
//
246-
//// TODO: Missing test to see if nodes were written to
161+
162+
// Test writes
163+
successfulQuery = false;
164+
boolean writeTimeoutOnce = false;
165+
unavailableOnce = false;
166+
restartOnce = false;
167+
for (int i = 0; i < 100; ++i) {
168+
try {
169+
// Force a WriteTimeoutException to be performed once
170+
if (!writeTimeoutOnce) {
171+
c.cassandraCluster.forceStop(2);
172+
}
173+
174+
// Force an UnavailableException to be performed once
175+
if (writeTimeoutOnce && !unavailableOnce) {
176+
waitForDownWithWait(CCMBridge.IP_PREFIX + "2", c.cluster, 5);
177+
}
178+
179+
// Bring back node to ensure other errors are not thrown on restart
180+
if (unavailableOnce && !restartOnce) {
181+
c.cassandraCluster.start(2);
182+
waitFor(CCMBridge.IP_PREFIX + "2", c.cluster);
183+
restartOnce = true;
184+
}
185+
186+
write(c, 12);
187+
188+
if (restartOnce)
189+
successfulQuery = true;
190+
} catch (UnavailableException e) {
191+
assertEquals("Not enough replica available for query at consistency ONE (1 required but only 0 alive)", e.getMessage());
192+
unavailableOnce = true;
193+
} catch (WriteTimeoutException e) {
194+
assertEquals("Cassandra timeout during write query at consistency ONE (1 replica were required but only 0 acknowledged the write)", e.getMessage());
195+
writeTimeoutOnce = true;
196+
}
197+
}
198+
// Ensure the full cycle was completed
199+
assertTrue(successfulQuery, "Hit testing race condition. [Never completed successfully.] (Shouldn't be an issue.):\n");
200+
assertTrue(writeTimeoutOnce, "Hit testing race condition. [Never encountered a ReadTimeoutException.] (Shouldn't be an issue.):\n");
201+
assertTrue(unavailableOnce, "Hit testing race condition. [Never encountered an UnavailableException.] (Shouldn't be an issue.):\n");
202+
203+
// TODO: Missing test to see if nodes were written to
204+
205+
206+
// Test batch writes
207+
successfulQuery = false;
208+
writeTimeoutOnce = false;
209+
unavailableOnce = false;
210+
restartOnce = false;
211+
for (int i = 0; i < 100; ++i) {
212+
try {
213+
// Force a WriteTimeoutException to be performed once
214+
if (!writeTimeoutOnce) {
215+
c.cassandraCluster.forceStop(2);
216+
}
217+
218+
// Force an UnavailableException to be performed once
219+
if (writeTimeoutOnce && !unavailableOnce) {
220+
waitForDownWithWait(CCMBridge.IP_PREFIX + "2", c.cluster, 5);
221+
}
222+
223+
// Bring back node to ensure other errors are not thrown on restart
224+
if (unavailableOnce && !restartOnce) {
225+
c.cassandraCluster.start(2);
226+
waitFor(CCMBridge.IP_PREFIX + "2", c.cluster);
227+
restartOnce = true;
228+
}
229+
230+
write(c, 12, true);
231+
232+
if (restartOnce)
233+
successfulQuery = true;
234+
} catch (UnavailableException e) {
235+
assertEquals("Not enough replica available for query at consistency ONE (1 required but only 0 alive)", e.getMessage());
236+
unavailableOnce = true;
237+
} catch (WriteTimeoutException e) {
238+
assertEquals("Cassandra timeout during write query at consistency ONE (1 replica were required but only 0 acknowledged the write)", e.getMessage());
239+
writeTimeoutOnce = true;
240+
}
241+
}
242+
// Ensure the full cycle was completed
243+
assertTrue(successfulQuery, "Hit testing race condition. [Never completed successfully.] (Shouldn't be an issue.):\n");
244+
assertTrue(writeTimeoutOnce, "Hit testing race condition. [Never encountered a ReadTimeoutException.] (Shouldn't be an issue.):\n");
245+
assertTrue(unavailableOnce, "Hit testing race condition. [Never encountered an UnavailableException.] (Shouldn't be an issue.):\n");
246+
247+
// TODO: Missing test to see if nodes were written to
247248

248249
} catch (Throwable e) {
249250
c.errorOut();

0 commit comments

Comments
 (0)