Skip to content

Commit

Permalink
Use fuzzy matchers for compaction bytes asserts. (apache#16870)
Browse files Browse the repository at this point in the history
* Use fuzzy matchers for compaction bytes asserts.

This still enables us to test that the bytes are zero and nonzero
when they're supposed to be, without having to ge them exactly
right. The need to get bytes exactly right makes it difficult to
ensure ITs pass when making changes to default segment metadata.

* Additional fuzziness.
  • Loading branch information
gianm authored Aug 12, 2024
1 parent 4ef4e75 commit efe0044
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 19 deletions.
10 changes: 10 additions & 0 deletions integration-tests/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -430,6 +430,16 @@
<artifactId>avatica-core</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.hamcrest</groupId>
<artifactId>hamcrest-all</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.hamcrest</groupId>
<artifactId>hamcrest-core</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.testng</groupId>
<artifactId>testng</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,9 @@
import org.apache.druid.tests.indexer.AbstractITBatchIndexTest;
import org.apache.druid.tests.indexer.AbstractIndexerTest;
import org.apache.druid.timeline.DataSegment;
import org.hamcrest.Matcher;
import org.hamcrest.MatcherAssert;
import org.hamcrest.Matchers;
import org.joda.time.DateTimeZone;
import org.joda.time.Interval;
import org.joda.time.Period;
Expand Down Expand Up @@ -532,9 +535,9 @@ public void testAutoCompactionDutySubmitAndVerifyCompaction() throws Exception
getAndAssertCompactionStatus(
fullDatasourceName,
AutoCompactionSnapshot.AutoCompactionScheduleStatus.RUNNING,
0,
14166,
14165,
Matchers.equalTo(0L),
Matchers.greaterThan(0L),
Matchers.greaterThan(0L),
0,
2,
2,
Expand All @@ -550,9 +553,9 @@ public void testAutoCompactionDutySubmitAndVerifyCompaction() throws Exception
getAndAssertCompactionStatus(
fullDatasourceName,
AutoCompactionSnapshot.AutoCompactionScheduleStatus.RUNNING,
0,
22262,
0,
Matchers.equalTo(0L),
Matchers.greaterThan(0L),
Matchers.equalTo(0L),
0,
3,
0,
Expand Down Expand Up @@ -670,16 +673,19 @@ public void testAutoCompactionDutyCanUpdateTaskSlots() throws Exception
getAndAssertCompactionStatus(
fullDatasourceName,
AutoCompactionSnapshot.AutoCompactionScheduleStatus.RUNNING,
14166,
14165,
0,
Matchers.greaterThan(0L),
Matchers.greaterThan(0L),
Matchers.equalTo(0L),
2,
2,
0,
1,
1,
0);
Assert.assertEquals(compactionResource.getCompactionProgress(fullDatasourceName).get("remainingSegmentSize"), "14166");
MatcherAssert.assertThat(
Long.parseLong(compactionResource.getCompactionProgress(fullDatasourceName).get("remainingSegmentSize")),
Matchers.greaterThan(0L)
);
// Run compaction again to compact the remaining day
// Remaining day compacted (1 new segment). Now both days compacted (2 total)
forceTriggerAutoCompaction(2);
Expand All @@ -689,9 +695,9 @@ public void testAutoCompactionDutyCanUpdateTaskSlots() throws Exception
getAndAssertCompactionStatus(
fullDatasourceName,
AutoCompactionSnapshot.AutoCompactionScheduleStatus.RUNNING,
0,
22262,
0,
Matchers.equalTo(0L),
Matchers.greaterThan(0L),
Matchers.equalTo(0L),
0,
3,
0,
Expand Down Expand Up @@ -1952,9 +1958,9 @@ private void updateCompactionTaskSlot(double compactionTaskSlotRatio, int maxCom
private void getAndAssertCompactionStatus(
String fullDatasourceName,
AutoCompactionSnapshot.AutoCompactionScheduleStatus scheduleStatus,
long bytesAwaitingCompaction,
long bytesCompacted,
long bytesSkipped,
Matcher<Long> bytesAwaitingCompactionMatcher,
Matcher<Long> bytesCompactedMatcher,
Matcher<Long> bytesSkippedMatcher,
long segmentCountAwaitingCompaction,
long segmentCountCompacted,
long segmentCountSkipped,
Expand All @@ -1966,9 +1972,9 @@ private void getAndAssertCompactionStatus(
Map<String, String> actualStatus = compactionResource.getCompactionStatus(fullDatasourceName);
Assert.assertNotNull(actualStatus);
Assert.assertEquals(actualStatus.get("scheduleStatus"), scheduleStatus.toString());
Assert.assertEquals(Long.parseLong(actualStatus.get("bytesAwaitingCompaction")), bytesAwaitingCompaction);
Assert.assertEquals(Long.parseLong(actualStatus.get("bytesCompacted")), bytesCompacted);
Assert.assertEquals(Long.parseLong(actualStatus.get("bytesSkipped")), bytesSkipped);
MatcherAssert.assertThat(Long.parseLong(actualStatus.get("bytesAwaitingCompaction")), bytesAwaitingCompactionMatcher);
MatcherAssert.assertThat(Long.parseLong(actualStatus.get("bytesCompacted")), bytesCompactedMatcher);
MatcherAssert.assertThat(Long.parseLong(actualStatus.get("bytesSkipped")), bytesSkippedMatcher);
Assert.assertEquals(Long.parseLong(actualStatus.get("segmentCountAwaitingCompaction")), segmentCountAwaitingCompaction);
Assert.assertEquals(Long.parseLong(actualStatus.get("segmentCountCompacted")), segmentCountCompacted);
Assert.assertEquals(Long.parseLong(actualStatus.get("segmentCountSkipped")), segmentCountSkipped);
Expand Down

0 comments on commit efe0044

Please sign in to comment.