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

Unit tests failing when using ebean-postgis Point type #3123

Closed
kristinnsnaer opened this issue Jun 30, 2023 · 9 comments
Closed

Unit tests failing when using ebean-postgis Point type #3123

kristinnsnaer opened this issue Jun 30, 2023 · 9 comments

Comments

@kristinnsnaer
Copy link

My tests are failing when I initiate model A which has a OneToMany relation to model B.
Model B has a nullable column called location of the org.postgis.Point type.

Could very well affect other types.

Expected behavior

The tests should complete successfully.

Actual behavior

All tests that try to initiate model A fail, with the error of that it can't find the class io.ebean.DB

Steps to reproduce

Create a model that has a relation to another model with the Point type.

@Entity
@History
class DModelA(
    @OneToMany(mappedBy = "modelA", cascade = [CascadeType.PERSIST])
    var modelB: MutableList<DModelB>? = mutableListOf()

) : DBaseModel()
import org.postgis.Point;

@Entity
class DModelB(

    @ManyToOne
    var modelA: DModelA? = null,

    ...

    @GraphQLIgnore
    var location: Point? = null
) : Model()
{
    @Id
    var id: UUID = UUID.randomUUID()

    @WhenCreated
    lateinit var dateScanned: Instant
}

Stacktrace from one of the errors (they all have the same exception)

  java.lang.NoClassDefFoundError: Could not initialize class io.ebean.DB
	at io.ebean.Model.db(Model.java:130)
	at io.ebean.Model.save(Model.java:192)
	at com.passi.services.AuthServiceTest.addTestData(AuthServiceTest.kt:230)
	at com.passi.services.AuthServiceTest.setUp(AuthServiceTest.kt:54)
	at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:77)
	at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.base/java.lang.reflect.Method.invoke(Method.java:568)
	at org.junit.platform.commons.util.ReflectionUtils.invokeMethod(ReflectionUtils.java:688)
	at org.junit.jupiter.engine.execution.MethodInvocation.proceed(MethodInvocation.java:60)

From build.gradle:

    // DB
    implementation("io.ebean:ebean-postgis:12.6.2")
    implementation("io.ebean:ebean-querybean:12.6.2")
    implementation("io.ebean:ebean:12.6.2")
    implementation("com.zaxxer:HikariCP:5.0.0")
    implementation("org.postgresql:postgresql:42.2.23")

    testImplementation("io.ebean:ebean-test:12.6.2")
@rbygrave
Copy link
Member

rbygrave commented Jul 3, 2023

java.lang.NoClassDefFoundError: Could not initialize class io.ebean.DB

This is not the "Root Cause". There is either more of this stack trace that was not included above or an earlier stack trace that has the root cause. Can you find the root cause part of the stack trace / include the entire stack trace?

@kristinnsnaer
Copy link
Author

Hi, here is the whole stacktrace.
I have no other info other than the reports from the tests.
This only happens when running tests, no problems when running the server.

