-
Notifications
You must be signed in to change notification settings - Fork 178
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
Allow eclipselink config outside classpath #95
Changes from all commits
27bc0e1
9a05ce4
cfc596c
bfe2286
13831f7
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -24,7 +24,14 @@ | |
import io.polaris.core.persistence.PolarisTestMetaStoreManager; | ||
import io.polaris.extension.persistence.impl.eclipselink.PolarisEclipseLinkMetaStoreSessionImpl; | ||
import io.polaris.extension.persistence.impl.eclipselink.PolarisEclipseLinkStore; | ||
import java.io.IOException; | ||
import java.nio.file.Files; | ||
import java.nio.file.Path; | ||
import java.nio.file.Paths; | ||
import java.time.ZoneId; | ||
import java.util.Objects; | ||
import java.util.UUID; | ||
import org.junit.jupiter.api.Test; | ||
import org.mockito.Mockito; | ||
|
||
/** | ||
|
@@ -36,11 +43,20 @@ public class PolarisEclipseLinkMetaStoreTest extends PolarisMetaStoreManagerTest | |
|
||
@Override | ||
protected PolarisTestMetaStoreManager createPolarisTestMetaStoreManager() { | ||
Path tmpFile = Paths.get(String.format("/tmp/%s-persistence.xml", UUID.randomUUID())); | ||
try { | ||
Files.copy( | ||
Objects.requireNonNull(getClass().getResourceAsStream("/META-INF/persistence.xml")), | ||
tmpFile); | ||
} catch (IOException e) { | ||
throw new RuntimeException(e); | ||
} | ||
|
||
PolarisDiagnostics diagServices = new PolarisDefaultDiagServiceImpl(); | ||
PolarisEclipseLinkStore store = new PolarisEclipseLinkStore(diagServices); | ||
PolarisEclipseLinkMetaStoreSessionImpl session = | ||
new PolarisEclipseLinkMetaStoreSessionImpl( | ||
store, Mockito.mock(), () -> "realm", null, "polaris-dev"); | ||
store, Mockito.mock(), () -> "realm", tmpFile.toString(), "polaris-dev"); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. For this, Persistence.createEntityManagerFactory() will use the one in the jar, not the /tmp/%s-persistence.xml. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You can try to remove persistence.xml from the project and see the issue. |
||
return new PolarisTestMetaStoreManager( | ||
new PolarisMetaStoreManagerImpl(), | ||
new PolarisCallContext( | ||
|
@@ -49,4 +65,20 @@ protected PolarisTestMetaStoreManager createPolarisTestMetaStoreManager() { | |
new PolarisConfigurationStore() {}, | ||
timeSource.withZone(ZoneId.systemDefault()))); | ||
} | ||
|
||
@Test | ||
void throwExceptionIfConfigFileDoesNotExists() { | ||
PolarisDiagnostics diagServices = new PolarisDefaultDiagServiceImpl(); | ||
PolarisEclipseLinkStore store = new PolarisEclipseLinkStore(diagServices); | ||
new PolarisEclipseLinkMetaStoreSessionImpl( | ||
store, Mockito.mock(), () -> "realm", "does not exists", "polaris-dev"); | ||
} | ||
|
||
@Test | ||
void ensureNotLoadingDefaultClassPersistence() { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. How does this test that you're not still loading the file from |
||
PolarisDiagnostics diagServices = new PolarisDefaultDiagServiceImpl(); | ||
PolarisEclipseLinkStore store = new PolarisEclipseLinkStore(diagServices); | ||
new PolarisEclipseLinkMetaStoreSessionImpl( | ||
store, Mockito.mock(), () -> "realm", null, "polaris-dev"); | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is fine but Persistence.createEntityManagerFactory(persistenceUnitName, properties) puts the limitation which can only loads the configuration from a jar. I'm making a change to workaround that. #88
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I was able to fix this in the last commit. Please see the this comment in #79
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I replied in another thread.
@guitcastro Actually it's not because of the properties. Of course we need the properties because we want to replace realm in the database name - each realm will have its own database.
Persistence.createEntityManagerFactory() will still load configuration file from resource even without properties.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@aihuaxu only if you specify the
ECLIPSELINK_PERSISTENCE_XML
property. I've tested and it worked.From their docs:
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've added unit test to ensure config loads from outside the classpath is working.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@guitcastro Can you list the steps how you get it to work? It's possible the unit test found the persistence.xml from the embedded jar. That's why it doesn't fail for you.
I don't see the changes or unit tests in the PR. Did you forget to include that?
I only see
properties.put(ECLIPSELINK_PERSISTENCE_XML, confFile); -- removed
FileInputStream input = new FileInputStream(confFile);
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@aihuaxu Sorry, I have forgot to push it. Can you please take a look now? I also added a test to ensure that the config is not being loaded from the classpath.