Elffuss BraidHub

kikocis/java-driver public

Refactor TimeoutStressTest so it is more resilient.
Changesetb18f7041af0a8ef32a62e86a59aaf541a9c0266f1c8ceb74692480ec30047c36
AuthorAndrew Tolbert <andrew.tolbert@datastax.com> · 2015-06-26 15:25 -05:00
CommitterAndrew Tolbert <andrew.tolbert@datastax.com> · 2015-06-26 16:33 -05:00
Parents04dcb6147d7c

Browse the files at this changeset

1 file changed

modified driver-core/src/test/java/com/datastax/driver/core/TimeoutStressTest.java +13 −17
@@ -68,8 +68,6 @@
6868
6969 static List<InetSocketAddress> nodes;
7070
71- static PreparedStatement statement;
72-
7371 @BeforeClass(groups = "long")
7472 public void beforeClass() throws Exception {
7573 ccmBridge = CCMBridge.create("test", 3);
@@ -87,9 +85,6 @@
8785 .withPoolingOptions(poolingOptions)
8886 .withNettyOptions(channelMonitor.nettyOptions())
8987 .build();
90- Session session = cluster.connect();
91- setupSchema(session);
92- session.close();
9388 }
9489
9590 @AfterClass(groups = "long")
@@ -129,11 +124,17 @@
129124 * @since 2.0.10, 2.1.6
130125 */
131126 @Test(groups = "long")
132- public void host_state_should_be_maintained_with_timeouts() {
127+ public void host_state_should_be_maintained_with_timeouts() throws Exception {
128+ // Setup schema and insert records.
129+ Session session = cluster.connect();
130+ setupSchema(session);
131+ session.close();
132+
133133 // Set very low timeouts.
134134 cluster.getConfiguration().getSocketOptions().setConnectTimeoutMillis(CONNECTION_TIMEOUT_IN_MS);
135135 cluster.getConfiguration().getSocketOptions().setReadTimeoutMillis(READ_TIMEOUT_IN_MS);
136- Session session = cluster.connect();
136+ session = cluster.connect();
137+ PreparedStatement statement = session.prepare("select * from " + KEYSPACE + ".record where name=? limit 1000;");
137138
138139 int workers = Runtime.getRuntime().availableProcessors();
139140 ExecutorService workerPool = Executors.newFixedThreadPool(workers,
@@ -148,7 +149,7 @@
148149 try {
149150 Semaphore concurrentQueries = new Semaphore(CONCURRENT_QUERIES);
150151 for (int i = 0; i < workers; i++) {
151- workerPool.submit(new TimeoutStressWorker(session, concurrentQueries, stopped));
152+ workerPool.submit(new TimeoutStressWorker(session, statement, concurrentQueries, stopped));
152153 }
153154
154155 long startTime = System.currentTimeMillis();
@@ -214,20 +215,13 @@
214215 + ");");
215216
216217 int records = 30000;
217- List<ResultSetFuture> futures = Lists.newArrayListWithExpectedSize(records);
218-
219218 PreparedStatement insertStmt = session.prepare("insert into record (name, phone, value) values (?, ?, ?)");
220219
221220 for (int i = 0; i < records; i++) {
222221 if (i % 1000 == 0)
223222 logger.debug("Inserting record {}.", i);
224- futures.add(session.executeAsync(insertStmt.bind("0", Integer.toString(i), "test")));
223+ session.execute(insertStmt.bind("0", Integer.toString(i), "test"));
225224 }
226-
227- statement = session.prepare("select * from " + KEYSPACE + ".record where name=? limit 1000;");
228-
229- logger.debug("Completed inserting data. Waiting up to 30 for inserts to complete seconds before proceeding.");
230- Futures.allAsList(futures).get(30, TimeUnit.SECONDS);
231225 logger.debug("Inserts complete.");
232226 }
233227
@@ -236,9 +230,11 @@
236230 private final Semaphore concurrentQueries;
237231 private final AtomicBoolean stopped;
238232 private final Session session;
233+ private final PreparedStatement statement;
239234
240- public TimeoutStressWorker(Session session, Semaphore concurrentQueries, AtomicBoolean stopped) {
235+ public TimeoutStressWorker(Session session, PreparedStatement statement, Semaphore concurrentQueries, AtomicBoolean stopped) {
241236 this.session = session;
237+ this.statement = statement;
242238 this.concurrentQueries = concurrentQueries;
243239 this.stopped = stopped;
244240 }