diff --git a/core/src/main/java/apoc/cypher/CypherInitializer.java b/core/src/main/java/apoc/cypher/CypherInitializer.java index dfd3b6742a..f65f8ed61c 100644 --- a/core/src/main/java/apoc/cypher/CypherInitializer.java +++ b/core/src/main/java/apoc/cypher/CypherInitializer.java @@ -33,7 +33,6 @@ public class CypherInitializer implements AvailabilityListener { * indicates the status of the initializer, to be used for tests to ensure initializer operations are already done */ private boolean finished = false; - private boolean checkedVersion = false; public CypherInitializer(GraphDatabaseAPI db, Log userLog) { this.db = db; @@ -65,19 +64,13 @@ public void available() { } if (defaultDb.equals(db.databaseName())) { - try { - final String apocFullVersion = Version.class.getPackage().getImplementationVersion(); - final String apocVersion = getMajorMinVersion(apocFullVersion); - final List versions = db.executeTransactionally("CALL dbms.components", Collections.emptyMap(), - r -> (List) r.next().get("versions")); - final boolean versionDifferent = versions.stream().noneMatch(kernelVersion -> getMajorMinVersion(kernelVersion).equals(apocVersion)); - if (versionDifferent) { - userLog.warn("The apoc version (%s) and the Neo4j DBMS versions %s are incompatible. \n" + - "See the compatibility matrix in https://neo4j.com/labs/apoc/4.4/installation/ to see the correct version", - apocFullVersion, versions.toString()); - } - } catch (Exception ignored) { - // with embedded testdb, "call dbms.components" is not recognized here + final List versions = db.executeTransactionally("CALL dbms.components", Collections.emptyMap(), + r -> (List) r.next().get("versions")); + final String apocFullVersion = Version.class.getPackage().getImplementationVersion(); + if (isVersionDifferent(versions, apocFullVersion)) { + userLog.warn("The apoc version (%s) and the Neo4j DBMS versions %s are incompatible. \n" + + "See the compatibility matrix in https://neo4j.com/labs/apoc/4.4/installation/ to see the correct version", + apocFullVersion, versions.toString()); } } Configuration config = dependencyResolver.resolveDependency(ApocConfig.class).getConfig(); @@ -98,12 +91,9 @@ public void available() { }).start(); } - private String getMajorMinVersion(String completeVersion) { - if (completeVersion == null) { - return null; - } - final String[] split = completeVersion.split("\\."); - return split[0] + "." + split[1]; + // only for testing purpose + public static boolean isVersionDifferent(List versions, String apocFullVersion) { + return versions.stream().noneMatch(apocFullVersion::startsWith); } private Collection collectInitializers(boolean isSystemDatabase, Configuration config) { diff --git a/core/src/test/java/apoc/cypher/CypherInitializerTest.java b/core/src/test/java/apoc/cypher/CypherInitializerTest.java index 967753d1f8..fe8ee38577 100644 --- a/core/src/test/java/apoc/cypher/CypherInitializerTest.java +++ b/core/src/test/java/apoc/cypher/CypherInitializerTest.java @@ -16,15 +16,21 @@ import org.neo4j.kernel.availability.AvailabilityListener; import org.neo4j.kernel.availability.DatabaseAvailabilityGuard; import org.neo4j.kernel.internal.GraphDatabaseAPI; +import org.neo4j.logging.NullLog; +import org.neo4j.procedure.Procedure; import org.neo4j.test.ReflectionUtil; import org.neo4j.test.rule.DbmsRule; import org.neo4j.test.rule.ImpermanentDbmsRule; import java.util.Collections; +import java.util.List; +import java.util.stream.Stream; import static apoc.ApocConfig.APOC_CONFIG_INITIALIZER; import static apoc.ApocConfig.APOC_CONFIG_INITIALIZER_CYPHER; import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertTrue; import static org.neo4j.configuration.GraphDatabaseSettings.DEFAULT_DATABASE_NAME; import static org.neo4j.configuration.GraphDatabaseSettings.SYSTEM_DATABASE_NAME; @@ -76,6 +82,16 @@ private CypherInitializer getInitializer(String dbName) { } } + + @Test + @Env + public void shouldReturnFalseOnlyWithCompatibleVersion() { + assertTrue(CypherInitializer.isVersionDifferent(List.of("3.5"), "4.4.0.2")); + assertTrue(CypherInitializer.isVersionDifferent(List.of("5_0"), "4.4.0.2")); + + // we expect that APOC versioning is always consistent to Neo4j versioning + assertFalse(CypherInitializer.isVersionDifferent(List.of("5_0"), "5_0_0_1")); + } @Test @Env @@ -130,4 +146,5 @@ public void databaseSpecificInitializersForSystem() { private void expectNodeCount(long i) { assertEquals(i, TestUtil.count(dbmsRule, "match (n) return n")); } + }