0

I want to perform unit testing in Elasticsearch for that I am using Java-test-framework
I am using Elasticsearch-1.6.0 and referring to these link for help 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

here is the code

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()
  }

I am getting this exception

Exception encountered when attempting to run a suite with class name: org.scalatest.DeferredAbortedSuite *** ABORTED ***
[info]   java.lang.NoClassDefFoundError: org/apache/lucene/codecs/simpletext/SimpleTextCodec
[info]   at org.apache.lucene.util.LuceneTestCase.<clinit>(LuceneTestCase.java:616)
[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.ClassNotFoundException: org.apache.lucene.codecs.simpletext.SimpleTextCodec
[info]   at java.net.URLClassLoader.findClass(URLClassLoader.java:381)
[info]   at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
[info]   at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:331)
[info]   at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
[info]   at org.apache.lucene.util.LuceneTestCase.<clinit>(LuceneTestCase.java:616)
[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]   ...

getting an exception on this line

val client=new CampaignESTest

in class CampaignTestSearch

here is the dependencies in build.sbt file

"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.a"org.apache.lucene" % "lucene-expressions" % "4.10.4",
                pache.lucene" % "lucene-backward-codecs" % "5.4.0",

i suspect the cause of the exception maybe due to some versions of the dependencies can anyone please help with the correct library dependency version to make it to work or is tehre something else which i am missing

swaheed
  • 3,671
  • 10
  • 42
  • 103

1 Answers1

2

Two problems:

  • SimpleTextCodec is in codecs, not backwards-codecs.

  • You are using a jar from lucene 5.4.0. Never mix-and-match your lucene versions. Elasticsearch 1.6.0 is designed to work with lucene 4.10.4. Mixing in a jar from lucene 5.4.0 can only cause problems for you.

femtoRgon
  • 32,893
  • 7
  • 60
  • 87
  • that exception was resolved thanks but I am getting an another exception https://stackoverflow.com/questions/45768480/java-lang-noclassdeffounderror-org-apache-logging-log4j-logger – swaheed Aug 19 '17 at 06:35