[ 
https://issues.apache.org/jira/browse/CALCITE-5052?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17510816#comment-17510816
 ] 

Julian Hyde commented on CALCITE-5052:
--------------------------------------

I am reviewing the PR now. I might add a test case that actually reads 
resources from a jar file, and that should give us more confidence.

The fix is not specific to Bazel (and nor is the test case) so I think we 
should change the subject of this case. We can still mention that it helps the 
tests run under Bazel.

> Calcite testkit issue loading resources from jar in DiffRepository (bazel)
> --------------------------------------------------------------------------
>
>                 Key: CALCITE-5052
>                 URL: https://issues.apache.org/jira/browse/CALCITE-5052
>             Project: Calcite
>          Issue Type: Bug
>            Reporter: Marieke Gueye
>            Assignee: Marieke Gueye
>            Priority: Blocker
>              Labels: pull-request-available
>             Fix For: 1.31.0
>
>          Time Spent: 20m
>  Remaining Estimate: 0h
>
> Calcite testkit assumes resources are packaged/available with the {{file:}} 
> protocol, however jar resources have {{jar:}} as the protocol to indicate the 
> resource is within the internal jar file system.
> Here is where calcite requires a {{file:}} protocol: 
> [Sources.java|https://github.com/apache/calcite/blob/4bc916619fd286b2c0cc4d5c653c96a68801d74e/core/src/main/java/org/apache/calcite/util/Sources.java#L186]
> Here is where the resource is loaded and returns the URL to the file: 
> [DiffRepository.java|https://github.com/apache/calcite/blob/4bc916619fd286b2c0cc4d5c653c96a68801d74e/core/src/test/java/org/apache/calcite/test/DiffRepository.java#L231]
> In bazel builds this URL results in a {{jar:}} protocol.
> Here is an example of test that would fail: {{ExampleTest.kt}}:
>  
> {code}
> package com.looker.bazeltest
> import org.apache.calcite.test.DiffRepository
> import org.junit.jupiter.api.Test
> class ExampleTest {
>     @Test
>     fun testFixtureJarResource() {
>         DiffRepository.lookup(ExampleTest::class.java)
>     }
> }
> {code}
>  
> resource {{ExampleTest.xml}}: 
> {code}<?xml version="1.0" ?>
> <Root>
>   <!-- empty file used for location loading test -->
> </Root>
> {code}
> Built with Bazel {{BUILD.bazel}}:
> {code}....
> kt_jvm_test(
>     name = "ExampleTest",
>     srcs = glob(["src/test/kotlin/com/bazeltest/ExampleTest.kt"]),
>     main_class = "org.junit.platform.console.ConsoleLauncher",
>     resources = ["src/test/resources/com/bazeltest/ExampleTest.xml"],
>     deps = [
>         "@maven//:com_google_truth_truth",
>         "@maven//:junit_junit",
>         "@maven//:org_apache_calcite_calcite_testkit",
>         "@maven//:org_junit_jupiter_junit_jupiter_api",
>         "@maven//:org_junit_jupiter_junit_jupiter_engine",
>         "@maven//:org_junit_platform_junit_platform_console",
>     ],
> )
> {code}
> output: 
> {noformat}{{'-- JUnit Jupiter [OK]
> '-- ExampleTest [OK]
> '-- testFixtureJarResource() [X] java.lang.UnsupportedOperationException
> Failures (1):
> JUnit Jupiter:ExampleTest:testFixtureJarResource()
> MethodSource [className = 'com.looker.bazeltest.ExampleTest', methodName = 
> 'testFixtureJarResource', methodParameterTypes = '']
> => com.google.common.util.concurrent.UncheckedExecutionException: 
> java.lang.UnsupportedOperationException
> com.google.common.cache.LocalCache$Segment.get(LocalCache.java:2051)
> com.google.common.cache.LocalCache.get(LocalCache.java:3962)
> com.google.common.cache.LocalCache.getOrLoad(LocalCache.java:3985)
> com.google.common.cache.LocalCache$LocalLoadingCache.get(LocalCache.java:4946)
> com.google.common.cache.LocalCache$LocalLoadingCache.getUnchecked(LocalCache.java:4952)
> [...]
> Caused by: java.lang.UnsupportedOperationException
> org.apache.calcite.util.Sources$FileSource.file(Sources.java:245)
> org.apache.calcite.test.DiffRepository$Key.toRepo(DiffRepository.java:897)
> com.google.common.cache.CacheLoader$FunctionToCacheLoader.load(CacheLoader.java:168)
> com.google.common.cache.LocalCache$LoadingValueReference.loadFuture(LocalCache.java:3529)
> com.google.common.cache.LocalCache$Segment.loadSync(LocalCache.java:2278)
> [...]
> Test run finished after 122 ms
> [ 2 containers found ]
> [ 0 containers skipped ]
> [ 2 containers started ]
> [ 0 containers aborted ]
> [ 2 containers successful ]
> [ 0 containers failed ]
> [ 1 tests found ]
> [ 0 tests skipped ]
> [ 1 tests started ]
> [ 0 tests aborted ]
> [ 0 tests successful ] [ 1 tests failed ]}}
> {noformat}



--
This message was sent by Atlassian Jira
(v8.20.1#820001)

Reply via email to