Getting Jar Hell


(Prakhar Jain) #1
Caused by: java.lang.IllegalStateException: jar hell!
class: org.mockito.AdditionalAnswers
jar1: /Users/gns9/.gradle/caches/modules-2/files-2.1/org.mockito/mockito-core/1.10.19/e8546f5bef4e061d8dd73895b4e8f40e3fe6effe/mockito-core-1.10.19.jar
jar2: /Users/gns9/.gradle/caches/modules-2/files-2.1/org.mockito/mockito-all/1.9.5/79a8984096fc6591c1e3690e07d41be506356fa5/mockito-all-1.9.5.jar

What I have tried, removing ant-javax.jar
downgrade junit 4.11
and exluded hamcrest from cucumber junit library and junit library

Still there is some place where this dependency for mockito core exist.
I don't know how to remove this dependency.
I am pasting some section of my gradle file for you guys to see.

testCompile (
        'net.sourceforge.pmd:pmd:5.1.1',
        'org.apache.lucene:lucene-expressions:4.10.4',
        'info.cukes:cucumber-java:1.2.4',
        'info.cukes:cucumber-picocontainer:1.2.4'

)
testCompile ('junit:junit:4.11') {
    exclude group: 'org.hamcrest'
}

testCompile ('info.cukes:cucumber-junit:1.2.4') {
    exclude group: 'org.hamcrest'
}

buildscript {
  dependencies {
    classpath (
            'com.github.jengelman.gradle.plugins:shadow:1.2.3',
            'org.apache.ant:ant:1.9.2',
            'org.ow2.asm:asm-all:5.0.2',
            'commons-io:commons-io:2.2',
            'org.codehaus.plexus:plexus-utils:3.0.22',
            'com.google.guava:guava:18.0',
            'org.sonarsource.sonar-runner:sonar-runner-api:2.5.1',
            'org.sonarsource.scanner.gradle:sonarqube-gradle-plugin:1.2'
    )
 }
}

Please help!


(David Pilato) #2

Where is the dependency on elasticsearch? Can't see it.


(Prakhar Jain) #3

Hi, Finally found 1 dependency that was causing it. dropwizard test.
Adding the dependency again:

compile fileTree (dir: 'libs')
compile (
        'io.dropwizard:dropwizard-core:0.9.1',
        'io.dropwizard:dropwizard-client:0.9.1',
        'io.dropwizard:dropwizard-assets:0.9.1',
        'org.apache.commons:commons-lang3:3.4',
        'org.apache.commons:commons-jexl:2.1.1',
        'commons-io:commons-io:2.2',
        'commons-collections:commons-collections:3.2.1',
        'com.wordnik:swagger-core_2.10:1.3.0',
        'com.fasterxml.jackson.module:jackson-module-afterburner:2.1.5',
        'com.tesco.productservice:RSCouchBase:5.3.2',
        'com.tesco.productservice:common-auth:1.0.0',
        'javax.json:javax.json-api:1.0',
        'org.elasticsearch.client:elasticsearch-rest-high-level-client:6.1.1',
        'org.apache.logging.log4j:log4j-to-slf4j:2.9.1',
        'org.apache.logging.log4j:log4j-api:2.9.1',
        'org.apache.logging.log4j:log4j-core:2.9.1'


)

testCompile (
        'net.sourceforge.pmd:pmd:5.1.1',
        'org.apache.lucene:lucene-expressions:4.10.4',
        'info.cukes:cucumber-java:1.2.4',
        'org.elasticsearch.test:framework:6.1.1',
        'org.elasticsearch.client:transport:6.1.1',
        'info.cukes:cucumber-picocontainer:1.2.4'

)
testCompile ('junit:junit:4.11') {
    exclude group: 'org.hamcrest'
}

testCompile ('info.cukes:cucumber-junit:1.2.4') {
    exclude group: 'org.hamcrest'
}

I am getting this error now:

