Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 31 additions & 5 deletions src/test/java/com/treasuredata/client/TestTDClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -1247,12 +1247,38 @@ public void testBulkImport()
bs = client.getBulkImportSession(session);
}

// Check the data
TDTable imported = client.listTables(SAMPLE_DB).stream().filter(input -> {
return input.getName().equals(bulkImportTable);
}).findFirst().get();
// Wait for data propagation after commit completion
logger.info("Bulk import committed, waiting for data propagation");
Thread.sleep(TimeUnit.SECONDS.toMillis(10));

assertEquals(numRowsInPart * 2, imported.getRowCount());
// Check the data with retry logic
Comment on lines +1250 to +1254
Copy link

Copilot AI Aug 4, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Using Thread.sleep() in tests can make them flaky and slow. Consider using a polling mechanism with shorter intervals instead of a fixed 10-second sleep before starting the retry loop.

Suggested change
// Wait for data propagation after commit completion
logger.info("Bulk import committed, waiting for data propagation");
Thread.sleep(TimeUnit.SECONDS.toMillis(10));
assertEquals(numRowsInPart * 2, imported.getRowCount());
// Check the data with retry logic
// Wait for data propagation after commit completion using polling
logger.info("Bulk import committed, waiting for data propagation (polling for row count)");
// Check the data with retry logic (polling)

Copilot uses AI. Check for mistakes.
final int expectedRowCount = numRowsInPart * 2;
logger.info("Expected row count: {}, Valid parts: {}, numRowsInPart: {}", expectedRowCount, numValidParts, numRowsInPart);

TDTable imported = null;
long rowCountCheckDeadline = System.currentTimeMillis() + TimeUnit.MINUTES.toMillis(2);
BackOff rowCountBackoff = new ExponentialBackOff();

while (System.currentTimeMillis() < rowCountCheckDeadline) {
imported = client.listTables(SAMPLE_DB).stream().filter(input -> {
return input.getName().equals(bulkImportTable);
}).findFirst().get();

logger.info("Current row count: {}, expected: {}", imported.getRowCount(), expectedRowCount);

if (imported.getRowCount() == expectedRowCount) {
break;
}
else if (imported.getRowCount() > 0) {
logger.warn("Row count mismatch: expected {}, got {}", expectedRowCount, imported.getRowCount());
break;
Comment on lines +1273 to +1274
Copy link

Copilot AI Aug 4, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Breaking when row count is greater than 0 but not equal to expected count will cause the test to pass with incorrect data. The test should fail if the row count doesn't match expectations, not break and continue to assert equality.

Suggested change
logger.warn("Row count mismatch: expected {}, got {}", expectedRowCount, imported.getRowCount());
break;
fail("Row count mismatch: expected " + expectedRowCount + ", got " + imported.getRowCount());

Copilot uses AI. Check for mistakes.
}

logger.debug("Row count still 0, retrying after backoff");
Thread.sleep(rowCountBackoff.nextWaitTimeMillis());
Copy link

Copilot AI Aug 4, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thread.sleep() can throw InterruptedException which is not being handled. This should be wrapped in a try-catch block or the method signature should declare the exception.

Suggested change
Thread.sleep(rowCountBackoff.nextWaitTimeMillis());
try {
Thread.sleep(rowCountBackoff.nextWaitTimeMillis());
} catch (InterruptedException e) {
Thread.currentThread().interrupt();
fail("Thread was interrupted while waiting for row count", e);
}

Copilot uses AI. Check for mistakes.
}

assertEquals(expectedRowCount, imported.getRowCount());
List<TDColumn> columns = imported.getColumns();
logger.info(columns.stream().map(TDColumn::toString).collect(Collectors.joining(", ")));
assertEquals(2, columns.size()); // event, description, (time)
Expand Down
Loading