ELasticSearch: found jar hell in test classpath

2020-07-18 03:16发布

问题:

I am trying to get MockTransportClient here is the code

 class CampaignTest extends ESIntegTestCase {
  var client: Client = null
   @Before def initClient(): Unit = { 
    val file = Files.createTempDirectory("tempESData")
    val settings = Settings.builder()
      .put("http.enabled", "false")
      .put("path.data", file.toString()).build()
    client = new MockTransportClient(settings)
  }
  @Test def myTest(): Unit = {
    println("client is"+client)
  }

  @After def closeClient(): Unit = {
    client.close() //close client after test
    client = null
  }

and its throwing exception

[error] Test testcontrollers.campaign.CampaignTest failed: java.lang.RuntimeException: found jar hell in test classpath, took 0.0 sec
[error]     at org.elasticsearch.bootstrap.BootstrapForTesting.<clinit>(BootstrapForTesting.java:91)
[error]     at org.elasticsearch.test.ESTestCase.<clinit>(ESTestCase.java:178)
[error]     at java.lang.Class.forName0(Native Method)
[error]     at java.lang.Class.forName(Class.java:348)
[error]     at com.carrotsearch.randomizedtesting.RandomizedRunner$2.run(RandomizedRunner.java:620)
[error] Caused by: java.nio.file.NoSuchFileException: /home/myproject/target/web/classes/test
[error]     at sun.nio.fs.UnixException.translateToIOException(UnixException.java:86)
[error]     at sun.nio.fs.UnixException.rethrowAsIOException(UnixException.java:102)
[error]     at sun.nio.fs.UnixException.rethrowAsIOException(UnixException.java:107)
[error]     at sun.nio.fs.UnixFileAttributeViews$Basic.readAttributes(UnixFileAttributeViews.java:55)
[error]     at sun.nio.fs.UnixFileSystemProvider.readAttributes(UnixFileSystemProvider.java:144)
[error]     at sun.nio.fs.LinuxFileSystemProvider.readAttributes(LinuxFileSystemProvider.java:99)
[error]     at java.nio.file.Files.readAttributes(Files.java:1737)
[error]     at java.nio.file.FileTreeWalker.getAttributes(FileTreeWalker.java:219)
[error]     at java.nio.file.FileTreeWalker.visit(FileTreeWalker.java:276)
[error]     at java.nio.file.FileTreeWalker.walk(FileTreeWalker.java:322)
[error]     at java.nio.file.Files.walkFileTree(Files.java:2662)
[error]     at java.nio.file.Files.walkFileTree(Files.java:2742)
[error]     at org.elasticsearch.bootstrap.JarHell.checkJarHell(JarHell.java:201)
[error]     at org.elasticsearch.bootstrap.JarHell.checkJarHell(JarHell.java:90)
[error]     at org.elasticsearch.bootstrap.BootstrapForTesting.<clinit>(BootstrapForTesting.java:89)
[error]     ... 4 more
Exception in thread "Thread-1" java.lang.NoClassDefFoundError: Could not initialize class org.elasticsearch.test.ESTestCase
    at java.lang.Thread.run(Thread.java:745)
    Suppressed: java.lang.IllegalStateException: No context information for thread: Thread[id=13, name=Thread-1, state=RUNNABLE, group=TGRP-CampaignTest]. Is this thread running under a class com.carrotsearch.randomizedtesting.RandomizedRunner runner context? Add @RunWith(class com.carrotsearch.randomizedtesting.RandomizedRunner.class) to your test class. Make sure your code accesses random contexts within @BeforeClass and @AfterClass boundary (for example, static test class initializers are not permitted to access random contexts).
        at com.carrotsearch.randomizedtesting.RandomizedContext.context(RandomizedContext.java:248)
        at com.carrotsearch.randomizedtesting.RandomizedContext.current(RandomizedContext.java:134)
        at com.carrotsearch.randomizedtesting.RandomizedRunner.augmentStackTrace(RandomizedRunner.java:1872)
        at com.carrotsearch.randomizedtesting.RunnerThreadGroup.uncaughtException(RunnerThreadGroup.java:20)
        at java.lang.Thread.dispatchUncaughtException(Thread.java:1956)
[info] ScalaTest
[info] Run completed in 10 seconds, 706 milliseconds.
[info] Total number of tests run: 0
[info] Suites: completed 0, aborted 0
[info] Tests: succeeded 0, failed 0, canceled 0, ignored 0, pending 0
[info] No tests were executed.
[error] Failed: Total 1, Failed 1, Errors 0, Passed 0
[error] Failed tests:
[error]     testcontrollers.campaign.CampaignTest
[error] (arteciate/test:testOnly) sbt.TestsFailedException: Tests unsuccessful
[error] Total time: 21 s, completed Oct 6, 2017 6:00:09 PM

here are the libraries being used

"org.elasticsearch" % "elasticsearch" % "5.6.0",
                "org.elasticsearch.client" % "transport" % "5.6.0",
                "org.apache.lucene" % "lucene-expressions" % "6.6.0",
                "org.apache.logging.log4j" % "log4j-core" % "2.9.0",
                "org.apache.lucene" % "lucene-test-framework" % "6.6.0" % "test" ,
                "org.elasticsearch.test" % "framework" % "5.5.2" % "test",