java.lang.NoClassDefFoundError: Could not initialize class io.ebean.DB
	at io.ebean.Model.db(Model.java:130)
	at io.ebean.Model.save(Model.java:192)
	at com.passi.services.AuthServiceTest.addTestData(AuthServiceTest.kt:230)
	at com.passi.services.AuthServiceTest.setUp(AuthServiceTest.kt:54)
	at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:77)
	at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.base/java.lang.reflect.Method.invoke(Method.java:568)
	at org.junit.platform.commons.util.ReflectionUtils.invokeMethod(ReflectionUtils.java:688)
	at org.junit.jupiter.engine.execution.MethodInvocation.proceed(MethodInvocation.java:60)
	at org.junit.jupiter.engine.execution.InvocationInterceptorChain$ValidatingInvocation.proceed(InvocationInterceptorChain.java:131)
	at org.junit.jupiter.engine.extension.TimeoutExtension.intercept(TimeoutExtension.java:149)
	at org.junit.jupiter.engine.extension.TimeoutExtension.interceptLifecycleMethod(TimeoutExtension.java:126)
	at org.junit.jupiter.engine.extension.TimeoutExtension.interceptBeforeEachMethod(TimeoutExtension.java:76)
	at org.junit.jupiter.engine.execution.ExecutableInvoker$ReflectiveInterceptorCall.lambda$ofVoidMethod$0(ExecutableInvoker.java:115)
	at org.junit.jupiter.engine.execution.ExecutableInvoker.lambda$invoke$0(ExecutableInvoker.java:105)
	at org.junit.jupiter.engine.execution.InvocationInterceptorChain$InterceptedInvocation.proceed(InvocationInterceptorChain.java:106)
	at org.junit.jupiter.engine.execution.InvocationInterceptorChain.proceed(InvocationInterceptorChain.java:64)
	at org.junit.jupiter.engine.execution.InvocationInterceptorChain.chainAndInvoke(InvocationInterceptorChain.java:45)
	at org.junit.jupiter.engine.execution.InvocationInterceptorChain.invoke(InvocationInterceptorChain.java:37)
	at org.junit.jupiter.engine.execution.ExecutableInvoker.invoke(ExecutableInvoker.java:104)
	at org.junit.jupiter.engine.execution.ExecutableInvoker.invoke(ExecutableInvoker.java:98)
	at org.junit.jupiter.engine.descriptor.ClassBasedTestDescriptor.invokeMethodInExtensionContext(ClassBasedTestDescriptor.java:490)
	at org.junit.jupiter.engine.descriptor.ClassBasedTestDescriptor.lambda$synthesizeBeforeEachMethodAdapter$19(ClassBasedTestDescriptor.java:475)
	at org.junit.jupiter.engine.descriptor.TestMethodTestDescriptor.lambda$invokeBeforeEachMethods$2(TestMethodTestDescriptor.java:167)
	at org.junit.jupiter.engine.descriptor.TestMethodTestDescriptor.lambda$invokeBeforeMethodsOrCallbacksUntilExceptionOccurs$5(TestMethodTestDescriptor.java:195)
	at org.junit.platform.engine.support.hierarchical.ThrowableCollector.execute(ThrowableCollector.java:73)
	at org.junit.jupiter.engine.descriptor.TestMethodTestDescriptor.invokeBeforeMethodsOrCallbacksUntilExceptionOccurs(TestMethodTestDescriptor.java:195)
	at org.junit.jupiter.engine.descriptor.TestMethodTestDescriptor.invokeBeforeEachMethods(TestMethodTestDescriptor.java:164)
	at org.junit.jupiter.engine.descriptor.TestMethodTestDescriptor.execute(TestMethodTestDescriptor.java:127)
	at org.junit.jupiter.engine.descriptor.TestMethodTestDescriptor.execute(TestMethodTestDescriptor.java:65)
	at org.junit.platform.engine.support.hierarchical.NodeTestTask.lambda$executeRecursively$5(NodeTestTask.java:139)
	at org.junit.platform.engine.support.hierarchical.ThrowableCollector.execute(ThrowableCollector.java:73)
	at org.junit.platform.engine.support.hierarchical.NodeTestTask.lambda$executeRecursively$7(NodeTestTask.java:129)
	at org.junit.platform.engine.support.hierarchical.Node.around(Node.java:137)
	at org.junit.platform.engine.support.hierarchical.NodeTestTask.lambda$executeRecursively$8(NodeTestTask.java:127)
	at org.junit.platform.engine.support.hierarchical.ThrowableCollector.execute(ThrowableCollector.java:73)
	at org.junit.platform.engine.support.hierarchical.NodeTestTask.executeRecursively(NodeTestTask.java:126)
	at org.junit.platform.engine.support.hierarchical.NodeTestTask.execute(NodeTestTask.java:84)
	at java.base/java.util.ArrayList.forEach(ArrayList.java:1511)
	at org.junit.platform.engine.support.hierarchical.SameThreadHierarchicalTestExecutorService.invokeAll(SameThreadHierarchicalTestExecutorService.java:38)
	at org.junit.platform.engine.support.hierarchical.NodeTestTask.lambda$executeRecursively$5(NodeTestTask.java:143)
	at org.junit.platform.engine.support.hierarchical.ThrowableCollector.execute(ThrowableCollector.java:73)
	at org.junit.platform.engine.support.hierarchical.NodeTestTask.lambda$executeRecursively$7(NodeTestTask.java:129)
	at org.junit.platform.engine.support.hierarchical.Node.around(Node.java:137)
	at org.junit.platform.engine.support.hierarchical.NodeTestTask.lambda$executeRecursively$8(NodeTestTask.java:127)
	at org.junit.platform.engine.support.hierarchical.ThrowableCollector.execute(ThrowableCollector.java:73)
	at org.junit.platform.engine.support.hierarchical.NodeTestTask.executeRecursively(NodeTestTask.java:126)
	at org.junit.platform.engine.support.hierarchical.NodeTestTask.execute(NodeTestTask.java:84)
	at java.base/java.util.ArrayList.forEach(ArrayList.java:1511)
	at org.junit.platform.engine.support.hierarchical.SameThreadHierarchicalTestExecutorService.invokeAll(SameThreadHierarchicalTestExecutorService.java:38)
	at org.junit.platform.engine.support.hierarchical.NodeTestTask.lambda$executeRecursively$5(NodeTestTask.java:143)
	at org.junit.platform.engine.support.hierarchical.ThrowableCollector.execute(ThrowableCollector.java:73)
	at org.junit.platform.engine.support.hierarchical.NodeTestTask.lambda$executeRecursively$7(NodeTestTask.java:129)
	at org.junit.platform.engine.support.hierarchical.Node.around(Node.java:137)
	at org.junit.platform.engine.support.hierarchical.NodeTestTask.lambda$executeRecursively$8(NodeTestTask.java:127)
	at org.junit.platform.engine.support.hierarchical.ThrowableCollector.execute(ThrowableCollector.java:73)
	at org.junit.platform.engine.support.hierarchical.NodeTestTask.executeRecursively(NodeTestTask.java:126)
	at org.junit.platform.engine.support.hierarchical.NodeTestTask.execute(NodeTestTask.java:84)
	at org.junit.platform.engine.support.hierarchical.SameThreadHierarchicalTestExecutorService.submit(SameThreadHierarchicalTestExecutorService.java:32)
	at org.junit.platform.engine.support.hierarchical.HierarchicalTestExecutor.execute(HierarchicalTestExecutor.java:57)
	at org.junit.platform.engine.support.hierarchical.HierarchicalTestEngine.execute(HierarchicalTestEngine.java:51)
	at org.junit.platform.launcher.core.DefaultLauncher.execute(DefaultLauncher.java:248)
	at org.junit.platform.launcher.core.DefaultLauncher.lambda$execute$5(DefaultLauncher.java:211)
	at org.junit.platform.launcher.core.DefaultLauncher.withInterceptedStreams(DefaultLauncher.java:226)
	at org.junit.platform.launcher.core.DefaultLauncher.execute(DefaultLauncher.java:199)
	at org.junit.platform.launcher.core.DefaultLauncher.execute(DefaultLauncher.java:132)
	at org.gradle.api.internal.tasks.testing.junitplatform.JUnitPlatformTestClassProcessor$CollectAllTestClassesExecutor.processAllTestClasses(JUnitPlatformTestClassProcessor.java:99)
	at org.gradle.api.internal.tasks.testing.junitplatform.JUnitPlatformTestClassProcessor$CollectAllTestClassesExecutor.access$000(JUnitPlatformTestClassProcessor.java:79)
	at org.gradle.api.internal.tasks.testing.junitplatform.JUnitPlatformTestClassProcessor.stop(JUnitPlatformTestClassProcessor.java:75)
	at org.gradle.api.internal.tasks.testing.SuiteTestClassProcessor.stop(SuiteTestClassProcessor.java:61)
	at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:77)
	at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.base/java.lang.reflect.Method.invoke(Method.java:568)
	at org.gradle.internal.dispatch.ReflectionDispatch.dispatch(ReflectionDispatch.java:36)
	at org.gradle.internal.dispatch.ReflectionDispatch.dispatch(ReflectionDispatch.java:24)
	at org.gradle.internal.dispatch.ContextClassLoaderDispatch.dispatch(ContextClassLoaderDispatch.java:33)
	at org.gradle.internal.dispatch.ProxyDispatchAdapter$DispatchingInvocationHandler.invoke(ProxyDispatchAdapter.java:94)
	at jdk.proxy1/jdk.proxy1.$Proxy2.stop(Unknown Source)
	at org.gradle.api.internal.tasks.testing.worker.TestWorker.stop(TestWorker.java:133)
	at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:77)
	at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.base/java.lang.reflect.Method.invoke(Method.java:568)
	at org.gradle.internal.dispatch.ReflectionDispatch.dispatch(ReflectionDispatch.java:36)
	at org.gradle.internal.dispatch.ReflectionDispatch.dispatch(ReflectionDispatch.java:24)
	at org.gradle.internal.remote.internal.hub.MessageHubBackedObjectConnection$DispatchWrapper.dispatch(MessageHubBackedObjectConnection.java:182)
	at org.gradle.internal.remote.internal.hub.MessageHubBackedObjectConnection$DispatchWrapper.dispatch(MessageHubBackedObjectConnection.java:164)
	at org.gradle.internal.remote.internal.hub.MessageHub$Handler.run(MessageHub.java:414)
	at org.gradle.internal.concurrent.ExecutorPolicy$CatchAndRecordFailures.onExecute(ExecutorPolicy.java:64)
	at org.gradle.internal.concurrent.ManagedExecutorImpl$1.run(ManagedExecutorImpl.java:48)
	at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1136)
	at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:635)
	at org.gradle.internal.concurrent.ThreadFactoryImpl$ManagedThreadRunnable.run(ThreadFactoryImpl.java:56)
	at java.base/java.lang.Thread.run(Thread.java:833)

