ClassCastException in ESTestCase + SLF4J

Hi,

I tried to use ESSingleNodeTestCase (Elasticsearch v5.0.1) in my project, but tests throw following exception:

java.lang.ClassCastException: org.apache.logging.slf4j.SLF4JLoggerContext cannot be cast to org.apache.logging.log4j.core.LoggerContext
    at __randomizedtesting.SeedInfo.seed([281258191F6A65AD:4F71E07F941ECA0E]:0)
    at org.apache.logging.log4j.core.LoggerContext.getContext(LoggerContext.java:178)
    at org.apache.logging.log4j.core.config.Configurator.setLevel(Configurator.java:290)
    at org.elasticsearch.common.logging.Loggers.setLevel(Loggers.java:149)
    at org.elasticsearch.common.logging.Loggers.setLevel(Loggers.java:144)
    at org.elasticsearch.index.SearchSlowLog.setLevel(SearchSlowLog.java:114)
    at org.elasticsearch.index.SearchSlowLog.<init>(SearchSlowLog.java:109)
    at org.elasticsearch.index.IndexModule.<init>(IndexModule.java:114)
    at org.elasticsearch.indices.IndicesService.createIndexService(IndicesService.java:406)
    at org.elasticsearch.indices.IndicesService.createIndex(IndicesService.java:378)
    at org.elasticsearch.cluster.metadata.MetaDataIndexTemplateService.validateAndAddTemplate(MetaDataIndexTemplateService.java:210)
    at org.elasticsearch.cluster.metadata.MetaDataIndexTemplateService.access$200(MetaDataIndexTemplateService.java:60)
    at org.elasticsearch.cluster.metadata.MetaDataIndexTemplateService$2.execute(MetaDataIndexTemplateService.java:170)
    at org.elasticsearch.cluster.ClusterStateUpdateTask.execute(ClusterStateUpdateTask.java:45)
    at org.elasticsearch.cluster.service.ClusterService.runTasksForExecutor(ClusterService.java:555)
    at org.elasticsearch.cluster.service.ClusterService$UpdateTask.run(ClusterService.java:896)

From what I was able to diagnose, the problem is caused by using Elasticsearch testing framework together with SLF4J + Logback. ES node tries to setup its logging by accessing log4j2-core LoggerContext, which isn't available because we use SLF4J bridge. Is there a workaround?
I've created minimal project that reproduces error and can be found here https://github.com/iref/es-slf4j-test-error

Thank you for your help.

You can not embed elasticsearch like in tests without using the exact libs elasticsearch requires.
So SLF4J + Logback is not supported here.

You'd better run an external elasticsearch cluster for your tests.
I described a cookbook here for Maven: http://david.pilato.fr/blog/2016/10/18/elasticsearch-real-integration-tests-updated-for-ga/

HTH

I was afraid that is the case. Thank you for link, I'll tak a look.

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