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

Fixes #2878: apoc 4.4.0.4 is reported as incompatible with neo4j-community-4.4.6 in neo4j.log #2885

Merged
merged 2 commits into from
May 20, 2022
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
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"));
}
}