Skip to content

Commit

Permalink
Enable eclipselink with H2 database in testing
Browse files Browse the repository at this point in the history
  • Loading branch information
aihuaxu committed Aug 26, 2024
1 parent 2d572d2 commit 5da0d7a
Show file tree
Hide file tree
Showing 22 changed files with 182 additions and 273 deletions.
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(
"Create 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(
"Create 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/iceberg/{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.

Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,6 @@
*/
public abstract class LocalPolarisMetaStoreManagerFactory<StoreType>
implements MetaStoreManagerFactory {

final Map<String, PolarisMetaStoreManager> metaStoreManagerMap = new HashMap<>();
final Map<String, StorageCredentialCache> storageCredentialCacheMap = new HashMap<>();
final Map<String, StoreType> backingStoreMap = new HashMap<>();
Expand Down
3 changes: 3 additions & 0 deletions polaris-service/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,9 @@ dependencies {
testImplementation(libs.assertj.core)
testImplementation(libs.mockito.core)
testRuntimeOnly("org.junit.platform:junit-platform-launcher")

testRuntimeOnly(project(":polaris-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 @@ -62,6 +62,7 @@
import java.net.URL;
import java.util.Collections;
import java.util.EnumSet;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.concurrent.Executors;
Expand Down Expand Up @@ -288,7 +289,7 @@ public void run(PolarisApplicationConfig configuration, Environment environment)
// different processes
// and in-memory state will be lost b/w invocation of bootstrap command and running a server
if (metaStoreManagerFactory instanceof InMemoryPolarisMetaStoreManagerFactory) {
metaStoreManagerFactory.getOrCreateMetaStoreManager(configuration::getDefaultRealm);
metaStoreManagerFactory.bootstrapRealms(List.of(configuration.getDefaultRealm()));
}

LOGGER.info("Server started successfully.");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,9 @@
package org.apache.polaris.service.persistence;

import com.fasterxml.jackson.annotation.JsonTypeName;
import java.util.Collections;
import java.util.HashSet;
import java.util.Map;
import java.util.Set;
import java.util.function.Supplier;
import org.apache.polaris.core.PolarisDiagnostics;
import org.apache.polaris.core.context.RealmContext;
import org.apache.polaris.core.persistence.LocalPolarisMetaStoreManagerFactory;
import org.apache.polaris.core.persistence.PolarisMetaStoreManager;
import org.apache.polaris.core.persistence.PolarisMetaStoreSession;
import org.apache.polaris.core.persistence.PolarisTreeMapMetaStoreSessionImpl;
import org.apache.polaris.core.persistence.PolarisTreeMapStore;
Expand All @@ -36,8 +30,6 @@
@JsonTypeName("in-memory")
public class InMemoryPolarisMetaStoreManagerFactory
extends LocalPolarisMetaStoreManagerFactory<PolarisTreeMapStore> {
final Set<String> bootstrappedRealms = new HashSet<>();

@Override
protected PolarisTreeMapStore createBackingStore(@NotNull PolarisDiagnostics diagnostics) {
return new PolarisTreeMapStore(diagnostics);
Expand All @@ -48,40 +40,4 @@ protected PolarisMetaStoreSession createMetaStoreSession(
@NotNull PolarisTreeMapStore store, @NotNull RealmContext realmContext) {
return new PolarisTreeMapMetaStoreSessionImpl(store, storageIntegration);
}

@Override
public synchronized PolarisMetaStoreManager getOrCreateMetaStoreManager(
RealmContext realmContext) {
String realmId = realmContext.getRealmIdentifier();
if (!bootstrappedRealms.contains(realmId)) {
bootstrapRealmAndPrintCredentials(realmId);
}
return super.getOrCreateMetaStoreManager(realmContext);
}

@Override
public synchronized Supplier<PolarisMetaStoreSession> getOrCreateSessionSupplier(
RealmContext realmContext) {
String realmId = realmContext.getRealmIdentifier();
if (!bootstrappedRealms.contains(realmId)) {
bootstrapRealmAndPrintCredentials(realmId);
}
return super.getOrCreateSessionSupplier(realmContext);
}

private void bootstrapRealmAndPrintCredentials(String realmId) {
Map<String, PolarisMetaStoreManager.PrincipalSecretsResult> results =
this.bootstrapRealms(Collections.singletonList(realmId));
bootstrappedRealms.add(realmId);

PolarisMetaStoreManager.PrincipalSecretsResult principalSecrets = results.get(realmId);

String msg =
String.format(
"realm: %1s root principal credentials: %2s:%3s",
realmId,
principalSecrets.getPrincipalSecrets().getPrincipalClientId(),
principalSecrets.getPrincipalSecrets().getMainSecret());
System.out.println(msg);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -143,12 +143,13 @@ public abstract class PolarisAuthzTestBase {
@BeforeEach
@SuppressWarnings("unchecked")
public void before() {
RealmContext realmContext = () -> "realm";
PolarisDiagnostics diagServices = new PolarisDefaultDiagServiceImpl();
InMemoryPolarisMetaStoreManagerFactory managerFactory =
new InMemoryPolarisMetaStoreManagerFactory();
managerFactory.bootstrapRealms(List.of(realmContext.getRealmIdentifier()));
managerFactory.setStorageIntegrationProvider(
new PolarisStorageIntegrationProviderImpl(Mockito::mock));
RealmContext realmContext = () -> "realm";
PolarisMetaStoreManager metaStoreManager =
managerFactory.getOrCreateMetaStoreManager(realmContext);

Expand Down
Loading

0 comments on commit 5da0d7a

Please sign in to comment.