Caused by: java.lang.IllegalStateException: jar hell!
class: javassist.ByteArrayClassPath
jar1: /Users/gns9/.gradle/caches/modules-2/files-2.1/javassist/javassist/3.12.1.GA/526633327faa61aee448a519e8a4d53ec3057885/javassist-3.12.1.GA.jar
jar2: /Users/gns9/.gradle/caches/modules-2/files-2.1/org.javassist/javassist/3.18.1-GA/d9a09f7732226af26bf99f19e2cffe0ae219db5b/javassist-3.18.1-GA.jar

(David Pilato) #4

I'd try to exclude mockito core.


(Prakhar Jain) #5

I have solved this, but now I am getting this error

Assertions mismatch: -ea was not specified but -Dtests.asserts=true

java.lang.Exception: Assertions mismatch: -ea was not specified but -Dtests.asserts=true

	at __randomizedtesting.SeedInfo.seed([3D128401C67BEC61]:0)
	at org.apache.lucene.util.TestRuleAssertionsRequired$1.evaluate(TestRuleAssertionsRequired.java:47)
	at org.apache.lucene.util.TestRuleMarkFailure$1.evaluate(TestRuleMarkFailure.java:47)
	at org.apache.lucene.util.TestRuleIgnoreAfterMaxFailures$1.evaluate(TestRuleIgnoreAfterMaxFailures.java:64)
	at org.apache.lucene.util.TestRuleIgnoreTestSuites$1.evaluate(TestRuleIgnoreTestSuites.java:54)
	at com.carrotsearch.randomizedtesting.rules.StatementAdapter.evaluate(StatementAdapter.java:36)
	at com.carrotsearch.randomizedtesting.ThreadLeakControl$StatementRunner.run(ThreadLeakControl.java:368)
	at java.lang.Thread.run(Thread.java:748)


Test ignored.
REPRODUCE WITH: gradle null -Dtests.seed=3D128401C67BEC61 -Dtests.class=com.tesco.productservice.elasticsearch.ElasticsearchClientTestMethods -Dtests.locale=en-US -Dtests.timezone=Asia/Kolkata
NOTE: Mac OS X 10.12.6 x86_64/Oracle Corporation 1.8.0_151 (64-bit)/cpus=8,threads=1,free=189928872,total=257425408
NOTE: All tests run in this JVM: [ElasticsearchClientTestMethods]
Disconnected from the target VM, address: '127.0.0.1:52379', transport: 'socket'
Exception in thread "Thread-1" java.lang.ClassCastException: org.apache.logging.slf4j.SLF4JLoggerContext cannot be cast to org.apache.logging.log4j.core.LoggerContext
	at org.elasticsearch.test.ESTestCase.lambda$static$0(ESTestCase.java:186)
	at java.lang.Thread.run(Thread.java:748)
Suppressed: java.security.AccessControlException: access denied ("org.elasticsearch.ThreadPermission" "modifyArbitraryThreadGroup")
		at java.security.AccessControlContext.checkPermission(AccessControlContext.java:472)
		at java.security.AccessController.checkPermission(AccessController.java:884)
		at java.lang.SecurityManager.checkPermission(SecurityManager.java:549)
		at org.elasticsearch.SecureSM.checkThreadGroupAccess(SecureSM.java:196)
		at org.elasticsearch.SecureSM.checkAccess(SecureSM.java:143)
		at java.lang.ThreadGroup.checkAccess(ThreadGroup.java:315)
		at java.lang.ThreadGroup.getParent(ThreadGroup.java:167)
		at com.carrotsearch.randomizedtesting.RandomizedContext.context(RandomizedContext.java:240)
		at com.carrotsearch.randomizedtesting.RandomizedContext.current(RandomizedContext.java:134)
		at com.carrotsearch.randomizedtesting.RandomizedRunner.augmentStackTrace(RandomizedRunner.java:1848)
		at com.carrotsearch.randomizedtesting.RunnerThreadGroup.uncaughtException(RunnerThreadGroup.java:20)
		at java.lang.Thread.dispatchUncaughtException(Thread.java:1959)

