0

I am using ElasticSearch-1.6.0 using this link to setup ES testing https://www.elastic.co/guide/en/elasticsearch/reference/1.6/using-elasticsearch-test-classes.html and this link for https://www.elastic.co/guide/en/elasticsearch/reference/1.6/integration-tests.html to get the client instance.

Here is the code:

class CampaignESTest extends ElasticsearchIntegrationTest {
val client=ElasticsearchIntegrationTest.cluster().client()

}

But I'm getting a NullPointerException.

This is the stacktrace:

[info] Exception encountered when attempting to run a suite with class name: org.scalatest.DeferredAbortedSuite *** ABORTED ***
[info]   java.lang.NullPointerException:
[info]   at testcontrollers.campaign.CampaignESTest.<init>(CampaignESTest.scala:38)
[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)

CampaignESTest.scala: Line 38 is

val client=ElasticsearchIntegrationTest.cluster().client()

Here is the build.sbt file:

"org.elasticsearch" % "elasticsearch" % "1.6.0",
                "org.elasticsearch" % "elasticsearch" % "1.6.0" % "test" classifier "tests",
                "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",

Why am I getting a NullPointerException? I get the same exception when I do

ElasticsearchIntegrationTest.client()

How can I get the client object ? Also, how can I get a transportClient for testing purposes?

Frank Schmitt
  • 30,195
  • 12
  • 73
  • 107
swaheed
  • 3,671
  • 10
  • 42
  • 103
  • At first glance, it looks like you're trying to call an instance method without an instance. Have you tried `val client =this.cluster().client()` instead? – Frank Schmitt Aug 22 '17 at 10:57
  • getting error Multiple markers at this line: - value cluster is not a member of testcontrollers.campaign.CampaignESTest – swaheed Aug 22 '17 at 11:16

0 Answers0