java - Elasticsearch:在测试类路径中找到jar地狱

我想在ElasticSearch中执行单元测试,以查找我正在使用的Java-test-framework
我正在使用Elasticsearch-1.6.0
并参考这些链接寻求帮助
https://www.elastic.co/guide/en/elasticsearch/reference/1.6/using-elasticsearch-test-classes.html
https://github.com/elastic/elasticsearch/blob/master/core/src/test/java/org/elasticsearch/action/search/SearchRequestBuilderTests.java
这是密码

class CampaignESTest extends ESTestCase {

  def getCLient():MockTransportClient={
     val settings = Settings.builder()
                .put(Environment.PATH_HOME_SETTING.getKey(), Files.createTempDir().toString())
                .build();
     val client = new MockTransportClient(settings);  
     client
  }
 }

class CampaignTestSearch extends PlaySpec{
  val client=new CampaignESTest

val response = client.prepareSearch("dbtest")
      .setTypes(CAMPAIGN_COLLECTION_NAME)
      .setSearchType(SearchType.DFS_QUERY_THEN_FETCH)
      .addFields("uuid","campaignName","artworkID","activationDate","_source")
      .setQuery(query)
      .execute()
      .actionGet()
  }

我得到这些例外
    Exception encountered when attempting to run a suite with class name: org.scalatest.DeferredAbortedSuite *** ABORTED ***
[info]   java.lang.ExceptionInInitializerError:
[info]   at org.elasticsearch.test.ESTestCase.<clinit>(ESTestCase.java:138)
[info]   at testcontrollers.campaign.CampaignTestSearch.<init>(CampaignTestSearch.scala:40)
[info]   at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
[info]   at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
[info]   at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
[info]   at java.lang.reflect.Constructor.newInstance(Constructor.java:423)
[info]   at java.lang.Class.newInstance(Class.java:442)
[info]   at org.scalatest.tools.Framework$ScalaTestTask.execute(Framework.scala:468)
[info]   at sbt.ForkMain$Run$2.call(ForkMain.java:296)
[info]   at sbt.ForkMain$Run$2.call(ForkMain.java:286)
[info]   ...
[info]   Cause: java.lang.RuntimeException: found jar hell in test classpath
[info]   at org.elasticsearch.bootstrap.BootstrapForTesting.<clinit>(BootstrapForTesting.java:90)
[info]   at org.elasticsearch.test.ESTestCase.<clinit>(ESTestCase.java:138)
[info]   at testcontrollers.campaign.CampaignTestSearch.<init>(CampaignTestSearch.scala:40)
[info]   at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
[info]   at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
[info]   at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
[info]   at java.lang.reflect.Constructor.newInstance(Constructor.java:423)
[info]   at java.lang.Class.newInstance(Class.java:442)
[info]   at org.scalatest.tools.Framework$ScalaTestTask.execute(Framework.scala:468)
[info]   at sbt.ForkMain$Run$2.call(ForkMain.java:296)
[info]   ...
[info]   Cause: java.nio.file.NoSuchFileException: /home/testproject/target/web/classes/test
[info]   at sun.nio.fs.UnixException.translateToIOException(UnixException.java:86)
[info]   at sun.nio.fs.UnixException.rethrowAsIOException(UnixException.java:102)
[info]   at sun.nio.fs.UnixException.rethrowAsIOException(UnixException.java:107)
[info]   at sun.nio.fs.UnixFileAttributeViews$Basic.readAttributes(UnixFileAttributeViews.java:55)
[info]   at sun.nio.fs.UnixFileSystemProvider.readAttributes(UnixFileSystemProvider.java:144)
[info]   at sun.nio.fs.LinuxFileSystemProvider.readAttributes(LinuxFileSystemProvider.java:99)
[info]   at java.nio.file.Files.readAttributes(Files.java:1737)
[info]   at java.nio.file.FileTreeWalker.getAttributes(FileTreeWalker.java:219)
[info]   at java.nio.file.FileTreeWalker.visit(FileTreeWalker.java:276)
[info]   at java.nio.file.FileTreeWalker.walk(FileTreeWalker.java:322)

在此行中获取异常
val client=new CampaignESTest