I have tried this in my gradle file

test {
    exclude '**/functional/**'
    systemProperties 'environment': System.getProperty("environment")
    jvmArgs '-noverify'
    jvmArgs '-ea'
    //include '**/**'

    jacoco {
        excludes = ignoreJacoco
        append = false
        destinationFile = file("$buildDir/jacoco/jacocoTest.exec")
        classDumpFile = file("$buildDir/jacoco/classpathdumps")
    }
}

(David Pilato) #6

Are you trying to start elasticsearch from the JVM or something?


(Prakhar Jain) #7

This is the gradle task to run tests
For that I thought of specifying

jvmArgs '-ea'

How to run test in intellij so that they dont give the error.
I have also tried adding -ea in VM Options of Junit in Run->Edit Configurations. Still the same error.

PS: pardon me, I also don't understand the repository fully as I am new to it and had been assigned to do some work on it.


(Prakhar Jain) #8

-ea on VM Options, it worked.
Is there any way to do it for all tests by default?


(David Pilato) #9

You mean? In IntelliJ?

There is this documentation: https://github.com/elastic/elasticsearch/blob/master/CONTRIBUTING.md#contributing-to-the-elasticsearch-codebase


(Prakhar Jain) #10

That's solved. Thanks.

I am having more trouble to create an instance of elasticsearch for testing purpose.
I am following your guide in below link:
http://david.pilato.fr/blog/2016/10/18/elasticsearch-real-integration-tests-updated-for-ga/

I m having following error:

