Testing Neo4j Enterprise Edition

0

I am trying to test a property existence constraint which is an Enterprise Edition feature, so I have switched to enterprise libraries in the Gradle build:

    implementation group: 'org.neo4j.driver', name: 'neo4j-java-driver', version: '4.4.2'
    implementation group: 'org.neo4j', name: 'neo4j-enterprise', version: '3.5.0-beta01'
    implementation group: 'org.neo4j', name: 'neo4j-cypher-dsl', version: '2021.4.2'

    testImplementation group: 'org.neo4j.test', name: 'neo4j-harness-enterprise', version: '3.5.0-beta01'

Below is the test class:

@TestInstance(TestInstance.Lifecycle.PER_CLASS)
public class ExistenceConstraintTest {

    private final Driver driver;

    public ExistenceConstraintTest() {
        ServerControls serverControls = TestServerBuilders.newInProcessBuilder()
//                .withConfig("gds.enterprise.license_file", "/path/to/my/license/keyfile")
                .newServer();
        driver = GraphDatabase.driver(serverControls.boltURI());
    }

    @BeforeAll
    void createConstraints() {
        try (Session session = driver.session()) {
            session.run("CREATE CONSTRAINT " +
                    "ON (node:Label) " +
                    "ASSERT EXISTS(node.property)");
        }
    }

    @Test
    void test() {

    }
}

The withConfig line with the path to the license file is commented out because I am not sure whether it is needed. When I run this, I get the following error:

org.neo4j.driver.exceptions.DatabaseException: Unable to create CONSTRAINT ON ( label:Label ) ASSERT exists(label.property):
Property existence constraint requires Neo4j Enterprise Edition

The error suggests that the test still uses the Community Edition despite the Gradle configuration. Is there anything I am missing in the build or config?

Also, I have to use the old-style syntax with ASSERT in the constraint because the current version of neo4j-harness-enterprise fails with the new style:

org.neo4j.driver.exceptions.ClientException: Invalid input ' ': expected 'e/E' (line 1, column 22 (offset: 21))
"CREATE CONSTRAINT FOR (node:Label) REQUIRE Label.property IS NOT NULL"

I think you call to 'newInProcessBuilder()' creates a community edition. I have seen equivalent methods that have Enterprise in the method name, such as EnterpriseInProcessServerBuilder.

1 Like

Thank you! This works:

@TestInstance(TestInstance.Lifecycle.PER_CLASS)
public class ExistenceConstraintTest {

    private final Driver driver;

    public ExistenceConstraintTest() {
        ServerControls serverControls = new EnterpriseInProcessServerBuilder()
                .newServer();
        driver = GraphDatabase.driver(serverControls.boltURI());
    }

    @BeforeAll
    void createConstraints() {
        try (Session session = driver.session()) {
            session.run("CREATE CONSTRAINT " +
                    "ON (node:Label) " +
                    "ASSERT EXISTS(node.property)");
        }
    }

    @Test
    void test() {

    }
}

I still have the problem with deprecated syntax. REQUIRE clause is not recognized by the current version of harness-enterprise unfortunately. Apparently, the harness-enterprise versions are lagging behind: 3.5.0 vs 4.4.2.