You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@polaris.apache.org by ad...@apache.org on 2025/01/07 09:40:54 UTC
(polaris) branch main updated: EclipseLink: make test resilient to non-file classpath URLs (#619)
This is an automated email from the ASF dual-hosted git repository.
adutra pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/polaris.git
The following commit(s) were added to refs/heads/main by this push:
new 62c23c36 EclipseLink: make test resilient to non-file classpath URLs (#619)
62c23c36 is described below
commit 62c23c3658c11fb3bbc557cdeb2e9da0b6c50e8e
Author: Alexandre Dutra <ad...@users.noreply.github.com>
AuthorDate: Tue Jan 7 10:40:50 2025 +0100
EclipseLink: make test resilient to non-file classpath URLs (#619)
---
.../PolarisEclipseLinkMetaStoreManagerTest.java | 104 +++++++++++++--------
1 file changed, 67 insertions(+), 37 deletions(-)
diff --git a/extension/persistence/eclipselink/src/test/java/org/apache/polaris/extension/persistence/impl/eclipselink/PolarisEclipseLinkMetaStoreManagerTest.java b/extension/persistence/eclipselink/src/test/java/org/apache/polaris/extension/persistence/impl/eclipselink/PolarisEclipseLinkMetaStoreManagerTest.java
index 5b04ecc1..cd9b0859 100644
--- a/extension/persistence/eclipselink/src/test/java/org/apache/polaris/extension/persistence/impl/eclipselink/PolarisEclipseLinkMetaStoreManagerTest.java
+++ b/extension/persistence/eclipselink/src/test/java/org/apache/polaris/extension/persistence/impl/eclipselink/PolarisEclipseLinkMetaStoreManagerTest.java
@@ -25,10 +25,14 @@ import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.junit.jupiter.api.Assertions.assertTrue;
-import java.net.URISyntaxException;
+import java.io.File;
+import java.io.IOException;
+import java.io.InputStream;
+import java.net.URL;
+import java.nio.file.Files;
import java.nio.file.Path;
-import java.nio.file.Paths;
import java.time.ZoneId;
+import java.util.Comparator;
import java.util.Objects;
import java.util.stream.Stream;
import org.apache.polaris.core.PolarisCallContext;
@@ -40,13 +44,13 @@ import org.apache.polaris.core.persistence.BasePolarisMetaStoreManagerTest;
import org.apache.polaris.core.persistence.PolarisMetaStoreManagerImpl;
import org.apache.polaris.core.persistence.PolarisTestMetaStoreManager;
import org.apache.polaris.jpa.models.ModelPrincipalSecrets;
+import org.junit.jupiter.api.AfterAll;
import org.junit.jupiter.api.Assertions;
+import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;
-import org.junit.jupiter.api.extension.ExtensionContext;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.Arguments;
-import org.junit.jupiter.params.provider.ArgumentsProvider;
-import org.junit.jupiter.params.provider.ArgumentsSource;
+import org.junit.jupiter.params.provider.MethodSource;
import org.mockito.Mockito;
/**
@@ -56,6 +60,42 @@ import org.mockito.Mockito;
*/
public class PolarisEclipseLinkMetaStoreManagerTest extends BasePolarisMetaStoreManagerTest {
+ private static Path rootDir;
+ private static Path persistenceXml;
+ private static Path confJar;
+
+ @BeforeAll
+ static void prepareConfFiles() throws IOException {
+ URL persistenceXmlSource =
+ Objects.requireNonNull(
+ PolarisEclipseLinkMetaStoreManagerTest.class.getResource("/META-INF/persistence.xml"));
+ rootDir = Files.createTempDirectory("root");
+ Path archiveDir = rootDir.resolve("archive");
+ Files.createDirectory(archiveDir);
+ persistenceXml = archiveDir.resolve("persistence.xml");
+ try (InputStream is = persistenceXmlSource.openStream()) {
+ Files.copy(is, persistenceXml);
+ }
+ URL confJarSource =
+ Objects.requireNonNull(
+ PolarisEclipseLinkMetaStoreManagerTest.class.getResource("/eclipselink/test-conf.jar"));
+ confJar = archiveDir.resolve("test-conf.jar");
+ try (InputStream is = confJarSource.openStream()) {
+ Files.copy(is, confJar);
+ }
+ }
+
+ @AfterAll
+ static void deleteConfFiles() throws IOException {
+ if (rootDir != null) {
+ try (Stream<Path> paths = Files.walk(rootDir)) {
+ boolean allDeleted =
+ paths.sorted(Comparator.reverseOrder()).map(Path::toFile).allMatch(File::delete);
+ assertTrue(allDeleted);
+ }
+ }
+ }
+
@Override
protected PolarisTestMetaStoreManager createPolarisTestMetaStoreManager() {
PolarisDiagnostics diagServices = new PolarisDefaultDiagServiceImpl();
@@ -72,8 +112,8 @@ public class PolarisEclipseLinkMetaStoreManagerTest extends BasePolarisMetaStore
timeSource.withZone(ZoneId.systemDefault())));
}
- @ParameterizedTest()
- @ArgumentsSource(CreateStoreSessionArgs.class)
+ @ParameterizedTest
+ @MethodSource
void testCreateStoreSession(String confFile, boolean success) {
// Clear cache to prevent reuse EntityManagerFactory
PolarisEclipseLinkMetaStoreSessionImpl.clearEntityManagerFactories();
@@ -91,6 +131,26 @@ public class PolarisEclipseLinkMetaStoreManagerTest extends BasePolarisMetaStore
}
}
+ public static Stream<Arguments> testCreateStoreSession() {
+ return Stream.of(
+ // conf file not provided
+ Arguments.of(null, true),
+ // classpath resource
+ Arguments.of("META-INF/persistence.xml", true),
+ Arguments.of("META-INF/dummy.xml", false),
+ // classpath resource, embedded
+ Arguments.of("eclipselink/test-conf.jar!/persistence.xml", true),
+ Arguments.of("eclipselink/test-conf.jar!/dummy.xml", false),
+ Arguments.of("dummy/test-conf.jar!/persistence.xml", false),
+ // filesystem path
+ Arguments.of(persistenceXml.toString(), true),
+ Arguments.of("/dummy_path/conf/persistence.xml", false),
+ // filesystem path, embedded
+ Arguments.of(confJar + "!/persistence.xml", true),
+ Arguments.of(confJar + "!/dummy.xml", false),
+ Arguments.of("/dummy_path/test-conf.jar!/persistence.xml", false));
+ }
+
@Test
void testRotateLegacyPrincipalSecret() {
@@ -205,34 +265,4 @@ public class PolarisEclipseLinkMetaStoreManagerTest extends BasePolarisMetaStore
Assertions.assertFalse(reloadedSecrets.matchesSecret(newSecrets.getSecondarySecret()));
}
}
-
- private static class CreateStoreSessionArgs implements ArgumentsProvider {
- @Override
- public Stream<? extends Arguments> provideArguments(ExtensionContext extensionContext)
- throws URISyntaxException {
- Path persistenceXml =
- Paths.get(
- Objects.requireNonNull(getClass().getResource("/META-INF/persistence.xml")).toURI());
- Path confJar =
- Paths.get(
- Objects.requireNonNull(getClass().getResource("/eclipselink/test-conf.jar")).toURI());
- return Stream.of(
- // conf file not provided
- Arguments.of(null, true),
- // classpath resource
- Arguments.of("META-INF/persistence.xml", true),
- Arguments.of("META-INF/dummy.xml", false),
- // classpath resource, embedded
- Arguments.of("eclipselink/test-conf.jar!/persistence.xml", true),
- Arguments.of("eclipselink/test-conf.jar!/dummy.xml", false),
- Arguments.of("dummy/test-conf.jar!/persistence.xml", false),
- // filesystem path
- Arguments.of(persistenceXml.toString(), true),
- Arguments.of("/dummy_path/conf/persistence.xml", false),
- // filesystem path, embedded
- Arguments.of(confJar + "!/persistence.xml", true),
- Arguments.of(confJar + "!/dummy.xml", false),
- Arguments.of("/dummy_path/test-conf.jar!/persistence.xml", false));
- }
- }
}