18:16:19.949 [SUITE-ElasticsearchClientTest-seed#[392140009BB872CA]-worker] DEBUG o.a.h.impl.nio.client.MainClientExec - [exchange: 1] start execution
18:16:19.954 [SUITE-ElasticsearchClientTest-seed#[392140009BB872CA]-worker] DEBUG o.a.h.c.protocol.RequestAddCookies - CookieSpec selected: default
18:16:19.968 [SUITE-ElasticsearchClientTest-seed#[392140009BB872CA]-worker] DEBUG o.a.h.c.protocol.RequestAuthCache - Re-using cached 'basic' auth scheme for http://localhost:9400
18:16:19.969 [SUITE-ElasticsearchClientTest-seed#[392140009BB872CA]-worker] DEBUG o.a.h.c.protocol.RequestAuthCache - No credentials for preemptive authentication
18:16:19.969 [SUITE-ElasticsearchClientTest-seed#[392140009BB872CA]-worker] DEBUG o.a.h.i.n.c.InternalHttpAsyncClient - [exchange: 1] Request connection for {}->http://localhost:9400
18:16:19.970 [SUITE-ElasticsearchClientTest-seed#[392140009BB872CA]-worker] DEBUG o.a.h.i.n.c.PoolingNHttpClientConnectionManager - Connection request: [route: {}->http://localhost:9400][total kept alive: 0; route allocated: 0 of 10; total allocated: 0 of 30]
Unexpected exception
java.security.AccessControlException: access denied ("java.lang.RuntimePermission" "accessClassInPackage.sun.reflect")
	at java.security.AccessControlContext.checkPermission(AccessControlContext.java:472)
	[...]
	at java.lang.Thread.run(Thread.java:748) ~[na:1.8.0_151]
18:16:19.993 [SUITE-ElasticsearchClientTest-seed#[392140009BB872CA]-worker] DEBUG o.a.h.i.n.c.PoolingNHttpClientConnectionManager - Connection manager is shutting down
18:16:19.994 [SUITE-ElasticsearchClientTest-seed#[392140009BB872CA]-worker] DEBUG o.a.h.i.n.c.PoolingNHttpClientConnectionManager - Connection manager shut down
18:16:19.994 [SUITE-ElasticsearchClientTest-seed#[392140009BB872CA]-worker] INFO  it - Stopping integration tests against an external cluster

java.lang.AssertionError: Something wrong is happening. REST Client seemed to raise an exception.

Do I need to start Elasticsearch from Terminal? I want to start test elasticsearch instance from java code for my tests.


(Prakhar Jain) #11
18:16:19.970 [SUITE-ElasticsearchClientTest-seed#[392140009BB872CA]-worker] DEBUG o.a.h.i.n.c.PoolingNHttpClientConnectionManager - Connection request: [route: {}->http://localhost:9400][total kept alive: 0; route allocated: 0 of 10; total allocated: 0 of 30]
Unexpected exception
java.security.AccessControlException: access denied ("java.lang.RuntimePermission" "accessClassInPackage.sun.reflect")
[...][Omitted for brevity]
18:16:19.991 [pool-2-thread-1] DEBUG o.a.h.i.n.c.PoolingNHttpClientConnectionManager - Connection request failed
java.net.ConnectException: Connection refused
	at sun.nio.ch.SocketChannelImpl.checkConnect(Native Method) ~[na:1.8.0_151]
	at sun.nio.ch.SocketChannelImpl.finishConnect(SocketChannelImpl.java:717) ~[na:1.8.0_151]
[...][Omitted for brevity]
18:16:19.991 [pool-2-thread-1] DEBUG o.a.h.i.n.c.InternalHttpAsyncClient - [exchange: 1] connection request failed
18:16:19.992 [pool-2-thread-1] DEBUG org.elasticsearch.client.RestClient - request [GET http://localhost:9400/] failed
java.net.ConnectException: Connection refused
	at sun.nio.ch.SocketChannelImpl.checkConnect(Native Method) ~[na:1.8.0_151]
[...]
18:16:19.992 [pool-2-thread-1] DEBUG org.elasticsearch.client.RestClient - added host [http://localhost:9400] to blacklist
18:16:19.992 [SUITE-ElasticsearchClientTest-seed#[392140009BB872CA]-worker] WARN  it - Integration tests are skipped: [Connection refused]
18:16:19.993 [SUITE-ElasticsearchClientTest-seed#[392140009BB872CA]-worker] ERROR it - Full error is
java.net.ConnectException: Connection refused
	at sun.nio.ch.SocketChannelImpl.checkConnect(Native Method) ~[na:1.8.0_151]
	at sun.nio.ch.SocketChannelImpl.finishConnect(SocketChannelImpl.java:717) ~[na:1.8.0_151]
[...]
18:16:19.993 [SUITE-ElasticsearchClientTest-seed#[392140009BB872CA]-worker] DEBUG o.a.h.i.n.c.PoolingNHttpClientConnectionManager - Connection manager is shutting down
18:16:19.994 [SUITE-ElasticsearchClientTest-seed#[392140009BB872CA]-worker] DEBUG o.a.h.i.n.c.PoolingNHttpClientConnectionManager - Connection manager shut down
18:16:19.994 [SUITE-ElasticsearchClientTest-seed#[392140009BB872CA]-worker] INFO  it - Stopping integration tests against an external cluster

java.lang.AssertionError: Something wrong is happening. REST Client seemed to raise an exception.

	at __randomizedtesting.SeedInfo.seed([392140009BB872CA]:0)
	at org.junit.Assert.fail(Assert.java:88)
	at com.tesco.productservice.utils.ElasticsearchTestClient.startRestClient(ElasticsearchTestClient.java:36)
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
[,,,]
Exception in thread "main" java.lang.reflect.InvocationTargetException
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
[...]
Exception in thread "Thread-1" java.lang.ClassCastException: org.apache.logging.slf4j.SLF4JLoggerContext cannot be cast to org.apache.logging.log4j.core.LoggerContext

(David Pilato) #12

I want to start test elasticsearch instance from java code for my tests.

It's not supported. See https://www.elastic.co/blog/elasticsearch-the-server

Read this for some options:


(system) #13

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.