Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enable eclipselink with H2 database in testing #158

Merged
merged 1 commit into from
Sep 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion extension/persistence/eclipselink/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ tasks.register<Jar>("archiveConf") {
archiveFileName = "conf.jar"
destinationDirectory = layout.buildDirectory.dir("conf")

from("src/test/resources/META-INF/") { include("persistence.xml") }
from("src/main/resources/META-INF/") { include("persistence.xml") }
}

tasks.named("test") { dependsOn("archiveConf") }
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,8 @@ public PolarisEclipseLinkMetaStoreSessionImpl(
@NotNull RealmContext realmContext,
@Nullable String confFile,
@Nullable String persistenceUnitName) {
LOGGER.debug("Create EclipseLink Meta Store Session for {}", realmContext.getRealmIdentifier());
LOGGER.debug(
"Creating EclipseLink Meta Store Session for realm {}", realmContext.getRealmIdentifier());
emf = createEntityManagerFactory(realmContext, confFile, persistenceUnitName);

// init store
Expand Down Expand Up @@ -153,8 +154,8 @@ private EntityManagerFactory createEntityManagerFactory(
prefixUrl = new File(jarPrefixPath).toURI().toURL();
}

LOGGER.info(
"Created a new ClassLoader with the jar {} in classpath to load the config file",
LOGGER.debug(
"Creating a new ClassLoader with the jar {} in classpath to load the config file",
prefixUrl);

URLClassLoader currentClassLoader =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
<shared-cache-mode>NONE</shared-cache-mode>
<properties>
<property name="jakarta.persistence.jdbc.url"
value="jdbc:h2:file:/tmp/eclipseLink/{realm}"/>
value="jdbc:h2:file:./build/test_data/polaris/{realm}/db"/>
<property name="jakarta.persistence.jdbc.user" value="sa"/>
<property name="jakarta.persistence.jdbc.password" value=""/>
<property name="jakarta.persistence.schema-generation.database.action" value="create"/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ protected PolarisTestMetaStoreManager createPolarisTestMetaStoreManager() {
PolarisEclipseLinkStore store = new PolarisEclipseLinkStore(diagServices);
PolarisEclipseLinkMetaStoreSessionImpl session =
new PolarisEclipseLinkMetaStoreSessionImpl(
store, Mockito.mock(), () -> "realm", null, "polaris-dev");
store, Mockito.mock(), () -> "realm", null, "polaris");
return new PolarisTestMetaStoreManager(
new PolarisMetaStoreManagerImpl(),
new PolarisCallContext(
Expand All @@ -72,7 +72,7 @@ void testCreateStoreSession(String confFile, boolean success) {
try {
var session =
new PolarisEclipseLinkMetaStoreSessionImpl(
store, Mockito.mock(), () -> "realm", confFile, "polaris-dev");
store, Mockito.mock(), () -> "realm", confFile, "polaris");
assertNotNull(session);
assertTrue(success);
} catch (Exception e) {
Expand Down

This file was deleted.

3 changes: 3 additions & 0 deletions polaris-service/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,9 @@ dependencies {
testImplementation(libs.assertj.core)
testImplementation(libs.mockito.core)
testRuntimeOnly("org.junit.platform:junit-platform-launcher")

testRuntimeOnly(project(":polaris-eclipselink"))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For now I think this could be okay, but I feel like we may not want these dependencies here forever. We have intentionally not included these dependencies in the service. A new project to include all these dependencies could make sense.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we create a separate project to include the dependencies, we still need to include such project here , right? This is for test only though.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I will try to address in the following PRs to include the dependency if needed. I saw that we have -PeclipseLink=$ECLIPSELINK.

testRuntimeOnly(libs.h2)
}

if (project.properties.get("eclipseLink") == "true") {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,7 @@ public BootstrapRealmsCommand() {
protected void run(
Bootstrap<PolarisApplicationConfig> bootstrap,
Namespace namespace,
PolarisApplicationConfig configuration)
throws Exception {
PolarisApplicationConfig configuration) {
MetaStoreManagerFactory metaStoreManagerFactory = configuration.getMetaStoreManagerFactory();

PolarisConfigurationStore configurationStore = configuration.getConfigurationStore();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
import jakarta.ws.rs.client.Entity;
import jakarta.ws.rs.client.Invocation;
import jakarta.ws.rs.core.Response;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
Expand Down Expand Up @@ -60,9 +61,12 @@ public class PolarisOverlappingCatalogTest {
private static String realm;

@BeforeAll
public static void setup(PolarisConnectionExtension.PolarisToken adminToken) {
public static void setup(PolarisConnectionExtension.PolarisToken adminToken) throws IOException {
userToken = adminToken.token();
realm = PolarisConnectionExtension.getTestRealm(PolarisServiceImplIntegrationTest.class);
realm = PolarisConnectionExtension.getTestRealm(PolarisOverlappingCatalogTest.class);

// Set up the database location
PolarisConnectionExtension.createTestDir(realm);
}

private Response createCatalog(String prefix, String defaultBaseLocation, boolean isExternal) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -99,9 +99,12 @@ public class PolarisServiceImplIntegrationTest {
private static String realm;

@BeforeAll
public static void setup(PolarisConnectionExtension.PolarisToken adminToken) {
public static void setup(PolarisConnectionExtension.PolarisToken adminToken) throws IOException {
userToken = adminToken.token();
realm = PolarisConnectionExtension.getTestRealm(PolarisServiceImplIntegrationTest.class);

// Set up test location
PolarisConnectionExtension.createTestDir(realm);
}

@AfterEach
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,14 +31,11 @@
import jakarta.ws.rs.client.Entity;
import jakarta.ws.rs.core.Response;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Optional;
import java.util.UUID;
import org.apache.commons.io.FileUtils;
import org.apache.iceberg.BaseTable;
import org.apache.iceberg.CatalogProperties;
import org.apache.iceberg.Schema;
Expand Down Expand Up @@ -133,9 +130,8 @@ public class PolarisRestCatalogIntegrationTest extends CatalogTests<RESTCatalog>
public static void setup() throws IOException {
realm = PolarisConnectionExtension.getTestRealm(PolarisRestCatalogIntegrationTest.class);

Path testDir = Path.of("build/test_data/iceberg/" + realm);
FileUtils.deleteQuietly(testDir.toFile());
Files.createDirectories(testDir);
// Set up test location
PolarisConnectionExtension.createTestDir(realm);
}

@BeforeEach
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,8 @@
import jakarta.ws.rs.client.Entity;
import jakarta.ws.rs.core.Response;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.List;
import java.util.Optional;
import org.apache.commons.io.FileUtils;
import org.apache.iceberg.CatalogProperties;
import org.apache.iceberg.catalog.SessionCatalog;
import org.apache.iceberg.rest.HTTPClient;
Expand Down Expand Up @@ -96,9 +93,8 @@ public class PolarisRestCatalogViewIntegrationTest extends ViewCatalogTests<REST
public static void setup() throws IOException {
realm = PolarisConnectionExtension.getTestRealm(PolarisRestCatalogViewIntegrationTest.class);

Path testDir = Path.of("build/test_data/iceberg/" + realm);
FileUtils.deleteQuietly(testDir.toFile());
Files.createDirectories(testDir);
// Set up test location
PolarisConnectionExtension.createTestDir(realm);
}

@BeforeEach
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
import io.dropwizard.testing.junit5.DropwizardExtensionsSupport;
import jakarta.ws.rs.client.Entity;
import jakarta.ws.rs.core.Response;
import java.io.IOException;
import java.time.Instant;
import java.util.List;
import java.util.Map;
Expand Down Expand Up @@ -79,10 +80,14 @@ public class PolarisSparkIntegrationTest {
private static String realm;

@BeforeAll
public static void setup(PolarisConnectionExtension.PolarisToken polarisToken) {
public static void setup(PolarisConnectionExtension.PolarisToken polarisToken)
throws IOException {
s3Container.start();
PolarisSparkIntegrationTest.polarisToken = polarisToken;
realm = PolarisConnectionExtension.getTestRealm(PolarisSparkIntegrationTest.class);

// Set up test location
PolarisConnectionExtension.createTestDir(realm);
}

@AfterAll
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,15 +43,21 @@
import org.apache.polaris.core.entity.AsyncTaskType;
import org.apache.polaris.core.entity.TaskEntity;
import org.apache.polaris.service.persistence.InMemoryPolarisMetaStoreManagerFactory;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;

class ManifestFileCleanupTaskHandlerTest {
private InMemoryPolarisMetaStoreManagerFactory metaStoreManagerFactory;
private RealmContext realmContext;

@BeforeEach
void setUp() {
metaStoreManagerFactory = new InMemoryPolarisMetaStoreManagerFactory();
realmContext = () -> "realmName";
}

@Test
public void testCleanupFileNotExists() throws IOException {
InMemoryPolarisMetaStoreManagerFactory metaStoreManagerFactory =
new InMemoryPolarisMetaStoreManagerFactory();
RealmContext realmContext = () -> "realmName";
PolarisCallContext polarisCallContext =
new PolarisCallContext(
metaStoreManagerFactory.getOrCreateSessionSupplier(realmContext).get(),
Expand Down Expand Up @@ -83,9 +89,6 @@ public void testCleanupFileNotExists() throws IOException {

@Test
public void testCleanupFileManifestExistsDataFilesDontExist() throws IOException {
InMemoryPolarisMetaStoreManagerFactory metaStoreManagerFactory =
new InMemoryPolarisMetaStoreManagerFactory();
RealmContext realmContext = () -> "realmName";
PolarisCallContext polarisCallContext =
new PolarisCallContext(
metaStoreManagerFactory.getOrCreateSessionSupplier(realmContext).get(),
Expand Down Expand Up @@ -116,9 +119,6 @@ public void testCleanupFileManifestExistsDataFilesDontExist() throws IOException

@Test
public void testCleanupFiles() throws IOException {
InMemoryPolarisMetaStoreManagerFactory metaStoreManagerFactory =
new InMemoryPolarisMetaStoreManagerFactory();
RealmContext realmContext = () -> "realmName";
PolarisCallContext polarisCallContext =
new PolarisCallContext(
metaStoreManagerFactory.getOrCreateSessionSupplier(realmContext).get(),
Expand Down Expand Up @@ -166,9 +166,6 @@ public void close() {

@Test
public void testCleanupFilesWithRetries() throws IOException {
InMemoryPolarisMetaStoreManagerFactory metaStoreManagerFactory =
new InMemoryPolarisMetaStoreManagerFactory();
RealmContext realmContext = () -> "realmName";
PolarisCallContext polarisCallContext =
new PolarisCallContext(
metaStoreManagerFactory.getOrCreateSessionSupplier(realmContext).get(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,17 +41,23 @@
import org.apache.polaris.core.entity.TaskEntity;
import org.apache.polaris.service.persistence.InMemoryPolarisMetaStoreManagerFactory;
import org.assertj.core.api.Assertions;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.mockito.Mockito;
import org.slf4j.LoggerFactory;

class TableCleanupTaskHandlerTest {
private InMemoryPolarisMetaStoreManagerFactory metaStoreManagerFactory;
private RealmContext realmContext;

@BeforeEach
void setUp() {
metaStoreManagerFactory = new InMemoryPolarisMetaStoreManagerFactory();
realmContext = () -> "realmName";
}

@Test
public void testTableCleanup() throws IOException {
InMemoryPolarisMetaStoreManagerFactory metaStoreManagerFactory =
new InMemoryPolarisMetaStoreManagerFactory();
RealmContext realmContext = () -> "realmName";
PolarisCallContext polarisCallContext =
new PolarisCallContext(
metaStoreManagerFactory.getOrCreateSessionSupplier(realmContext).get(),
Expand Down Expand Up @@ -112,9 +118,6 @@ public void testTableCleanup() throws IOException {

@Test
public void testTableCleanupHandlesAlreadyDeletedMetadata() throws IOException {
InMemoryPolarisMetaStoreManagerFactory metaStoreManagerFactory =
new InMemoryPolarisMetaStoreManagerFactory();
RealmContext realmContext = () -> "realmName";
PolarisCallContext polarisCallContext =
new PolarisCallContext(
metaStoreManagerFactory.getOrCreateSessionSupplier(realmContext).get(),
Expand Down Expand Up @@ -174,9 +177,6 @@ public void close() {

@Test
public void testTableCleanupDuplicatesTasksIfFileStillExists() throws IOException {
InMemoryPolarisMetaStoreManagerFactory metaStoreManagerFactory =
new InMemoryPolarisMetaStoreManagerFactory();
RealmContext realmContext = () -> "realmName";
PolarisCallContext polarisCallContext =
new PolarisCallContext(
metaStoreManagerFactory.getOrCreateSessionSupplier(realmContext).get(),
Expand Down Expand Up @@ -269,9 +269,6 @@ public void close() {

@Test
public void testTableCleanupMultipleSnapshots() throws IOException {
InMemoryPolarisMetaStoreManagerFactory metaStoreManagerFactory =
new InMemoryPolarisMetaStoreManagerFactory();
RealmContext realmContext = () -> "realmName";
PolarisCallContext polarisCallContext =
new PolarisCallContext(
metaStoreManagerFactory.getOrCreateSessionSupplier(realmContext).get(),
Expand Down
Loading