Skip to content

Commit ec7a107

Browse files
committed
add logging
1 parent d7165f2 commit ec7a107

File tree

1 file changed

+21
-4
lines changed

1 file changed

+21
-4
lines changed

integration-tests/src/test/java/com/datastax/oss/driver/core/cql/PreparedStatementCachingIT.java

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -123,9 +123,11 @@ private static RemovalListener<Object, Object> buildCacheRemoveCallback(
123123
@NonNull Optional<DefaultDriverContext> context) {
124124
return (evt) -> {
125125
try {
126+
LOG.info("Cache removal callback triggered, cause: {}", evt.getCause());
126127
CompletableFuture<PreparedStatement> future =
127128
(CompletableFuture<PreparedStatement>) evt.getValue();
128129
ByteBuffer queryId = Uninterruptibles.getUninterruptibly(future).getId();
130+
LOG.info("Firing PreparedStatementRemovalEvent for queryId: {}", queryId);
129131
context.ifPresent(
130132
ctx -> ctx.getEventBus().fire(new PreparedStatementRemovalEvent(queryId)));
131133
} catch (Exception e) {
@@ -224,10 +226,15 @@ private void invalidationTestInner(
224226
assertThat(getPreparedCacheSize(session)).isEqualTo(0);
225227
setupTestSchema.accept(session);
226228

227-
session.prepare(preparedStmtQueryType1);
228-
ByteBuffer queryId2 = session.prepare(preparedStmtQueryType2).getId();
229+
PreparedStatement stmt1 = session.prepare(preparedStmtQueryType1);
230+
PreparedStatement stmt2 = session.prepare(preparedStmtQueryType2);
231+
ByteBuffer queryId2 = stmt2.getId();
229232
assertThat(getPreparedCacheSize(session)).isEqualTo(2);
230233

234+
LOG.info("Prepared statements in cache:");
235+
LOG.info(" Statement 1: {} (queryId: {})", preparedStmtQueryType1, stmt1.getId());
236+
LOG.info(" Statement 2: {} (queryId: {})", preparedStmtQueryType2, stmt2.getId());
237+
231238
CountDownLatch preparedStmtCacheRemoveLatch = new CountDownLatch(1);
232239
CountDownLatch typeChangeEventLatch = new CountDownLatch(expectedChangedTypes.size());
233240

@@ -244,6 +251,8 @@ private void invalidationTestInner(
244251
TypeChangeEvent.class,
245252
(e) -> {
246253
// expect one event per type changed and for every parent type that nests it
254+
LOG.info("Received TypeChangeEvent for type: {} (changeType: {})",
255+
e.oldType.getName(), e.changeType);
247256
if (Boolean.TRUE.equals(
248257
changedTypes.putIfAbsent(e.oldType.getName().toString(), true))) {
249258
// store an error if we see duplicate change event
@@ -256,16 +265,20 @@ private void invalidationTestInner(
256265
.register(
257266
PreparedStatementRemovalEvent.class,
258267
(e) -> {
268+
LOG.info("Received PreparedStatementRemovalEvent for queryId: {}", e.queryId);
259269
if (!removedQueryIds.compareAndSet(Optional.empty(), Optional.of(e.queryId))) {
260270
// store an error if we see multiple cache invalidation events
261271
// any non-empty error will fail the test so it's OK to do this multiple times
262272
removedQueryEventError.set(
263273
Optional.of("Unable to set reference for PS removal event"));
274+
LOG.warn("Multiple PreparedStatementRemovalEvents received, ignoring subsequent ones");
264275
}
265276
preparedStmtCacheRemoveLatch.countDown();
266277
});
267278

268279
// alter test_type_caching_2 to trigger cache invalidation and above events
280+
LOG.info("Executing ALTER TYPE test_type_caching_2 add i blob");
281+
LOG.info("Expected to invalidate statement 2 (queryId: {}) due to type change", queryId2);
269282
session.execute("ALTER TYPE test_type_caching_2 add i blob");
270283

271284
// Give a small delay to allow the schema change to propagate before checking agreement
@@ -288,16 +301,20 @@ private void invalidationTestInner(
288301
+ " - Cache removal latch success: %s (count: %d)\n"
289302
+ " - Type change latch success: %s (count: %d)\n"
290303
+ " - Current cache size: %d\n"
291-
+ " - Changed types detected: %s\n"
292-
+ " - Removed query IDs: %s\n"
304+
+ " - Expected changed types: %s\n"
305+
+ " - Actual changed types detected: %s\n"
306+
+ " - Expected removed query ID: %s\n"
307+
+ " - Actual removed query IDs: %s\n"
293308
+ " - Type change errors: %s\n"
294309
+ " - Removal event errors: %s",
295310
cacheRemovalSuccess,
296311
preparedStmtCacheRemoveLatch.getCount(),
297312
typeChangeSuccess,
298313
typeChangeEventLatch.getCount(),
299314
getPreparedCacheSize(session),
315+
expectedChangedTypes,
300316
changedTypes.keySet(),
317+
queryId2,
301318
removedQueryIds.get(),
302319
typeChangeEventError.get(),
303320
removedQueryEventError.get());

0 commit comments

Comments
 (0)