Skip to content

Commit c9e0202

Browse files
authored
fix(test): Do not let some more tests spam /tmp (#1651)
* fix(test): Do not let some more tests not spam `/tmp` * `PolarisRestCatalogViewFileIntegrationTest` * `FileIOExceptionsTest` * `PolarisRestCatalogViewFileIntegrationTest` Changes the tests to leverage JUnit's `@TempDir`. Simplifies `PolarisEclipseLinkMetaStoreManagerTest` * review: rename the (now) abstract class
1 parent a534193 commit c9e0202

File tree

7 files changed

+36
-34
lines changed

7 files changed

+36
-34
lines changed

extension/persistence/eclipselink/src/test/java/org/apache/polaris/extension/persistence/impl/eclipselink/PolarisEclipseLinkMetaStoreManagerTest.java

Lines changed: 3 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -25,14 +25,12 @@
2525
import static org.junit.jupiter.api.Assertions.assertNotNull;
2626
import static org.junit.jupiter.api.Assertions.assertTrue;
2727

28-
import java.io.File;
2928
import java.io.IOException;
3029
import java.io.InputStream;
3130
import java.net.URL;
3231
import java.nio.file.Files;
3332
import java.nio.file.Path;
3433
import java.time.ZoneId;
35-
import java.util.Comparator;
3634
import java.util.Objects;
3735
import java.util.stream.Stream;
3836
import org.apache.polaris.core.PolarisCallContext;
@@ -44,10 +42,10 @@
4442
import org.apache.polaris.core.persistence.PolarisTestMetaStoreManager;
4543
import org.apache.polaris.core.persistence.transactional.TransactionalMetaStoreManagerImpl;
4644
import org.apache.polaris.jpa.models.ModelPrincipalSecrets;
47-
import org.junit.jupiter.api.AfterAll;
4845
import org.junit.jupiter.api.Assertions;
4946
import org.junit.jupiter.api.BeforeAll;
5047
import org.junit.jupiter.api.Test;
48+
import org.junit.jupiter.api.io.TempDir;
5149
import org.junit.jupiter.params.ParameterizedTest;
5250
import org.junit.jupiter.params.provider.Arguments;
5351
import org.junit.jupiter.params.provider.MethodSource;
@@ -60,18 +58,15 @@
6058
*/
6159
public class PolarisEclipseLinkMetaStoreManagerTest extends BasePolarisMetaStoreManagerTest {
6260

63-
private static Path rootDir;
6461
private static Path persistenceXml;
6562
private static Path confJar;
6663

6764
@BeforeAll
68-
static void prepareConfFiles() throws IOException {
65+
static void prepareConfFiles(@TempDir Path archiveDir) throws IOException {
6966
URL persistenceXmlSource =
7067
Objects.requireNonNull(
7168
PolarisEclipseLinkMetaStoreManagerTest.class.getResource("/META-INF/persistence.xml"));
72-
rootDir = Files.createTempDirectory("root");
73-
Path archiveDir = rootDir.resolve("archive");
74-
Files.createDirectory(archiveDir);
69+
Files.createDirectories(archiveDir);
7570
persistenceXml = archiveDir.resolve("persistence.xml");
7671
try (InputStream is = persistenceXmlSource.openStream()) {
7772
Files.copy(is, persistenceXml);
@@ -85,17 +80,6 @@ static void prepareConfFiles() throws IOException {
8580
}
8681
}
8782

88-
@AfterAll
89-
static void deleteConfFiles() throws IOException {
90-
if (rootDir != null) {
91-
try (Stream<Path> paths = Files.walk(rootDir)) {
92-
boolean allDeleted =
93-
paths.sorted(Comparator.reverseOrder()).map(Path::toFile).allMatch(File::delete);
94-
assertTrue(allDeleted);
95-
}
96-
}
97-
}
98-
9983
@Override
10084
protected PolarisTestMetaStoreManager createPolarisTestMetaStoreManager() {
10185
PolarisDiagnostics diagServices = new PolarisDefaultDiagServiceImpl();
Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,20 +18,32 @@
1818
*/
1919
package org.apache.polaris.service.it.test;
2020

21+
import java.nio.file.Path;
2122
import java.util.List;
2223
import org.apache.polaris.core.admin.model.FileStorageConfigInfo;
2324
import org.apache.polaris.core.admin.model.StorageConfigInfo;
25+
import org.junit.jupiter.api.BeforeAll;
26+
import org.junit.jupiter.api.io.TempDir;
2427

2528
/** Runs PolarisRestCatalogViewIntegrationTest on the local filesystem. */
26-
public class PolarisRestCatalogViewFileIntegrationTest
29+
public abstract class PolarisRestCatalogViewFileIntegrationTestBase
2730
extends PolarisRestCatalogViewIntegrationBase {
28-
public static final String BASE_LOCATION = "file:///tmp/buckets/my-bucket";
31+
static String baseLocation;
32+
33+
@BeforeAll
34+
public static void setUp(@TempDir Path tempDir) {
35+
String baseUri = tempDir.toAbsolutePath().toUri().toString();
36+
if (baseUri.endsWith("/")) {
37+
baseUri = baseUri.substring(0, baseUri.length() - 1);
38+
}
39+
baseLocation = baseUri;
40+
}
2941

3042
@Override
3143
protected StorageConfigInfo getStorageConfigInfo() {
3244
return FileStorageConfigInfo.builder()
3345
.setStorageType(StorageConfigInfo.StorageTypeEnum.FILE)
34-
.setAllowedLocations(List.of(BASE_LOCATION))
46+
.setAllowedLocations(List.of(baseLocation))
3547
.build();
3648
}
3749

quarkus/service/src/intTest/java/org/apache/polaris/service/quarkus/it/QuarkusRestCatalogViewFileIT.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,12 +22,12 @@
2222
import java.lang.reflect.Field;
2323
import java.nio.file.Path;
2424
import org.apache.iceberg.view.ViewCatalogTests;
25-
import org.apache.polaris.service.it.test.PolarisRestCatalogViewFileIntegrationTest;
25+
import org.apache.polaris.service.it.test.PolarisRestCatalogViewFileIntegrationTestBase;
2626
import org.junit.jupiter.api.BeforeEach;
2727
import org.junit.jupiter.api.io.TempDir;
2828

2929
@QuarkusIntegrationTest
30-
public class QuarkusRestCatalogViewFileIT extends PolarisRestCatalogViewFileIntegrationTest {
30+
public class QuarkusRestCatalogViewFileIT extends PolarisRestCatalogViewFileIntegrationTestBase {
3131

3232
@BeforeEach
3333
public void setUpTempDir(@TempDir Path tempDir) throws Exception {

quarkus/service/src/intTest/java/org/apache/polaris/service/quarkus/it/relational/jdbc/JdbcQuarkusViewFileIT.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,9 @@
2020

2121
import io.quarkus.test.junit.QuarkusIntegrationTest;
2222
import io.quarkus.test.junit.TestProfile;
23-
import org.apache.polaris.service.it.test.PolarisRestCatalogViewFileIntegrationTest;
23+
import org.apache.polaris.service.it.test.PolarisRestCatalogViewFileIntegrationTestBase;
2424
import org.apache.polaris.test.commons.RelationalJdbcProfile;
2525

2626
@TestProfile(RelationalJdbcProfile.class)
2727
@QuarkusIntegrationTest
28-
public class JdbcQuarkusViewFileIT extends PolarisRestCatalogViewFileIntegrationTest {}
28+
public class JdbcQuarkusViewFileIT extends PolarisRestCatalogViewFileIntegrationTestBase {}

quarkus/service/src/test/java/org/apache/polaris/service/quarkus/auth/JWTRSAKeyPairTest.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@
2626
import com.auth0.jwt.interfaces.DecodedJWT;
2727
import io.quarkus.test.junit.QuarkusTest;
2828
import jakarta.inject.Inject;
29-
import java.nio.file.Files;
3029
import java.nio.file.Path;
3130
import java.security.interfaces.RSAPrivateKey;
3231
import java.security.interfaces.RSAPublicKey;
@@ -47,6 +46,7 @@
4746
import org.apache.polaris.service.auth.TokenResponse;
4847
import org.apache.polaris.service.types.TokenType;
4948
import org.junit.jupiter.api.Test;
49+
import org.junit.jupiter.api.io.TempDir;
5050
import org.mockito.Mockito;
5151

5252
@QuarkusTest
@@ -55,9 +55,9 @@ public class JWTRSAKeyPairTest {
5555
@Inject protected PolarisConfigurationStore configurationStore;
5656

5757
@Test
58-
public void testSuccessfulTokenGeneration() throws Exception {
59-
Path privateFileLocation = Files.createTempFile("test-private", ".pem");
60-
Path publicFileLocation = Files.createTempFile("test-public", ".pem");
58+
public void testSuccessfulTokenGeneration(@TempDir Path tempDir) throws Exception {
59+
Path privateFileLocation = tempDir.resolve("test-private.pem");
60+
Path publicFileLocation = tempDir.resolve("test-public.pem");
6161
PemUtils.generateKeyPair(privateFileLocation, publicFileLocation);
6262

6363
final String clientId = "test-client-id";

quarkus/service/src/test/java/org/apache/polaris/service/quarkus/catalog/io/FileIOExceptionsTest.java

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
import com.azure.core.exception.AzureException;
2727
import com.google.cloud.storage.StorageException;
2828
import jakarta.ws.rs.core.Response;
29+
import java.nio.file.Path;
2930
import java.util.List;
3031
import java.util.Map;
3132
import java.util.Optional;
@@ -44,6 +45,7 @@
4445
import org.apache.polaris.service.catalog.io.MeasuredFileIOFactory;
4546
import org.junit.jupiter.api.BeforeAll;
4647
import org.junit.jupiter.api.BeforeEach;
48+
import org.junit.jupiter.api.io.TempDir;
4749
import org.junit.jupiter.params.ParameterizedTest;
4850
import org.junit.jupiter.params.provider.MethodSource;
4951
import software.amazon.awssdk.services.s3.model.S3Exception;
@@ -54,13 +56,12 @@ public class FileIOExceptionsTest {
5456
new Schema(required(3, "id", Types.IntegerType.get(), "unique ID"));
5557

5658
private static final String catalog = "test-catalog";
57-
private static final String catalogBaseLocation = "file:/tmp/buckets/my-bucket/path/to/data";
5859

5960
private static TestServices services;
6061
private static MeasuredFileIOFactory ioFactory;
6162

6263
@BeforeAll
63-
public static void beforeAll() {
64+
public static void beforeAll(@TempDir Path tempDir) {
6465
services =
6566
TestServices.builder()
6667
.config(
@@ -72,6 +73,11 @@ public static void beforeAll() {
7273
.build();
7374
ioFactory = (MeasuredFileIOFactory) services.fileIOFactory();
7475

76+
String catalogBaseLocation = tempDir.toAbsolutePath().toUri().toString();
77+
if (catalogBaseLocation.endsWith("/")) {
78+
catalogBaseLocation = catalogBaseLocation.substring(0, catalogBaseLocation.length() - 1);
79+
}
80+
7581
FileStorageConfigInfo storageConfigInfo =
7682
FileStorageConfigInfo.builder()
7783
.setStorageType(StorageConfigInfo.StorageTypeEnum.FILE)

quarkus/service/src/test/java/org/apache/polaris/service/quarkus/it/QuarkusRestCatalogViewFileIntegrationTest.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,14 +25,14 @@
2525
import java.nio.file.Path;
2626
import java.util.Map;
2727
import org.apache.iceberg.view.ViewCatalogTests;
28-
import org.apache.polaris.service.it.test.PolarisRestCatalogViewFileIntegrationTest;
28+
import org.apache.polaris.service.it.test.PolarisRestCatalogViewFileIntegrationTestBase;
2929
import org.junit.jupiter.api.BeforeEach;
3030
import org.junit.jupiter.api.io.TempDir;
3131

3232
@QuarkusTest
3333
@TestProfile(QuarkusRestCatalogViewFileIntegrationTest.Profile.class)
3434
public class QuarkusRestCatalogViewFileIntegrationTest
35-
extends PolarisRestCatalogViewFileIntegrationTest {
35+
extends PolarisRestCatalogViewFileIntegrationTestBase {
3636

3737
public static class Profile implements QuarkusTestProfile {
3838

0 commit comments

Comments
 (0)