ClassCastException in ESTestCase + SLF4J

(Jan Ferko) #1


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(
    at org.apache.logging.log4j.core.config.Configurator.setLevel(
    at org.elasticsearch.common.logging.Loggers.setLevel(
    at org.elasticsearch.common.logging.Loggers.setLevel(
    at org.elasticsearch.index.SearchSlowLog.setLevel(
    at org.elasticsearch.index.SearchSlowLog.<init>(
    at org.elasticsearch.index.IndexModule.<init>(
    at org.elasticsearch.indices.IndicesService.createIndexService(
    at org.elasticsearch.indices.IndicesService.createIndex(
    at org.elasticsearch.cluster.metadata.MetaDataIndexTemplateService.validateAndAddTemplate(
    at org.elasticsearch.cluster.metadata.MetaDataIndexTemplateService.access$200(
    at org.elasticsearch.cluster.metadata.MetaDataIndexTemplateService$2.execute(
    at org.elasticsearch.cluster.ClusterStateUpdateTask.execute(
    at org.elasticsearch.cluster.service.ClusterService.runTasksForExecutor(
    at org.elasticsearch.cluster.service.ClusterService$

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

Thank you for your help.

(David Pilato) #2

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:


(Jan Ferko) #3

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

(system) #4

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