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

fix(java): exclude tests that use Mockito from native image testing #1753

Closed
wants to merge 1 commit into from

Conversation

mpeddada1
Copy link
Contributor

Mockito dynamically loads classes at run-time and is currently incompatible with native image testing. Therefore, tests that use Mockito are resulting in the following error when they are executed with native image testing:

DdlClientTest:

  JUnit Vintage:DdlClientTest:testExecuteDdl
    MethodSource [className = 'com.google.cloud.spanner.connection.DdlClientTest', methodName = 'testExecuteDdl', methodParameterTypes = '']
    => com.oracle.svm.core.jdk.UnsupportedFeatureError: Proxy class defined by interfaces [interface org.mockito.plugins.PluginSwitch] not found. Generating proxy classes at runtime is not supported. Proxy classes need to be defined at image build time by specifying the list of interfaces that they implement. To define proxy classes use -H:DynamicProxyConfigurationFiles=<comma-separated-config-files> and -H:DynamicProxyConfigurationResources=<comma-separated-config-resources> options.
       com.oracle.svm.core.util.VMError.unsupportedFeature(VMError.java:87)
       com.oracle.svm.reflect.proxy.DynamicProxySupport.getProxyClass(DynamicProxySupport.java:146)
       java.lang.reflect.Proxy.getProxyConstructor(Proxy.java:66)
       java.lang.reflect.Proxy.newProxyInstance(Proxy.java:1006)
       org.mockito.internal.configuration.plugins.PluginLoader.loadPlugin(PluginLoader.java:81)
       org.mockito.internal.configuration.plugins.PluginLoader.loadPlugin(PluginLoader.java:54)
       org.mockito.internal.configuration.plugins.PluginRegistry.<init>(PluginRegistry.java:21)
       org.mockito.internal.configuration.plugins.Plugins.<clinit>(Plugins.java:22)
       org.mockito.internal.MockitoCore.<clinit>(MockitoCore.java:77)
       org.mockito.Mockito.<clinit>(Mockito.java:1614)
       [...]

SessionClientTest:

JUnit Vintage:SessionClientTest:[NumChannels = 8]:createAndCloseSession[NumChannels = 8]
    MethodSource [className = 'com.google.cloud.spanner.SessionClientTest', methodName = 'createAndCloseSession', methodParameterTypes = '']
    => java.lang.NoClassDefFoundError: Could not initialize class org.mockito.internal.configuration.plugins.Plugins
       org.mockito.internal.configuration.GlobalConfiguration.tryGetPluginAnnotationEngine(GlobalConfiguration.java:50)
       org.mockito.MockitoAnnotations.openMocks(MockitoAnnotations.java:81)
       org.mockito.MockitoAnnotations.initMocks(MockitoAnnotations.java:100)
       com.google.cloud.spanner.SessionClientTest.setUp(SessionClientTest.java:90)
       java.lang.reflect.Method.invoke(Method.java:566)
       org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:59)
       org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
       org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:56)
       org.junit.internal.runners.statements.RunBefores.invokeMethod(RunBefores.java:33)
       org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:24)
       [...]

Some background on how native image tests are opted in: The logic to opt libraries into native image testing lives in java-shared-config (see https://github.com/googleapis/java-shared-config/blob/1015b908c5aaa6f0b6c77759d86557ca26504868/pom.xml#L811) Currently tests with the IT* and *ClientTest pattern are opted in. The reason for this is to include integration tests in all libraries and unit tests in only generated libraries for native image testing (see this logic for the naming pattern the Gapic generator uses to generate unit tests).

This PR excludes SessionClientTest and DdlClientTest from native image testing by renaming them to SessionClientTests and DdlClientTests.

cc @ansh0l @meltsufin

@mpeddada1 mpeddada1 requested a review from a team as a code owner March 16, 2022 23:28
@product-auto-label product-auto-label bot added the api: spanner Issues related to the googleapis/java-spanner API. label Mar 16, 2022
@mpeddada1 mpeddada1 added the kokoro:run Add this label to force Kokoro to re-run the tests. label Mar 18, 2022
@yoshi-kokoro yoshi-kokoro removed the kokoro:run Add this label to force Kokoro to re-run the tests. label Mar 18, 2022
@mpeddada1
Copy link
Contributor Author

Hi @ansh0l could we get a review on this PR?

Copy link
Contributor

@ansh0l ansh0l left a comment

Choose a reason for hiding this comment

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

LGTM. @mpeddada1 Please wait on merging this one, I think we should batch all PRs for native image testing to have a single release. We're planning a release for cross region backups in next few days.

@ansh0l ansh0l added the do not merge Indicates a pull request not ready for merge, due to either quality or timing. label Mar 28, 2022
@ansh0l
Copy link
Contributor

ansh0l commented Mar 28, 2022

@mpeddada1 : I've added a do not merge label - feel free to remove and merge with other PRs when they are ready.

@ansh0l
Copy link
Contributor

ansh0l commented May 23, 2022

Closing since native image changes have been released with #1878

@ansh0l ansh0l closed this May 23, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
api: spanner Issues related to the googleapis/java-spanner API. do not merge Indicates a pull request not ready for merge, due to either quality or timing.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants