Skip to content
This repository was archived by the owner on Sep 16, 2023. It is now read-only.

test: adding native image configuration required for tests#754

Closed
suztomo wants to merge 3 commits intogoogleapis:mainfrom
suztomo:graalvm_test
Closed

test: adding native image configuration required for tests#754
suztomo wants to merge 3 commits intogoogleapis:mainfrom
suztomo:graalvm_test

Conversation

@suztomo
Copy link
Copy Markdown
Member

@suztomo suztomo commented Nov 30, 2021

Trying to fix "Kokoro - Test: Java GraalVM Native Image" build.

Failures (12):
  JUnit Vintage:ITSystemTest:detectLabelsTest
    MethodSource [className = 'com.google.cloud.vision.it.ITSystemTest', methodName = 'detectLabelsTest', methodParameterTypes = '']
    => java.io.FileNotFoundException: src/test/resources/wakeupcat.jpg (No such file or directory)
       com.oracle.svm.jni.JNIJavaCallWrappers.jniInvoke_VA_LIST:Ljava_io_FileNotFoundException_2_0002e_0003cinit_0003e_00028Ljava_lang_String_2Ljava_lang_String_2_00029V(JNIJavaCallWrappers.java:0)
       java.io.FileInputStream.open0(FileInputStream.java)
       java.io.FileInputStream.open(FileInputStream.java:219)
       java.io.FileInputStream.<init>(FileInputStream.java:157)
       java.io.FileInputStream.<init>(FileInputStream.java:112)
       com.google.cloud.vision.it.ITSystemTest.getResponsesList(ITSystemTest.java:223)
       com.google.cloud.vision.it.ITSystemTest.detectLabelsTest(ITSystemTest.java:263)
       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)
       [...]
...

https://source.cloud.google.com/results/invocations/cc541c2e-5da6-48bf-acb1-dd0d90f340b3/targets/cloud-devrel%2Fclient-libraries%2Fjava%2Fjava-vision%2Fpresubmit%2Fgraalvm-native/log

The test execution requires some configuration for native image to load resource files.

@google-cla google-cla bot added the cla: yes This human has signed the Contributor License Agreement. label Nov 30, 2021
@product-auto-label product-auto-label bot added the api: vision Issues related to the googleapis/java-vision API. label Nov 30, 2021
@suztomo
Copy link
Copy Markdown
Member Author

suztomo commented Nov 30, 2021

{"pattern":"*.png"} failed:

Fatal error:java.util.regex.PatternSyntaxException: Dangling meta character '*' near index 0
*.png
^

@suztomo
Copy link
Copy Markdown
Member Author

suztomo commented Nov 30, 2021

{"pattern":".*.jpg"}, didn't make any effect.

Failures (12):
  JUnit Vintage:ITSystemTest:detectLabelsTest
    MethodSource [className = 'com.google.cloud.vision.it.ITSystemTest', methodName = 'detectLabelsTest', methodParameterTypes = '']
    => java.io.FileNotFoundException: src/test/resources/wakeupcat.jpg (No such file or directory)
       com.oracle.svm.jni.JNIJavaCallWrappers.jniInvoke_VA_LIST:Ljava_io_FileNotFoundException_2_0002e_0003cinit_0003e_00028Ljava_lang_String_2Ljava_lang_String_2_00029V(JNIJavaCallWrappers.java:0)
       java.io.FileInputStream.open0(FileInputStream.java)
       java.io.FileInputStream.open(FileInputStream.java:219)
       java.io.FileInputStream.<init>(FileInputStream.java:157)
       java.io.FileInputStream.<init>(FileInputStream.java:112)
       com.google.cloud.vision.it.ITSystemTest.getResponsesList(ITSystemTest.java:223)
       com.google.cloud.vision.it.ITSystemTest.detectLabelsTest(ITSystemTest.java:263)
       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)
       [...]

@suztomo
Copy link
Copy Markdown
Member Author

suztomo commented Nov 30, 2021

@suztomo
Copy link
Copy Markdown
Member Author

suztomo commented Nov 30, 2021

From the stacktrace, the error is from FileInputStream (stream for a file in a file system):

ByteString imgBytes = ByteString.readFrom(new FileInputStream(RESOURCES + image));

where RESOURCES is "src/test/resources/" and image is "wakeupcat.jpg" for example. It seems the problem is the wrong working directory.

If it was referring a resource, the error message would have "wakeupcat.jpg", not "src/test/resources/wakeupcat.jpg".

@mpeddada1
Copy link
Copy Markdown
Contributor

I think this is a limitation of using resource configs with Graal: https://github.com/mpeddada1/native-resources-config/blob/main/child-module/src/test/java/com/example/ResourceExampleTest.java. FileInputStream/FileSystems doesn't recognize the resources-config.json. What happens if we reference the resource using the ClassLoader?

@suztomo
Copy link
Copy Markdown
Member Author

suztomo commented Mar 25, 2022

I recognize this is the problem of working directory #856 (comment). JVM execution and GraalVM native-image execution show different output for working directory.

I think the integration test is intended to use file as input, rather than resources, for documentation purpose on how to use this library.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

api: vision Issues related to the googleapis/java-vision API. cla: yes This human has signed the Contributor License Agreement.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants