You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@calcite.apache.org by "Marieke Gueye (Jira)" <ji...@apache.org> on 2022/03/18 22:05:00 UTC

[jira] [Created] (CALCITE-5052) Calcite testkit issue loading resources from jar in DiffRepository (bazel)

Marieke Gueye created CALCITE-5052:
--------------------------------------

             Summary: 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


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: [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: [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`

```

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)
    }
}
```
resource `ExampleTest.xml`

```
<?xml version="1.0" ?>
<Root>
  <!-- empty file used for location loading test -->
</Root>
```
Built with Bazel `BUILD.bazel`


```

....

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",
    ],
)
```

output:

```

{{'-- 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 ]}}

```



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