Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[MiVboeTJ] Fixes slf4j apoc logger #274

Merged
merged 1 commit into from
Jan 9, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions common/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,8 @@ dependencies {
api group: 'com.jayway.jsonpath', name: 'json-path', version: '2.7.0'
api group: 'org.hdrhistogram', name: 'HdrHistogram', version: '2.1.9'
api group: 'org.apache.commons', name: 'commons-collections4', version: '4.2'
// We need this to avoid seeing SLF4J: Failed to load class "org.slf4j.impl.StaticLoggerBinder" on startup
api group: 'org.slf4j', name: 'slf4j-simple', version: '1.7.36'

// We need to force this dependency's verion due to a vulnerability https://github.com/neo4j-contrib/neo4j-apoc-procedures/issues/3048
api group: 'org.apache.commons', name: 'commons-lang3', {
Expand Down
10 changes: 8 additions & 2 deletions test-startup/src/test/java/StartupTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,9 @@
import java.util.stream.Collectors;

import static apoc.util.TestContainerUtil.createDB;
import static apoc.util.TestContainerUtil.dockerImageForNeo4j;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;

Expand All @@ -35,17 +37,21 @@ public void check_basic_deployment() {
int procedureCount = session.run("SHOW PROCEDURES YIELD name WHERE name STARTS WITH 'apoc' RETURN count(*) AS count").peek().get("count").asInt();
int functionCount = session.run("SHOW FUNCTIONS YIELD name WHERE name STARTS WITH 'apoc' RETURN count(*) AS count").peek().get("count").asInt();
int coreCount = session.run("CALL apoc.help('') YIELD core WHERE core = true RETURN count(*) AS count").peek().get("count").asInt();
String startupLog = neo4jContainer.getLogs();

assertTrue(procedureCount > 0);
assertTrue(functionCount > 0);
assertTrue(coreCount > 0);
// Check there's one and only one logger for apoc inside the container
assertFalse(startupLog.contains("SLF4J: Failed to load class \"org.slf4j.impl.StaticLoggerBinder\""));
assertFalse(startupLog.contains("SLF4J: Class path contains multiple SLF4J providers"));
} catch (Exception ex) {
// if Testcontainers wasn't able to retrieve the docker image we ignore the test
if (TestContainerUtil.isDockerImageAvailable(ex)) {
ex.printStackTrace();
fail("Should not have thrown exception when trying to start Neo4j: " + ex);
} else if (!TestUtil.isRunningInCI()) {
fail( "The docker image " + TestContainerUtil.neo4jEnterpriseDockerImageVersion + " should be available in the CI. Exception:" + ex);
fail( "The docker image " + dockerImageForNeo4j(version) + " could not be loaded. Check whether it's available locally / in the CI. Exception:" + ex);
}
}
}
Expand Down Expand Up @@ -74,7 +80,7 @@ public void compare_with_sources() {
ex.printStackTrace();
fail("Should not have thrown exception when trying to start Neo4j: " + ex);
} else {
fail( "The docker image " + TestContainerUtil.neo4jEnterpriseDockerImageVersion + " should be available in the CI. Exception:" + ex);
fail( "The docker image " + dockerImageForNeo4j(version) + " could not be loaded. Check whether it's available locally / in the CI. Exception:" + ex);
}
}
}
Expand Down
12 changes: 9 additions & 3 deletions test-utils/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,21 @@ dependencies {
exclude group: 'org.apache.hive', module: 'hive-service'
}

// The logger will come from the :common project via slf4j-simple
def withoutLoggers = {
exclude group: 'org.slf4j', module: 'slf4j-log4j12'
exclude group: 'org.slf4j', module: 'slf4j-reload4j'
}

api group: 'junit', name: 'junit', version: '4.13.2'
api group: 'org.hamcrest', name: 'hamcrest', version: '2.2'
api group: 'org.hamcrest', name: 'hamcrest-library', version: '2.2'
api group: 'org.neo4j.community', name: 'it-test-support', version: neo4jVersionEffective // , classifier: "tests"
api group: 'org.neo4j', name: 'log-test-utils', version: neo4jVersionEffective // , classifier: "tests"
api group: 'org.neo4j.driver', name: 'neo4j-java-driver', version: '4.0.0'
api group: 'org.apache.hadoop', name: 'hadoop-hdfs', version: '3.3.4', withoutServers
api group: 'org.apache.hadoop', name: 'hadoop-common', version: '3.3.4', withoutServers
api group: 'org.apache.hadoop', name: 'hadoop-minicluster', version: '3.3.4', withoutServers
api group: 'org.apache.hadoop', name: 'hadoop-hdfs', version: '3.3.4', withoutServers.andThen(withoutLoggers)
nadja-muller marked this conversation as resolved.
Show resolved Hide resolved
api group: 'org.apache.hadoop', name: 'hadoop-common', version: '3.3.4', withoutServers.andThen(withoutLoggers)
api group: 'org.apache.hadoop', name: 'hadoop-minicluster', version: '3.3.4', withoutServers.andThen(withoutLoggers)
api group: 'org.testcontainers', name: 'testcontainers', version: testContainersVersion
api group: 'org.testcontainers', name: 'neo4j', version: testContainersVersion
api group: 'org.testcontainers', name: 'elasticsearch', version: testContainersVersion
Expand Down
7 changes: 7 additions & 0 deletions test-utils/src/main/java/apoc/util/TestContainerUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,13 @@ private TestContainerUtil() {}
private static File coreDir = new File(baseDir, System.getProperty("coreDir"));
private static File extendedDir = new File(baseDir, "extended");

public static String dockerImageForNeo4j(Neo4jVersion version) {
if (version == Neo4jVersion.COMMUNITY)
return neo4jCommunityDockerImageVersion;
else
return neo4jEnterpriseDockerImageVersion;
}

public static TestcontainersCausalCluster createEnterpriseCluster(List<ApocPackage> apocPackages, int numOfCoreInstances, int numberOfReadReplica, Map<String, Object> neo4jConfig, Map<String, String> envSettings) {
return TestcontainersCausalCluster.create(apocPackages, numOfCoreInstances, numberOfReadReplica, Duration.ofMinutes(4), neo4jConfig, envSettings);
}
Expand Down