Skip to content

Commit

Permalink
[test] fix flaky test for testBatchWriteGeneratorTag. (apache#3546)
Browse files Browse the repository at this point in the history
  • Loading branch information
LinMingQiang authored Jun 19, 2024
1 parent 61fae74 commit a0558f1
Showing 1 changed file with 12 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -70,19 +70,13 @@ public void testBatchWriteGeneratorTag() throws Exception {
SnapshotManager snapshotManager = table.newSnapshotReader().snapshotManager();
TagManager tagManager = table.tagManager();

// Generate tag name
String prefix = "batch-write-";
Instant instant =
Instant.ofEpochMilli(
Objects.requireNonNull(snapshotManager.latestSnapshot()).timeMillis());
LocalDateTime localDateTime = LocalDateTime.ofInstant(instant, ZoneId.systemDefault());
String tagName = prefix + localDateTime.format(DateTimeFormatter.ofPattern("yyyy-MM-dd"));

// No tag is generated before the finish method
assertThat(table.tagManager().tagCount()).isEqualTo(0);
committerOperator.finish();
// After the finish method, a tag is generated
assertThat(table.tagManager().tagCount()).isEqualTo(1);
// Get tagName from tagManager.
String tagName = tagManager.allTagNames().get(0);
// The tag is consistent with the latest snapshot
assertThat(tagManager.taggedSnapshot(tagName)).isEqualTo(snapshotManager.latestSnapshot());

Expand All @@ -98,7 +92,16 @@ public void testBatchWriteGeneratorTag() throws Exception {
// note that this tag has the same name with previous tag
// so the previous tag will be deleted
committerOperator.finish();

// If tagName does not exist, it happened across the day.
if (!tagManager.tagExists(tagName)) {
// Generate tag name
String prefix = "batch-write-";
Instant instant =
Instant.ofEpochMilli(
Objects.requireNonNull(snapshotManager.latestSnapshot()).timeMillis());
LocalDateTime localDateTime = LocalDateTime.ofInstant(instant, ZoneId.systemDefault());
tagName = prefix + localDateTime.format(DateTimeFormatter.ofPattern("yyyy-MM-dd"));
}
assertThat(tagManager.allTagNames()).containsOnly("many-tags-test2", tagName);
}

Expand Down

0 comments on commit a0558f1

Please sign in to comment.