Java.lang.AssertionError with Integration Tests

I am trying to use the Integration features that now comes with Elasticsearch. So I have my test class annotated with @ClusterScope(scope = Scope.TEST), extending the ElasticsearchIntegrationTest and using the methods createIndex() and Index() to create and index data for testing, but when I run the test I get the following:

java.lang.AssertionError: fix your classpath to have tests-framework.jar before lucene-core.jar
__randomizedtesting.SeedInfo.seed([1B076E861944DDD3]:0)
org.apache.lucene.util.TestRuleSetupAndRestoreClassEnv.before(TestRuleSetupAndRestoreClassEnv.java:219)
org.apache.lucene.util.AbstractBeforeAfterRule$1.evaluate(AbstractBeforeAfterRule.java:45)
org.apache.lucene.util.TestRuleStoreClassName$1.evaluate(TestRuleStoreClassName.java:42)
[...com.carrotsearch.randomizedtesting.]
org.apache.lucene.util.TestRuleAssertionsRequired$1.evaluate(TestRuleAssertionsRequired.java:54)
org.apache.lucene.util.TestRuleMarkFailure$1.evaluate(TestRuleMarkFailure.java:48)
org.apache.lucene.util.TestRuleIgnoreAfterMaxFailures$1.evaluate(TestRuleIgnoreAfterMaxFailures.java:65)
org.apache.lucene.util.TestRuleIgnoreTestSuites$1.evaluate(TestRuleIgnoreTestSuites.java:55)
[...com.carrotsearch.randomizedtesting.
]
java.lang.Thread.run(Thread.java:745)

Any idea on how to fix this? Thanks!

1 Like

Yes. Put the test-framework before elasticsearch in your pom.xml.

Something like https://github.com/elastic/elasticsearch/blob/master/plugins/pom.xml#L27-L55

Thanks @dadoonet for the reply.
Yes, I have my dependencies ordered in a similar fashion, although I noticed I was missing

<dependency>
            <groupId>org.elasticsearch</groupId>
            <artifactId>elasticsearch</artifactId>
            <type>zip</type>
            <scope>test</scope>
</dependency>

in my dependencies; added it and it is still the same. I am running the test as a Junit test from within an IDE (IntelliJ) but the strange thing is the exception pops up randomly. Sometimes it runs without that exception, at most time, it throws it. That is the part I am not clear on what exactly is going on.

This one is not needed.

What does your pom.xml look like?

Here:

    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-web</artifactId>
    </dependency>

    <dependency>
        <groupId>${project.groupId}</groupId>
        <artifactId>model-module</artifactId>
        <version>0.0.1-SNAPSHOT</version>
    </dependency>

    <dependency>
        <groupId>${project.groupId}</groupId>
        <artifactId>event-module</artifactId>
        <version>0.0.1-SNAPSHOT</version>
    </dependency>

    <dependency>
        <groupId>org.elasticsearch</groupId>
        <artifactId>elasticsearch</artifactId>
    </dependency>

    <dependency>
        <groupId>com.google.guava</groupId>
        <artifactId>guava</artifactId>
    </dependency>


    <!-- Test -->
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-test</artifactId>
    </dependency>
    <dependency>
        <groupId>org.apache.lucene</groupId>
        <artifactId>lucene-test-framework</artifactId>
        <scope>test</scope>
    </dependency>
    <dependency>
        <groupId>org.elasticsearch</groupId>
        <artifactId>elasticsearch</artifactId>
        <version>${es.version}</version>
        <scope>test</scope>
        <type>test-jar</type>
    </dependency>
    <dependency>
        <groupId>org.elasticsearch</groupId>
        <artifactId>elasticsearch</artifactId>
        <version>${es.version}</version>
        <type>zip</type>
        <scope>test</scope>
    </dependency>
</dependencies>

Its interesting as I get the random exception even if I run mvn clean test

After running it successfully for 3 times, the 4th time popped up:

Failed tests: 
  ElasticSearchServiceTest.xx.xxx.ElasticSearchServiceTest fix your classpath to have tests-framework.jar before lucene-core.jar

I have no idea why!

So we agree that lucene-test-framework is not the first one in your pom.xml?

Put it on the very top before anything else.

Sure. But that can't explain the fact it sometimes work, can it?

So now I have my pom as:

<dependencies>
    <!-- Test -->
    <dependency>
        <groupId>org.apache.lucene</groupId>
        <artifactId>lucene-test-framework</artifactId>
        <scope>test</scope>
    </dependency>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-test</artifactId>
    </dependency>
    <dependency>
        <groupId>org.elasticsearch</groupId>
        <artifactId>elasticsearch</artifactId>
        <version>${es.version}</version>
        <scope>test</scope>
        <type>test-jar</type>
    </dependency>
    <dependency>
        <groupId>org.elasticsearch</groupId>
        <artifactId>elasticsearch</artifactId>
        <version>${es.version}</version>
        <type>zip</type>
        <scope>test</scope>
    </dependency>

    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-web</artifactId>
    </dependency>
    <dependency>
        <groupId>${project.groupId}</groupId>
        <artifactId>model-module</artifactId>
        <version>0.0.1-SNAPSHOT</version>
    </dependency>

    <dependency>
        <groupId>${project.groupId}</groupId>
        <artifactId>event-module</artifactId>
        <version>0.0.1-SNAPSHOT</version>
    </dependency>

    <dependency>
        <groupId>org.elasticsearch</groupId>
        <artifactId>elasticsearch</artifactId>
    </dependency>

    <dependency>
        <groupId>com.google.guava</groupId>
        <artifactId>guava</artifactId>
    </dependency>
    
</dependencies>

but now I get this exception:

java.lang.NoSuchFieldError: LUCENE_4_10_4
	at org.elasticsearch.Version.<clinit>(Version.java:226)
	at org.elasticsearch.test.ElasticsearchTestCase.<clinit>(ElasticsearchTestCase.java:87)
	at java.lang.Class.forName0(Native Method)
	at java.lang.Class.forName(Class.java:348)
	at com.carrotsearch.randomizedtesting.RandomizedRunner$1.run(RandomizedRunner.java:562)

Sounds like you are mixing elasticsearch versions between tests/core here. But unsure.

Seems the problem was with discrepancies in the elasticsearch and lucene versions. Checked to see the correct version of lucene to use with the version of elasticsearch I am running with, updated, and everything seems to be fine now...I have ran the test aprox. 10 times now and it consistently pass.

I would still be curious to know though, why I was experiencing the random failings when the version was off?

Anyways, thanks for pointing me in the direction of looking into the dependency versions!