Skip to content

Commit

Permalink
Fixes neo4j-contrib#2878: apoc 4.4.0.4 is reported as incompatible wi…
Browse files Browse the repository at this point in the history
…th neo4j-community-4.4.6 in neo4j.log (neo4j-contrib#2885)
  • Loading branch information
vga91 committed May 27, 2022
1 parent 447c696 commit ed992f6
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 8 deletions.
22 changes: 17 additions & 5 deletions core/src/main/java/apoc/cypher/CypherInitializer.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import apoc.util.Util;
import apoc.version.Version;
import org.apache.commons.configuration2.Configuration;
import org.apache.commons.lang3.StringUtils;
import org.neo4j.common.DependencyResolver;
import org.neo4j.configuration.Config;
import org.neo4j.configuration.GraphDatabaseSettings;
Expand All @@ -19,7 +20,6 @@
import java.util.ConcurrentModificationException;
import java.util.List;
import java.util.Map;
import java.util.Optional;
import java.util.TreeMap;

public class CypherInitializer implements AvailabilityListener {
Expand Down Expand Up @@ -93,10 +93,22 @@ public void available() {
}

// the visibility is public only for testing purpose, it could be private otherwise
public static boolean isVersionDifferent(List<String> versions, String apocFullVersion) {
return Optional.ofNullable(apocFullVersion)
.map(v -> versions.stream().noneMatch(v::startsWith))
.orElse(true);
public static boolean isVersionDifferent(List<String> versions, String apocVersion) {
final String[] apocSplit = splitVersion(apocVersion);
return versions.stream()
.noneMatch(kernelVersion -> {
final String[] kernelSplit = splitVersion(kernelVersion);
return apocSplit != null && kernelSplit != null
&& apocSplit[0].equals(kernelSplit[0])
&& apocSplit[1].equals(kernelSplit[1]);
});
}

private static String[] splitVersion(String completeVersion) {
if (StringUtils.isBlank(completeVersion)) {
return null;
}
return completeVersion.split("[^\\d]");
}

private Collection<String> collectInitializers(boolean isSystemDatabase, Configuration config) {
Expand Down
25 changes: 22 additions & 3 deletions core/src/test/java/apoc/cypher/CypherIsVersionDifferentTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,36 @@

import java.util.List;

import static apoc.cypher.CypherInitializer.isVersionDifferent;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;

public class CypherIsVersionDifferentTest {

@Test
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"));
assertTrue(isVersionDifferent(List.of("3.5"), "4.4.0.2"));
assertTrue(isVersionDifferent(List.of("5_0"), "4.4.0.2"));
assertFalse(isVersionDifferent(List.of("3.5.12"), "3.5.0.9"));
assertFalse(isVersionDifferent(List.of("3.5.12"), "3.5.1.9"));
assertFalse(isVersionDifferent(List.of("4.4.5"), "4.4.0.4"));

// we expect that APOC versioning is always consistent to Neo4j versioning
assertFalse(CypherInitializer.isVersionDifferent(List.of("5_0"), "5_0_0_1"));
assertTrue(isVersionDifferent(List.of(""), "5_2_0_1"));
assertTrue(isVersionDifferent(List.of("5_1_0"), "5_0_0_1"));
assertTrue(isVersionDifferent(List.of("5_1_0"), "5_2_0_1"));
assertTrue(isVersionDifferent(List.of("5_22_1"), "5_2_0_1"));
assertTrue(isVersionDifferent(List.of("5_2_1"), "5_22_0_1"));
assertTrue(isVersionDifferent(List.of("55_2_1"), "5_2_1"));
assertTrue(isVersionDifferent(List.of("55_2_1"), "5_2_1_0_1"));
assertTrue(isVersionDifferent(List.of("51-1-9-9"), "5-1-1-9"));

assertFalse(isVersionDifferent(List.of("4_4_5"), "4.4.0.4"));
assertFalse(isVersionDifferent(List.of("5_1_0"), "5-1-0-1"));
assertFalse(isVersionDifferent(List.of("5_22_1"), "5_22_0_1"));
assertFalse(isVersionDifferent(List.of("5_0"), "5_0_0_1"));
assertFalse(isVersionDifferent(List.of("5_0_1"), "5_0_0_1"));

assertFalse(isVersionDifferent(List.of("5-1-9-9"), "5-1-0-1"));
}
}

0 comments on commit ed992f6

Please sign in to comment.