diff --git a/java/system-test/system-test-suite/src/test/java/sleeper/systemtest/suite/CompactionOnEC2ST.java b/java/system-test/system-test-suite/src/test/java/sleeper/systemtest/suite/CompactionOnEC2ST.java index 0783993099..e0e0e1e4f7 100644 --- a/java/system-test/system-test-suite/src/test/java/sleeper/systemtest/suite/CompactionOnEC2ST.java +++ b/java/system-test/system-test-suite/src/test/java/sleeper/systemtest/suite/CompactionOnEC2ST.java @@ -16,7 +16,6 @@ package sleeper.systemtest.suite; -import org.approvaltests.Approvals; import org.junit.jupiter.api.AfterEach; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; @@ -39,6 +38,7 @@ import static sleeper.configuration.properties.table.TableProperty.COMPACTION_FILES_BATCH_SIZE; import static sleeper.core.testutils.printers.FileReferencePrinter.printFiles; import static sleeper.systemtest.suite.fixtures.SystemTestInstance.COMPACTION_ON_EC2; +import static sleeper.systemtest.suite.testutil.TestResources.exampleString; @SystemTest @Slow @@ -78,6 +78,7 @@ void shouldCompactFilesUsingDefaultCompactionStrategy(SleeperSystemTest sleeper) // Then assertThat(sleeper.directQuery().allRecordsInTable()) .containsExactlyInAnyOrderElementsOf(sleeper.generateNumberedRecords(LongStream.range(0, 46))); - Approvals.verify(printFiles(sleeper.partitioning().tree(), sleeper.tableFiles().all())); + assertThat(printFiles(sleeper.partitioning().tree(), sleeper.tableFiles().all())) + .isEqualTo(exampleString("compaction/compacted5ToSingleFile.txt")); } } diff --git a/java/system-test/system-test-suite/src/test/java/sleeper/systemtest/suite/CompactionST.java b/java/system-test/system-test-suite/src/test/java/sleeper/systemtest/suite/CompactionST.java index af99daa718..73badd8aad 100644 --- a/java/system-test/system-test-suite/src/test/java/sleeper/systemtest/suite/CompactionST.java +++ b/java/system-test/system-test-suite/src/test/java/sleeper/systemtest/suite/CompactionST.java @@ -16,7 +16,6 @@ package sleeper.systemtest.suite; -import org.approvaltests.Approvals; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.Nested; @@ -51,6 +50,7 @@ import static sleeper.systemtest.suite.fixtures.SystemTestInstance.MAIN; import static sleeper.systemtest.suite.fixtures.SystemTestSchema.DEFAULT_SCHEMA; import static sleeper.systemtest.suite.fixtures.SystemTestSchema.ROW_KEY_FIELD_NAME; +import static sleeper.systemtest.suite.testutil.TestResources.exampleString; @SystemTest public class CompactionST { @@ -88,7 +88,8 @@ void shouldCompactFilesUsingDefaultCompactionStrategy(SleeperSystemTest sleeper) // Then assertThat(sleeper.directQuery().allRecordsInTable()) .containsExactlyInAnyOrderElementsOf(sleeper.generateNumberedRecords(LongStream.range(0, 46))); - Approvals.verify(printFiles(sleeper.partitioning().tree(), sleeper.tableFiles().all())); + assertThat(printFiles(sleeper.partitioning().tree(), sleeper.tableFiles().all())) + .isEqualTo(exampleString("compaction/compacted5ToSingleFile.txt")); } @Test @@ -110,7 +111,8 @@ void shouldCompactFilesUsingBasicCompactionStrategy(SleeperSystemTest sleeper) { // Then assertThat(sleeper.directQuery().allRecordsInTable()) .containsExactlyInAnyOrderElementsOf(sleeper.generateNumberedRecords(LongStream.range(0, 100))); - Approvals.verify(printFiles(sleeper.partitioning().tree(), sleeper.tableFiles().all())); + assertThat(printFiles(sleeper.partitioning().tree(), sleeper.tableFiles().all())) + .isEqualTo(exampleString("compaction/compacted4To2Files.txt")); } } @@ -155,7 +157,8 @@ void shouldCompactOneFileIntoExistingFilesOnLeafPartitions(SleeperSystemTest sle // Then the same records should be present, in one file on each leaf partition assertThat(sleeper.directQuery().allRecordsInTable()) .containsExactlyInAnyOrderElementsOf(sleeper.generateNumberedRecords(LongStream.range(0, 100))); - Approvals.verify(printFiles(sleeper.partitioning().tree(), sleeper.tableFiles().all())); + assertThat(printFiles(sleeper.partitioning().tree(), sleeper.tableFiles().all())) + .isEqualTo(exampleString("compaction/compactedFileIntoLeafPartitions.txt")); } @Test @@ -181,7 +184,8 @@ void shouldCompactOneFileFromRootIntoExistingFilesOnLeafPartitions(SleeperSystem // Then the same records should be present, in one file on each leaf partition assertThat(sleeper.directQuery().allRecordsInTable()) .containsExactlyInAnyOrderElementsOf(sleeper.generateNumberedRecords(LongStream.range(0, 100))); - Approvals.verify(printFiles(sleeper.partitioning().tree(), sleeper.tableFiles().all())); + assertThat(printFiles(sleeper.partitioning().tree(), sleeper.tableFiles().all())) + .isEqualTo(exampleString("compaction/compactedFileIntoLeafPartitions.txt")); } } @@ -213,7 +217,8 @@ void shouldCompactFilesInSinglePartition(SleeperSystemTest sleeper) { // Then assertThat(sleeper.directQuery().allRecordsInTable()) .containsExactlyInAnyOrderElementsOf(sleeper.generateNumberedRecords(LongStream.range(0, 100))); - Approvals.verify(printFiles(sleeper.partitioning().tree(), sleeper.tableFiles().all())); + assertThat(printFiles(sleeper.partitioning().tree(), sleeper.tableFiles().all())) + .isEqualTo(exampleString("compaction/compacted4To2Files.txt")); } @Test @@ -241,7 +246,8 @@ void shouldCompactFilesFromMultiplePartitions(SleeperSystemTest sleeper) throws // Then assertThat(sleeper.directQuery().allRecordsInTable()) .containsExactlyInAnyOrderElementsOf(sleeper.generateNumberedRecords(LongStream.range(0, 100))); - Approvals.verify(printFiles(sleeper.partitioning().tree(), sleeper.tableFiles().all())); + assertThat(printFiles(sleeper.partitioning().tree(), sleeper.tableFiles().all())) + .isEqualTo(exampleString("compaction/compactedFileIntoLeafPartitions.txt")); } } } diff --git a/java/system-test/system-test-suite/src/test/java/sleeper/systemtest/suite/approvals/CompactionOnEC2ST.MergePartialFiles.shouldCompactOneFileIntoExistingFilesOnLeafPartitions.approved.txt b/java/system-test/system-test-suite/src/test/java/sleeper/systemtest/suite/approvals/CompactionOnEC2ST.MergePartialFiles.shouldCompactOneFileIntoExistingFilesOnLeafPartitions.approved.txt deleted file mode 100644 index 07c7ba6c84..0000000000 --- a/java/system-test/system-test-suite/src/test/java/sleeper/systemtest/suite/approvals/CompactionOnEC2ST.MergePartialFiles.shouldCompactOneFileIntoExistingFilesOnLeafPartitions.approved.txt +++ /dev/null @@ -1,7 +0,0 @@ -Unreferenced files: 5 -Referenced files: 4 -File references: 4 -Partition at LL: 25 records in file 1 -Partition at LR: 25 records in file 2 -Partition at RL: 25 records in file 3 -Partition at RR: 25 records in file 4 diff --git a/java/system-test/system-test-suite/src/test/java/sleeper/systemtest/suite/approvals/CompactionOnFargateST.MergeFiles.shouldCompactFilesUsingBasicCompactionStrategy.approved.txt b/java/system-test/system-test-suite/src/test/java/sleeper/systemtest/suite/approvals/CompactionOnFargateST.MergeFiles.shouldCompactFilesUsingBasicCompactionStrategy.approved.txt deleted file mode 100644 index b8dfb3f73b..0000000000 --- a/java/system-test/system-test-suite/src/test/java/sleeper/systemtest/suite/approvals/CompactionOnFargateST.MergeFiles.shouldCompactFilesUsingBasicCompactionStrategy.approved.txt +++ /dev/null @@ -1,6 +0,0 @@ -Unreferenced files: 4 -Referenced files: 2 -File references: 2 -Partition at root: -50 records in file 1 -50 records in file 2 diff --git a/java/system-test/system-test-suite/src/test/java/sleeper/systemtest/suite/approvals/CompactionOnFargateST.MergeFiles.shouldCompactFilesUsingDefaultCompactionStrategy.approved.txt b/java/system-test/system-test-suite/src/test/java/sleeper/systemtest/suite/approvals/CompactionOnFargateST.MergeFiles.shouldCompactFilesUsingDefaultCompactionStrategy.approved.txt deleted file mode 100644 index a90862bc97..0000000000 --- a/java/system-test/system-test-suite/src/test/java/sleeper/systemtest/suite/approvals/CompactionOnFargateST.MergeFiles.shouldCompactFilesUsingDefaultCompactionStrategy.approved.txt +++ /dev/null @@ -1,4 +0,0 @@ -Unreferenced files: 5 -Referenced files: 1 -File references: 1 -Partition at root: 46 records in file 1 diff --git a/java/system-test/system-test-suite/src/test/java/sleeper/systemtest/suite/approvals/CompactionOnFargateST.MergePartialFiles.shouldCompactOneFileFromRootIntoExistingFilesOnLeafPartitions.approved.txt b/java/system-test/system-test-suite/src/test/java/sleeper/systemtest/suite/approvals/CompactionOnFargateST.MergePartialFiles.shouldCompactOneFileFromRootIntoExistingFilesOnLeafPartitions.approved.txt deleted file mode 100644 index 07c7ba6c84..0000000000 --- a/java/system-test/system-test-suite/src/test/java/sleeper/systemtest/suite/approvals/CompactionOnFargateST.MergePartialFiles.shouldCompactOneFileFromRootIntoExistingFilesOnLeafPartitions.approved.txt +++ /dev/null @@ -1,7 +0,0 @@ -Unreferenced files: 5 -Referenced files: 4 -File references: 4 -Partition at LL: 25 records in file 1 -Partition at LR: 25 records in file 2 -Partition at RL: 25 records in file 3 -Partition at RR: 25 records in file 4 diff --git a/java/system-test/system-test-suite/src/test/java/sleeper/systemtest/suite/approvals/CompactionOnFargateST.MergePartialFiles.shouldCompactOneFileIntoExistingFilesOnLeafPartitions.approved.txt b/java/system-test/system-test-suite/src/test/java/sleeper/systemtest/suite/approvals/CompactionOnFargateST.MergePartialFiles.shouldCompactOneFileIntoExistingFilesOnLeafPartitions.approved.txt deleted file mode 100644 index 07c7ba6c84..0000000000 --- a/java/system-test/system-test-suite/src/test/java/sleeper/systemtest/suite/approvals/CompactionOnFargateST.MergePartialFiles.shouldCompactOneFileIntoExistingFilesOnLeafPartitions.approved.txt +++ /dev/null @@ -1,7 +0,0 @@ -Unreferenced files: 5 -Referenced files: 4 -File references: 4 -Partition at LL: 25 records in file 1 -Partition at LR: 25 records in file 2 -Partition at RL: 25 records in file 3 -Partition at RR: 25 records in file 4 diff --git a/java/system-test/system-test-suite/src/test/java/sleeper/systemtest/suite/testutil/TestResources.java b/java/system-test/system-test-suite/src/test/java/sleeper/systemtest/suite/testutil/TestResources.java new file mode 100644 index 0000000000..157dcaaff6 --- /dev/null +++ b/java/system-test/system-test-suite/src/test/java/sleeper/systemtest/suite/testutil/TestResources.java @@ -0,0 +1,53 @@ +/* + * Copyright 2022-2024 Crown Copyright + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package sleeper.systemtest.suite.testutil; + +import org.apache.commons.io.IOUtils; + +import java.io.IOException; +import java.io.InputStream; +import java.io.InputStreamReader; +import java.io.Reader; +import java.net.URL; +import java.util.Objects; + +public class TestResources { + + private TestResources() { + } + + public static String exampleString(String path) { + try (Reader reader = exampleReader(path)) { + return IOUtils.toString(reader); + } catch (IOException e) { + throw new IllegalStateException("Failed to load example: " + path, e); + } + } + + public static Reader exampleReader(String path) { + return new InputStreamReader(exampleInputStream(path)); + } + + public static InputStream exampleInputStream(String path) { + URL resource = Objects.requireNonNull(TestResources.class.getClassLoader().getResource(path)); + try { + return resource.openStream(); + } catch (IOException e) { + throw new IllegalStateException("Failed to load test example: " + path, e); + } + } + +} diff --git a/java/system-test/system-test-suite/src/test/java/sleeper/systemtest/suite/approvals/CompactionOnEC2ST.MergeFiles.shouldCompactFilesUsingBasicCompactionStrategy.approved.txt b/java/system-test/system-test-suite/src/test/resources/compaction/compacted4To2Files.txt similarity index 100% rename from java/system-test/system-test-suite/src/test/java/sleeper/systemtest/suite/approvals/CompactionOnEC2ST.MergeFiles.shouldCompactFilesUsingBasicCompactionStrategy.approved.txt rename to java/system-test/system-test-suite/src/test/resources/compaction/compacted4To2Files.txt diff --git a/java/system-test/system-test-suite/src/test/java/sleeper/systemtest/suite/approvals/CompactionOnEC2ST.MergeFiles.shouldCompactFilesUsingDefaultCompactionStrategy.approved.txt b/java/system-test/system-test-suite/src/test/resources/compaction/compacted5ToSingleFile.txt similarity index 100% rename from java/system-test/system-test-suite/src/test/java/sleeper/systemtest/suite/approvals/CompactionOnEC2ST.MergeFiles.shouldCompactFilesUsingDefaultCompactionStrategy.approved.txt rename to java/system-test/system-test-suite/src/test/resources/compaction/compacted5ToSingleFile.txt diff --git a/java/system-test/system-test-suite/src/test/java/sleeper/systemtest/suite/approvals/CompactionOnEC2ST.MergePartialFiles.shouldCompactOneFileFromRootIntoExistingFilesOnLeafPartitions.approved.txt b/java/system-test/system-test-suite/src/test/resources/compaction/compactedFileIntoLeafPartitions.txt similarity index 100% rename from java/system-test/system-test-suite/src/test/java/sleeper/systemtest/suite/approvals/CompactionOnEC2ST.MergePartialFiles.shouldCompactOneFileFromRootIntoExistingFilesOnLeafPartitions.approved.txt rename to java/system-test/system-test-suite/src/test/resources/compaction/compactedFileIntoLeafPartitions.txt