@rbygrave
Copy link
Member

rbygrave commented Jul 3, 2023

Is there another error / stack trace that is reported before that one?

@kristinnsnaer
Copy link
Author

No I only got this, in the sense that there were 21 tests initiating this model and all failed but returned relatively the same stack trace. I can try to run the test more verbosely.

@kristinnsnaer
Copy link
Author

The only other "trace" found is this one.
I realise though that I meant when a model is being saved, as in creating the test data. Not in initialization of the model.

    java.lang.ExceptionInInitializerError at IssuerServiceTest.kt:125
        Caused by: java.lang.RuntimeException at IssuerServiceTest.kt:125
            Caused by: javax.persistence.PersistenceException at IssuerServiceTest.kt:125
                Caused by: java.sql.SQLException at IssuerServiceTest.kt:125
                    Caused by: org.postgresql.util.PSQLException at IssuerServiceTest.kt:125

@rbygrave
Copy link
Member

rbygrave commented Jul 3, 2023

21 tests initiating this model and all failed

I'd suggest to only run 1 test.

Caused by: org.postgresql.util.PSQLException at IssuerServiceTest.kt:125

It is unlikely to be this issue but we can't really tell with the truncated stack trace? Is there not more to that stack trace?

Ultimately there will be another error which we have not seen yet. I'd suggest running 1 test only, and we are looking for the entire stack trace of the first error we see as a result of running that 1 test.