在课堂上
以下是CampaignTestSearch文件中的依赖项
libraryDependencies ++= Seq(filters, 
                "org.scalatest" %% "scalatest" % "2.2.6" % "test"withSources() withJavadoc(),
                "org.scalatestplus" %% "play" % "1.4.0-M3" % "test",
                "com.esotericsoftware.kryo" % "kryo" % "2.10",
                "org.mongodb" %% "casbah" % "2.8.0",
                "org.slf4j" % "slf4j-api" % "1.6.4",
                "org.elasticsearch" % "elasticsearch" % "1.6.0",
                "org.elasticsearch.test" % "framework" % "5.0.0" % "test",
                "org.apache.lucene" % "lucene-test-framework" % "4.10.4" % "test",
                "com.carrotsearch.randomizedtesting" % "randomizedtesting-runner" % "1.6.0" % "test",
                "org.apache.lucene" % "lucene-codecs" % "4.10.4" % "test",
                "org.apache.logging.log4j" % "log4j-core" % "2.8.2",
                "org.apache.logging.log4j" % "log4j-slf4j-impl" % "2.8.2" ,
                "org.apache.logging.log4j" % "log4j-api" % "2.8.2",
                "com.typesafe.akka" %% "akka-actor" % "2.3.6",
                "com.typesafe.akka" % "akka-testkit_2.11" % "2.3.6",
                "ch.qos.logback" % "logback-core" % "1.0.9",
                "com.github.nscala-time" %% "nscala-time" % "2.0.0",
                "com.hazelcast" % "hazelcast" % "3.5",
                "com.hazelcast" % "hazelcast-client" % "3.5",
                "com.twitter" % "chill-bijection_2.11" % "0.7.0",
                "com.github.slugify" % "slugify" % "2.1.3" ,
                "org.mindrot" % "jbcrypt" % "0.3m",
                "org.codehaus.groovy" % "groovy-all" % "2.4.0",
                "org.apache.lucene" % "lucene-expressions" % "4.10.4",
                "com.restfb" % "restfb" % "1.19.0",
                "org.twitter4j" % "twitter4j-core" % "4.0.0",
                "org.scribe" % "scribe" % "1.3.5",
                "com.google.code.gson" % "gson" % "2.6.2",
                "com.google.oauth-client" % "google-oauth-client" % "1.20.0",
                "com.google.api.client" % "google-api-client-auth-oauth2" % "1.2.0-alpha",
                "com.google.api-client" % "google-api-client" % "1.20.0",
                "com.google.http-client" % "google-http-client-jackson" % "1.20.0",
                "com.google.apis" % "google-api-services-oauth2" % "v2-rev120-1.20.0",
                "com.google.oauth-client" % "google-oauth-client-appengine" % "1.20.0",
                "com.google.oauth-client" % "google-oauth-client-java6" % "1.20.0",
                "com.google.oauth-client" % "google-oauth-client-jetty" % "1.20.0",
                "com.google.oauth-client" % "google-oauth-client-servlet" % "1.20.0",
                "com.google.apis" % "google-api-services-calendar" % "v3-rev120-1.19.1",
                "com.google.inject" % "guice" % "3.0",
                "org.mockito" % "mockito-all" % "1.10.19")

如何解决这些异常?我也尝试过这里给出的解决方案
Java Jar hell Runtime Exception
当我试图在包中创建一个类时,它不会让我创建它,说类型已经存在,我也尝试搜索该类,但没有找到,请指导

最佳答案

正如@val所观察到的,ESv5的测试框架不能与ESv1一起工作。
为什么不升级到更新版本的ES?
我记得,旧的v1有一些严重的安全缺陷。加上ES5有更好的性能等。
您可以做的另一件事是通过使用HTTP库(如JestESJC)将测试与准确的es版本分离。

本文翻译自 https://stackoverflow.com/questions/45770719/

网站遵循 CC BY-SA 4.0 协议,转载或引用请注明出处。

标签 java scala elasticsearch elasticsearch-1.6.0


相关文章:

java - logstash org.elasticsearch.discovery.MasterNotDiscoveredException错误

java - Spark如何将作业发送到集群?

xml - 如何还原XML转义字符(XML unescape)?

python - 带有Elasticsearch的python中的“ exceptions.TypeError:列表索引必须是整数而不是str”

java - 为什么我的DataPoints方法被多次调用?

java - Play 2.0 Framework模板引擎中的计算

elasticsearch - 弹性搜索搜索查询返回不正确的结果

java - 我应该将定期作业作为使用Java构建的CRON或JAR运行吗?

java - Wicket ListView为什么只将更改分配到最后一行?

java - Joda格式无效