|
18 | 18 | package com.datastax.oss.driver.core.cql; |
19 | 19 |
|
20 | 20 | import static org.assertj.core.api.Assertions.assertThat; |
| 21 | +import static org.awaitility.Awaitility.await; |
21 | 22 |
|
22 | 23 | import com.codahale.metrics.Gauge; |
23 | 24 | import com.datastax.oss.driver.api.core.CqlSession; |
@@ -226,7 +227,6 @@ private void invalidationTestInner( |
226 | 227 | ByteBuffer queryId2 = session.prepare(preparedStmtQueryType2).getId(); |
227 | 228 | assertThat(getPreparedCacheSize(session)).isEqualTo(2); |
228 | 229 |
|
229 | | - CountDownLatch preparedStmtCacheRemoveLatch = new CountDownLatch(1); |
230 | 230 | CountDownLatch typeChangeEventLatch = new CountDownLatch(expectedChangedTypes.size()); |
231 | 231 |
|
232 | 232 | DefaultDriverContext ctx = (DefaultDriverContext) session.getContext(); |
@@ -260,23 +260,24 @@ private void invalidationTestInner( |
260 | 260 | removedQueryEventError.set( |
261 | 261 | Optional.of("Unable to set reference for PS removal event")); |
262 | 262 | } |
263 | | - preparedStmtCacheRemoveLatch.countDown(); |
264 | 263 | }); |
265 | 264 |
|
266 | 265 | // alter test_type_2 to trigger cache invalidation and above events |
267 | 266 | session.execute("ALTER TYPE test_type_2 add i blob"); |
268 | 267 |
|
269 | | - // wait for latches and fail if they don't reach zero before timeout |
| 268 | + // wait for schema propagation and prepared statement invalidation to settle |
270 | 269 | assertThat(Uninterruptibles.awaitUninterruptibly(typeChangeEventLatch, 60, TimeUnit.SECONDS)) |
271 | 270 | .withFailMessage("typeChangeEventLatch did not trigger before timeout") |
272 | 271 | .isTrue(); |
273 | | - assertThat( |
274 | | - Uninterruptibles.awaitUninterruptibly( |
275 | | - preparedStmtCacheRemoveLatch, 60, TimeUnit.SECONDS)) |
276 | | - .withFailMessage("preparedStmtCacheRemoveLatch did not trigger before timeout") |
277 | | - .isTrue(); |
| 272 | + await() |
| 273 | + .atMost(120, TimeUnit.SECONDS) |
| 274 | + .untilAsserted( |
| 275 | + () -> { |
| 276 | + assertThat(removedQueryIds.get()).isNotEmpty().get().isEqualTo(queryId2); |
| 277 | + assertThat(getPreparedCacheSize(session)).isEqualTo(1); |
| 278 | + }); |
278 | 279 |
|
279 | | - /* Okay, the latch triggered so cache processing should now be done. Let's validate :allthethings: */ |
| 280 | + /* Okay, the type change and cache invalidation events should now be done. */ |
280 | 281 | assertThat(changedTypes.keySet()).isEqualTo(expectedChangedTypes); |
281 | 282 | assertThat(removedQueryIds.get()).isNotEmpty().get().isEqualTo(queryId2); |
282 | 283 | assertThat(getPreparedCacheSize(session)).isEqualTo(1); |
|
0 commit comments