@rob-bygrave
Copy link
Contributor

Ok, it looks like it can fail like this without logging the root cause when a DataSourceConfigurationException is thrown.

You could confirm this is the case by setting a break point into DbContext line 44. This re-throws the DataSourceConfigurationException but that exception is suppressed and not reported and we only see the java.lang.NoClassDefFoundError: Could not initialize class io.ebean.DB - which is very unhelpful.

https://github.com/ebean-orm/ebean/blob/master/ebean-api/src/main/java/io/ebean/DbContext.java#L44-L47

We can "fix" this by ensuring that the DataSourceConfigurationException is logged before it is re-thrown (and potentially suppressed).

@rob-bygrave
Copy link
Contributor

Note that this typically means a missing application-test.yaml or missing ebean-test dependency. See https://ebean.io/docs/trouble-shooting#datasource

Example application-test.yaml

https://github.com/ebean-orm/ebean/blob/master/ebean-postgis/src/test/resources/application-test.yml#L8

Example pom with ebean-test as a test dependency

https://github.com/ebean-orm/ebean/blob/master/ebean-postgis/pom.xml#L65-L70

rbygrave added a commit that referenced this issue Jul 5, 2023
…essed

#3123 Root cause error can be suppressed on initialisation
@kristinnsnaer
Copy link
Author

When tinkering with breakpoints and changing scripts I have seen that it's failing because it's not loading extensions correctly, either postgis(gemoetry type failing) or uuid-ossp. The test file seems to only want to load one extension for me. When looking further into it, using normal yaml array notation doesn't work and causes the generator to create the extensions wrong such as 'create extension -uuid-ossp' or 'create extension -"postgis', the only representation that seemed to work was a comma seperated one-line list of extensions.
Alas this is working, thank you so very much for your help @rbygrave

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants