kikocis/java-driver public
Changesets · Branches · Tags · Compare
| Changeset | b18f7041af0a8ef32a62e86a59aaf541a9c0266f1c8ceb74692480ec30047c36 |
|---|---|
| Author | Andrew Tolbert <andrew.tolbert@datastax.com> · 2015-06-26 15:25 -05:00 |
| Committer | Andrew Tolbert <andrew.tolbert@datastax.com> · 2015-06-26 16:33 -05:00 |
| Parents | 04dcb6147d7c |
1 file changed
modified driver-core/src/test/java/com/datastax/driver/core/TimeoutStressTest.java +13 −17
| @@ -68,8 +68,6 @@ | ||
| 68 | 68 | |
| 69 | 69 | static List<InetSocketAddress> nodes; |
| 70 | 70 | |
| 71 | - static PreparedStatement statement; | |
| 72 | - | |
| 73 | 71 | @BeforeClass(groups = "long") |
| 74 | 72 | public void beforeClass() throws Exception { |
| 75 | 73 | ccmBridge = CCMBridge.create("test", 3); |
| @@ -87,9 +85,6 @@ | ||
| 87 | 85 | .withPoolingOptions(poolingOptions) |
| 88 | 86 | .withNettyOptions(channelMonitor.nettyOptions()) |
| 89 | 87 | .build(); |
| 90 | - Session session = cluster.connect(); | |
| 91 | - setupSchema(session); | |
| 92 | - session.close(); | |
| 93 | 88 | } |
| 94 | 89 | |
| 95 | 90 | @AfterClass(groups = "long") |
| @@ -129,11 +124,17 @@ | ||
| 129 | 124 | * @since 2.0.10, 2.1.6 |
| 130 | 125 | */ |
| 131 | 126 | @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 | + | |
| 133 | 133 | // Set very low timeouts. |
| 134 | 134 | cluster.getConfiguration().getSocketOptions().setConnectTimeoutMillis(CONNECTION_TIMEOUT_IN_MS); |
| 135 | 135 | 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;"); | |
| 137 | 138 | |
| 138 | 139 | int workers = Runtime.getRuntime().availableProcessors(); |
| 139 | 140 | ExecutorService workerPool = Executors.newFixedThreadPool(workers, |
| @@ -148,7 +149,7 @@ | ||
| 148 | 149 | try { |
| 149 | 150 | Semaphore concurrentQueries = new Semaphore(CONCURRENT_QUERIES); |
| 150 | 151 | for (int i = 0; i < workers; i++) { |
| 151 | - workerPool.submit(new TimeoutStressWorker(session, concurrentQueries, stopped)); | |
| 152 | + workerPool.submit(new TimeoutStressWorker(session, statement, concurrentQueries, stopped)); | |
| 152 | 153 | } |
| 153 | 154 | |
| 154 | 155 | long startTime = System.currentTimeMillis(); |
| @@ -214,20 +215,13 @@ | ||
| 214 | 215 | + ");"); |
| 215 | 216 | |
| 216 | 217 | int records = 30000; |
| 217 | - List<ResultSetFuture> futures = Lists.newArrayListWithExpectedSize(records); | |
| 218 | - | |
| 219 | 218 | PreparedStatement insertStmt = session.prepare("insert into record (name, phone, value) values (?, ?, ?)"); |
| 220 | 219 | |
| 221 | 220 | for (int i = 0; i < records; i++) { |
| 222 | 221 | if (i % 1000 == 0) |
| 223 | 222 | 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")); | |
| 225 | 224 | } |
| 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); | |
| 231 | 225 | logger.debug("Inserts complete."); |
| 232 | 226 | } |
| 233 | 227 | |
| @@ -236,9 +230,11 @@ | ||
| 236 | 230 | private final Semaphore concurrentQueries; |
| 237 | 231 | private final AtomicBoolean stopped; |
| 238 | 232 | private final Session session; |
| 233 | + private final PreparedStatement statement; | |
| 239 | 234 | |
| 240 | - public TimeoutStressWorker(Session session, Semaphore concurrentQueries, AtomicBoolean stopped) { | |
| 235 | + public TimeoutStressWorker(Session session, PreparedStatement statement, Semaphore concurrentQueries, AtomicBoolean stopped) { | |
| 241 | 236 | this.session = session; |
| 237 | + this.statement = statement; | |
| 242 | 238 | this.concurrentQueries = concurrentQueries; |
| 243 | 239 | this.stopped = stopped; |
| 244 | 240 | } |