Skip to content

Commit

Permalink
Removed use of Approvals from compaction system tests
Browse files Browse the repository at this point in the history
  • Loading branch information
patchwork01 committed Aug 6, 2024
1 parent 9acdfc4 commit 22ebd70
Show file tree
Hide file tree
Showing 11 changed files with 69 additions and 40 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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
Expand Down Expand Up @@ -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"));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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
Expand All @@ -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"));
}
}

Expand Down Expand Up @@ -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
Expand All @@ -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"));
}
}

Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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"));
}
}
}

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
@@ -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);
}
}

}

0 comments on commit 22ebd70

Please sign in to comment.