Skip to content

Commit 3f6b8c1

Browse files
fix(test): handle empty log (#12768)
1 parent 3a63d8a commit 3f6b8c1

File tree

1 file changed

+16
-13
lines changed

1 file changed

+16
-13
lines changed

metadata-io/src/test/java/com/linkedin/metadata/entity/EbeanEntityServiceOptimizationTest.java

+16-13
Original file line numberDiff line numberDiff line change
@@ -232,22 +232,25 @@ private void assertSQL(
232232

233233
try {
234234
entityService.ingestProposal(opContext, batch, false);
235-
List<String> txnLog =
235+
// First collect all SQL statements that start with "txn[]"
236+
List<String> allSqlStatements =
236237
LoggedSql.collect().stream()
237238
.filter(sql -> sql.startsWith("txn[]"))
238-
.collect(
239-
ArrayList::new,
240-
(ArrayList<String> list, String sql) -> {
241-
// fold into previous line
242-
if (sql.startsWith("txn[] -- ")) {
243-
String current = list.get(list.size() - 1);
244-
list.set(list.size() - 1, current + "\n" + sql);
245-
} else {
246-
list.add(sql);
247-
}
248-
},
249-
ArrayList::addAll);
239+
.collect(Collectors.toList());
250240

241+
// Then process them to fold comments into previous lines
242+
List<String> txnLog = new ArrayList<>();
243+
for (String sql : allSqlStatements) {
244+
if (sql.startsWith("txn[] -- ") && !txnLog.isEmpty()) {
245+
// Append this comment to the previous statement
246+
int lastIndex = txnLog.size() - 1;
247+
String current = txnLog.get(lastIndex);
248+
txnLog.set(lastIndex, current + "\n" + sql);
249+
} else {
250+
// Add as a new statement
251+
txnLog.add(sql);
252+
}
253+
}
251254
// Get the captured SQL statements
252255
Map<String, List<String>> statementMap =
253256
txnLog.stream()

0 commit comments

Comments
 (0)