From 9cc1a3da8bc4fd1018fb0afe9e0d49c3edb555d8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Florentin=20D=C3=B6rre?= Date: Tue, 18 Jul 2023 07:50:57 +0200 Subject: [PATCH 1/7] Automate doc tests of gds.ephemeral.database.create * database attribute to code blocks * enterprise db creation * avoid inheritance from BaseProcTest in DocTest --- .../doc/DocumentationTestToolsConstants.java | 2 + .../neo4j/gds/doc/MultiFileDocTestBase.java | 88 ++++++++++++++----- .../gds/doc/QueryCollectingTreeProcessor.java | 5 ++ .../org/neo4j/gds/doc/syntax/DocQuery.java | 4 + .../doc/QueryCollectingTreeProcessorTest.java | 16 ++++ ...llecting-tree-processor-test_database.adoc | 8 ++ .../gds/doc/ModelCatalogDocTestBase.java | 1 + .../java/org/neo4j/gds/doc/WccDocTest.java | 2 +- .../graph-reads/read-with-cypher.adoc | 9 +- .../ephemeral-db/create-example.adoc | 27 +++--- .../ephemeral-db/drop-example.adoc | 11 +-- 11 files changed, 132 insertions(+), 41 deletions(-) create mode 100644 doc-test-tools/src/test/resources/query-collecting-tree-processor-test_database.adoc diff --git a/doc-test-tools/src/main/java/org/neo4j/gds/doc/DocumentationTestToolsConstants.java b/doc-test-tools/src/main/java/org/neo4j/gds/doc/DocumentationTestToolsConstants.java index 961de0015b9..63e61e8906f 100644 --- a/doc-test-tools/src/main/java/org/neo4j/gds/doc/DocumentationTestToolsConstants.java +++ b/doc-test-tools/src/main/java/org/neo4j/gds/doc/DocumentationTestToolsConstants.java @@ -48,6 +48,8 @@ final class DocumentationTestToolsConstants { static final String GRAPH_PROJECT_QUERY_ROLE = "graph-project-query"; static final String QUERY_EXAMPLE_ROLE = "query-example"; static final String TEST_TYPE_NO_RESULT = "no-result"; + + static final String TEST_DATABASE_ATTRIBUTE = "database"; static final String TEST_GROUP_ATTRIBUTE = "group"; static final String TEST_OPERATOR_ATTRIBUTE = "operator"; static final String ROLE_SELECTOR = "role"; diff --git a/doc-test-tools/src/main/java/org/neo4j/gds/doc/MultiFileDocTestBase.java b/doc-test-tools/src/main/java/org/neo4j/gds/doc/MultiFileDocTestBase.java index a20d9ca4a81..3495fdf7e78 100644 --- a/doc-test-tools/src/main/java/org/neo4j/gds/doc/MultiFileDocTestBase.java +++ b/doc-test-tools/src/main/java/org/neo4j/gds/doc/MultiFileDocTestBase.java @@ -24,15 +24,22 @@ import org.asciidoctor.SafeMode; import org.assertj.core.api.Assertions; import org.jetbrains.annotations.NotNull; +import org.junit.jupiter.api.AfterEach; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.DynamicTest; import org.junit.jupiter.api.TestFactory; import org.junit.jupiter.api.io.TempDir; -import org.neo4j.gds.BaseProcTest; +import org.neo4j.dbms.api.DatabaseManagementService; +import org.neo4j.gds.QueryRunner; import org.neo4j.gds.compat.CompatUserAggregationFunction; +import org.neo4j.gds.core.Settings; import org.neo4j.gds.core.loading.GraphStoreCatalog; import org.neo4j.gds.doc.syntax.DocQuery; +import org.neo4j.graphdb.GraphDatabaseService; import org.neo4j.graphdb.Result; +import org.neo4j.io.layout.Neo4jLayout; +import org.neo4j.test.TestDatabaseManagementServiceBuilder; +import org.neo4j.test.extension.Inject; import java.io.File; import java.nio.file.Path; @@ -44,27 +51,40 @@ import java.util.function.Consumer; import java.util.stream.Collectors; +import static java.util.Collections.singletonList; import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.AssertionsForClassTypes.assertThatNoException; import static org.junit.jupiter.api.DynamicTest.dynamicTest; +import static org.neo4j.gds.compat.GraphDatabaseApiProxy.registerAggregationFunctions; +import static org.neo4j.gds.compat.GraphDatabaseApiProxy.registerFunctions; +import static org.neo4j.gds.compat.GraphDatabaseApiProxy.registerProcedures; -public abstract class MultiFileDocTestBase extends BaseProcTest { +public abstract class MultiFileDocTestBase { private List beforeEachQueries; private List beforeAllQueries; private List queryExampleGroups; + @Inject + protected DatabaseManagementService dbms; + + protected GraphDatabaseService defaultDb; + protected abstract List adocPaths(); @BeforeEach void setUp(@TempDir File workingDirectory) throws Exception { + this.dbms = setupDbms(workingDirectory.toPath()); + this.defaultDb = dbms.database("neo4j"); + Class[] clazzArray = new Class[0]; - registerProcedures(procedures().toArray(clazzArray)); - registerFunctions(functions().toArray(clazzArray)); - for (var function : aggregationFunctions()) { - registerAggregationFunction(function); - } + GraphDatabaseService defaultDb = dbms.database("neo4j"); + registerProcedures(defaultDb, procedures().toArray(clazzArray)); + registerFunctions(defaultDb, functions().toArray(clazzArray)); + + registerAggregationFunctions(defaultDb, aggregationFunctions().toArray(Class[]::new)); + var treeProcessor = new QueryCollectingTreeProcessor(); var includeProcessor = new PartialsIncludeProcessor(); @@ -93,6 +113,22 @@ void setUp(@TempDir File workingDirectory) throws Exception { } } + @AfterEach + void tearDownDbms() { + dbms.shutdown(); + } + + protected DatabaseManagementService setupDbms(Path workingDirectory) { + var builder = new TestDatabaseManagementServiceBuilder(Neo4jLayout.of(workingDirectory)); + configureDbms(builder); + return builder.build(); + } + + protected void configureDbms(TestDatabaseManagementServiceBuilder builder) { + builder.noOpSystemGraphInitializer(); + builder.setConfig(Settings.procedureUnrestricted(), singletonList("gds.*")); + } + private List adocFiles() { return adocPaths() .stream() @@ -127,10 +163,9 @@ private void beforeEachTest() { private void runDocQuery(DocQuery docQuery) { try { if (docQuery.runAsOperator()) { - String operatorHandle = docQuery.operator(); - super.runQuery(operatorHandle, docQuery.query()); + QueryRunner.runQuery(dbms.database(docQuery.database()), docQuery.operator(), docQuery.query(), Map.of()); } else { - super.runQuery(docQuery.query()); + QueryRunner.runQuery(dbms.database(docQuery.database()), docQuery.query()); } } catch (Exception e) { throw new RuntimeException("Failed to run query: " + docQuery.query(), e); @@ -152,11 +187,20 @@ private DynamicTest createDynamicTest(QueryExampleGroup queryExampleGroup) { } private void runQueryExampleWithResultConsumer(QueryExample queryExample, Consumer check) { - if (!queryExample.runAsOperator()) { - super.runQueryWithResultConsumer(queryExample.query(), check); + if (queryExample.runAsOperator()) { + QueryRunner.runQueryWithResultConsumer( + dbms.database(queryExample.database()), + queryExample.operator(), + queryExample.query(), + Map.of(), + check + ); } else { - String operatorHandle = queryExample.operator(); - super.runQueryWithResultConsumer(operatorHandle, queryExample.query(), check); + QueryRunner.runQueryWithResultConsumer( + dbms.database(queryExample.database()), + queryExample.query(), + Map.of(), + check); } } @@ -207,15 +251,15 @@ private List> reducePrecisionOfDoubles(Collection> res return resultsFromDoc .stream() .map(list -> list.stream().map(string -> { - try { - if (string.startsWith("[")) { - return formatListOfNumbers(string); + try { + if (string.startsWith("[")) { + return formatListOfNumbers(string); + } + return DocumentationTestToolsConstants.FLOAT_FORMAT.format(Double.parseDouble(string)); + } catch (NumberFormatException e) { + return string; } - return DocumentationTestToolsConstants.FLOAT_FORMAT.format(Double.parseDouble(string)); - } catch (NumberFormatException e) { - return string; - } - }).collect(Collectors.toList()) + }).collect(Collectors.toList()) ) .collect(Collectors.toList()); } diff --git a/doc-test-tools/src/main/java/org/neo4j/gds/doc/QueryCollectingTreeProcessor.java b/doc-test-tools/src/main/java/org/neo4j/gds/doc/QueryCollectingTreeProcessor.java index 0520f72be89..921302f1674 100644 --- a/doc-test-tools/src/main/java/org/neo4j/gds/doc/QueryCollectingTreeProcessor.java +++ b/doc-test-tools/src/main/java/org/neo4j/gds/doc/QueryCollectingTreeProcessor.java @@ -42,6 +42,7 @@ import static org.neo4j.gds.doc.DocumentationTestToolsConstants.ROLE_SELECTOR; import static org.neo4j.gds.doc.DocumentationTestToolsConstants.SETUP_QUERY_ROLE; import static org.neo4j.gds.doc.DocumentationTestToolsConstants.TABLE_CONTEXT; +import static org.neo4j.gds.doc.DocumentationTestToolsConstants.TEST_DATABASE_ATTRIBUTE; import static org.neo4j.gds.doc.DocumentationTestToolsConstants.TEST_GROUP_ATTRIBUTE; import static org.neo4j.gds.doc.DocumentationTestToolsConstants.TEST_OPERATOR_ATTRIBUTE; import static org.neo4j.gds.doc.DocumentationTestToolsConstants.TEST_TYPE_NO_RESULT; @@ -163,6 +164,10 @@ private QueryExample convertToQueryExample(StructuralNode queryExampleNode) { queryExampleBuilder.operator(queryExampleNode.getAttribute(TEST_OPERATOR_ATTRIBUTE).toString()); } + if (queryExampleNode.hasAttribute(TEST_DATABASE_ATTRIBUTE)) { + queryExampleBuilder.database(queryExampleNode.getAttribute(TEST_DATABASE_ATTRIBUTE).toString()); + } + if (Boolean.parseBoolean(queryExampleNode.getAttribute(TEST_TYPE_NO_RESULT, false).toString())) { queryExampleBuilder.assertResults(false); } else { diff --git a/doc-test-tools/src/main/java/org/neo4j/gds/doc/syntax/DocQuery.java b/doc-test-tools/src/main/java/org/neo4j/gds/doc/syntax/DocQuery.java index c294426c100..bff4e23b11e 100644 --- a/doc-test-tools/src/main/java/org/neo4j/gds/doc/syntax/DocQuery.java +++ b/doc-test-tools/src/main/java/org/neo4j/gds/doc/syntax/DocQuery.java @@ -20,6 +20,7 @@ package org.neo4j.gds.doc.syntax; import org.immutables.value.Value; +import org.neo4j.configuration.GraphDatabaseSettings; import org.neo4j.gds.annotation.ValueClass; /** @@ -41,6 +42,9 @@ default String operator() { return DEFAULT_OPERATOR; } + @Value.Default + default String database() { return GraphDatabaseSettings.DEFAULT_DATABASE_NAME;} + static ImmutableDocQuery.Builder builder() { return ImmutableDocQuery.builder(); } diff --git a/doc-test-tools/src/test/java/org/neo4j/gds/doc/QueryCollectingTreeProcessorTest.java b/doc-test-tools/src/test/java/org/neo4j/gds/doc/QueryCollectingTreeProcessorTest.java index fd95fb3dd0c..fbdfd914b51 100644 --- a/doc-test-tools/src/test/java/org/neo4j/gds/doc/QueryCollectingTreeProcessorTest.java +++ b/doc-test-tools/src/test/java/org/neo4j/gds/doc/QueryCollectingTreeProcessorTest.java @@ -125,6 +125,22 @@ void loadsQueryExamplesCorrectly() { ); } + @Test + void parseDatabase() { + processor = new QueryCollectingTreeProcessor(); + asciidoctor.javaExtensionRegistry().treeprocessor(processor); + + var file = ResourceUtil.path("query-collecting-tree-processor-test_database.adoc").toFile(); + assertThat(file).exists().canRead(); + + asciidoctor.loadFile(file, Collections.emptyMap()); + + assertThat(processor.getQueryExampleGroups()).hasSize(1); + assertThat(processor.getQueryExampleGroups().get(0).queryExamples()).containsExactly( + QueryExample.builder().query("SHOW DATABASES").database("system").assertResults(false).build() + ); + } + @Test void parseMultipleDocuments() { var file = ResourceUtil.path("query-collecting-tree-processor-test_part2.adoc").toFile(); diff --git a/doc-test-tools/src/test/resources/query-collecting-tree-processor-test_database.adoc b/doc-test-tools/src/test/resources/query-collecting-tree-processor-test_database.adoc new file mode 100644 index 00000000000..2bec1569654 --- /dev/null +++ b/doc-test-tools/src/test/resources/query-collecting-tree-processor-test_database.adoc @@ -0,0 +1,8 @@ +[role=query-example, database=system, no-result=true] +-- +.This is a test code block +[source, cypher, role=noplay] +---- +SHOW DATABASES +---- +-- diff --git a/doc-test/src/main/java/org/neo4j/gds/doc/ModelCatalogDocTestBase.java b/doc-test/src/main/java/org/neo4j/gds/doc/ModelCatalogDocTestBase.java index 8f6dd449811..85b1f65df57 100644 --- a/doc-test/src/main/java/org/neo4j/gds/doc/ModelCatalogDocTestBase.java +++ b/doc-test/src/main/java/org/neo4j/gds/doc/ModelCatalogDocTestBase.java @@ -22,6 +22,7 @@ import org.junit.jupiter.api.AfterEach; import org.junit.jupiter.api.BeforeEach; import org.neo4j.gds.api.schema.GraphSchema; +import org.neo4j.gds.core.Username; import org.neo4j.gds.core.model.Model; import org.neo4j.gds.core.model.ModelCatalog; import org.neo4j.gds.core.model.TestCustomInfo; diff --git a/doc-test/src/test/java/org/neo4j/gds/doc/WccDocTest.java b/doc-test/src/test/java/org/neo4j/gds/doc/WccDocTest.java index 8a53cb86955..c4519baf32b 100644 --- a/doc-test/src/test/java/org/neo4j/gds/doc/WccDocTest.java +++ b/doc-test/src/test/java/org/neo4j/gds/doc/WccDocTest.java @@ -56,7 +56,7 @@ boolean setupNeo4jGraphPerTest() { Runnable cleanup() { return () -> { GraphStoreCatalog.removeAllLoadedGraphs(); - db.executeTransactionally("MATCH (n) DETACH DELETE n"); + defaultDb.executeTransactionally("MATCH (n) DETACH DELETE n"); }; } diff --git a/doc/modules/ROOT/pages/management-ops/graph-reads/read-with-cypher.adoc b/doc/modules/ROOT/pages/management-ops/graph-reads/read-with-cypher.adoc index 19c13b691d6..b11f1610128 100644 --- a/doc/modules/ROOT/pages/management-ops/graph-reads/read-with-cypher.adoc +++ b/doc/modules/ROOT/pages/management-ops/graph-reads/read-with-cypher.adoc @@ -39,20 +39,23 @@ include::partial$/management-ops/ephemeral-db/create-example.adoc[] === Read query We can now run a `MATCH` Cypher query on the in-memory database and check the results: - -[source, cypher, role=noplay] +[role=query-example] +-- +[source, cypher, role=noplay, database=gdsdb] ---- MATCH (n:Person)-[:KNOWS]->(m:Person) RETURN n.age AS age1, m.age AS age2 +ORDER BY age1, age2 ---- .Results [opts="header"] |=== | age1 | age2 +| 23 | 31 | 23 | 42 | 42 | 23 -| 23 | 31 |=== +-- The returned properties correctly match those from the original graph. diff --git a/doc/modules/ROOT/partials/management-ops/ephemeral-db/create-example.adoc b/doc/modules/ROOT/partials/management-ops/ephemeral-db/create-example.adoc index 754d2c4d418..e76b7733696 100644 --- a/doc/modules/ROOT/partials/management-ops/ephemeral-db/create-example.adoc +++ b/doc/modules/ROOT/partials/management-ops/ephemeral-db/create-example.adoc @@ -1,7 +1,7 @@ Here we create a Neo4j database and xref:management-ops/graph-creation/graph-project.adoc[project] it into memory: -[source, cypher, role=noplay] ----- +[source, cypher, role=noplay setup-query] +-- CREATE (alice:Person { name: 'Alice', age: 23 }), (bob:Person { name: 'Bob', age: 42 }), @@ -10,10 +10,10 @@ CREATE (alice)-[:KNOWS]->(bob), (bob)-[:KNOWS]->(alice), (alice)-[:KNOWS]->(carl) ----- +-- .Project `Person` nodes and `KNOWS` relationships: -[source, cypher, role=noplay] +[source, cypher, role=noplay graph-project-query] ---- CALL gds.graph.project( 'social_network', @@ -28,7 +28,7 @@ YIELD Next, we create an ephemeral database from the projected graph: .Create a new database `gdsdb` using our `social_network` graph: -[source, cypher, role=noplay] +[source, cypher, role=noplay query-example, no-result=true] ---- CALL gds.ephemeral.database.create( 'gdsdb', @@ -38,22 +38,29 @@ CALL gds.ephemeral.database.create( We can use the Neo4j `SHOW DATABASES` command to verify that the new database has been created successfully: -[source, cypher, role=noplay] +[role=query-example, database=system] +-- +[source, cypher, role=noplay, database=system, query-example] ---- SHOW DATABASES +YIELD name, requestedStatus, currentStatus, default +RETURN name, requestedStatus, currentStatus, default +ORDER BY name ---- .Results [opts="header"] |=== -| name | address | role | requestedStatus | currentStatus | error | default | home -| "neo4j" | "localhost:7687" | "standalone" | "online" | "online" | "" | true | true -| "system" | "localhost:7687" | "standalone" | "online" | "online" | "" | false | false -| "gdsdb" | "localhost:7687" | "standalone" | "online" | "online" | "" | false | false +| name | requestedStatus | currentStatus | default +| "gdsdb" | "online" | "online" | false +| "neo4j" | "online" | "online" | true +| "system" | "online" | "online" | false |=== +-- Finally, we switch to the newly created database to start using it: +// this is not valid cypher [source, cypher, role=noplay] ---- :use gdsdb diff --git a/doc/modules/ROOT/partials/management-ops/ephemeral-db/drop-example.adoc b/doc/modules/ROOT/partials/management-ops/ephemeral-db/drop-example.adoc index 93d118b7aaf..844710292da 100644 --- a/doc/modules/ROOT/partials/management-ops/ephemeral-db/drop-example.adoc +++ b/doc/modules/ROOT/partials/management-ops/ephemeral-db/drop-example.adoc @@ -1,18 +1,19 @@ As described above, ephemeral databases are impermanent and are removed when the DBMS is shut down. There are two ways to drop an ephemeral database immediately: -* Use an administrative command against the `system` database: +* Use the <> procedure: + -[source, cypher, role=noplay] +[source, cypher, role=noplay query-example, no-result=true] ---- -DROP DATABASE gdsdb +CALL gds.ephemeral.database.drop('gdsdb') ---- -* Use the <> procedure: +* Use an administrative command against the `system` database: + [source, cypher, role=noplay] ---- -CALL gds.ephemeral.database.drop('gdsdb') +DROP DATABASE gdsdb ---- + In both cases, you need to switch to a different database before proceeding. \ No newline at end of file From b2acf655963a97d6e4a495bb58e13f03c3d942ae Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Florentin=20D=C3=B6rre?= Date: Fri, 21 Jul 2023 15:00:07 +0200 Subject: [PATCH 2/7] Test write-with-cypher --- .../management-ops/graph-update/_write-with-cypher.adoc | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/doc/modules/ROOT/pages/management-ops/graph-update/_write-with-cypher.adoc b/doc/modules/ROOT/pages/management-ops/graph-update/_write-with-cypher.adoc index e3ee106cfbe..3e85e267994 100644 --- a/doc/modules/ROOT/pages/management-ops/graph-update/_write-with-cypher.adoc +++ b/doc/modules/ROOT/pages/management-ops/graph-update/_write-with-cypher.adoc @@ -26,6 +26,8 @@ include::partial$/management-ops/ephemeral-db/create-example.adoc[] As an example of updating the graph, we add a `level` node property only to some nodes that match a given condition: +[role=query-example] +-- [source, cypher, role=noplay] ---- MATCH (n:Person) @@ -40,9 +42,12 @@ RETURN n.age, n.level | n.age | n.level | 42 | 3 |=== +-- Then, we run a Cypher query to check that the new property has actually been added: +[role=query-example] +-- [source, cypher, role=noplay] ---- MATCH (n:Person) @@ -56,6 +61,7 @@ RETURN n.age, n.level | n.age | n.level | 42 | 3 |=== +-- [[drop-ephemeral-db]] === Cleanup From ce2dc7c4a300dd1b644fe4e1a783cf2fd78fc573 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Florentin=20D=C3=B6rre?= Date: Fri, 21 Jul 2023 15:06:06 +0200 Subject: [PATCH 3/7] Add syntax test for ephermal db doc --- .../src/main/java/org/neo4j/gds/doc/syntax/SyntaxMode.java | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/doc-test-tools/src/main/java/org/neo4j/gds/doc/syntax/SyntaxMode.java b/doc-test-tools/src/main/java/org/neo4j/gds/doc/syntax/SyntaxMode.java index 75e76eb4376..b10f8d2d48a 100644 --- a/doc-test-tools/src/main/java/org/neo4j/gds/doc/syntax/SyntaxMode.java +++ b/doc-test-tools/src/main/java/org/neo4j/gds/doc/syntax/SyntaxMode.java @@ -75,8 +75,10 @@ public enum SyntaxMode { SYS_INFO("debug-sysinfo-syntax", false), WRITE_NODE_LABEL("include-with-write-node-label", false), MUTATE_NODE_LABEL("include-with-mutate-node-label", false), - GRAPH_GENERATE("include-with-graph-generate"),; - + GRAPH_GENERATE("include-with-graph-generate"), + DB_CREATE("create-cypher-db-syntax", false), + DB_DROP("drop-cypher-db-syntax", false); + private final String mode; public final boolean hasParameters; public final CustomProcedure.Namespace namespace; From 1725c5fbe2f1626ffc84fd7c076ff42c8af000ea Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Florentin=20D=C3=B6rre?= Date: Mon, 24 Jul 2023 10:39:17 +0200 Subject: [PATCH 4/7] Fix registering aggregation functions in doc test --- .../main/java/org/neo4j/gds/doc/MultiFileDocTestBase.java | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/doc-test-tools/src/main/java/org/neo4j/gds/doc/MultiFileDocTestBase.java b/doc-test-tools/src/main/java/org/neo4j/gds/doc/MultiFileDocTestBase.java index 3495fdf7e78..a2e61f3fdf5 100644 --- a/doc-test-tools/src/main/java/org/neo4j/gds/doc/MultiFileDocTestBase.java +++ b/doc-test-tools/src/main/java/org/neo4j/gds/doc/MultiFileDocTestBase.java @@ -32,6 +32,8 @@ import org.neo4j.dbms.api.DatabaseManagementService; import org.neo4j.gds.QueryRunner; import org.neo4j.gds.compat.CompatUserAggregationFunction; +import org.neo4j.gds.compat.GraphDatabaseApiProxy; +import org.neo4j.gds.compat.Neo4jProxy; import org.neo4j.gds.core.Settings; import org.neo4j.gds.core.loading.GraphStoreCatalog; import org.neo4j.gds.doc.syntax.DocQuery; @@ -83,7 +85,10 @@ void setUp(@TempDir File workingDirectory) throws Exception { registerProcedures(defaultDb, procedures().toArray(clazzArray)); registerFunctions(defaultDb, functions().toArray(clazzArray)); - registerAggregationFunctions(defaultDb, aggregationFunctions().toArray(Class[]::new)); + for (CompatUserAggregationFunction func : aggregationFunctions()) { + GraphDatabaseApiProxy.register(defaultDb, Neo4jProxy.callableUserAggregationFunction(func)); + } + var treeProcessor = new QueryCollectingTreeProcessor(); From 02f7f5b9ff90a7066bfd4643a69309935ec756a3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Florentin=20D=C3=B6rre?= Date: Mon, 24 Jul 2023 10:39:36 +0200 Subject: [PATCH 5/7] Fix ModelCatalog setup in some doc tests --- .../java/org/neo4j/gds/doc/MultiFileDocTestBase.java | 1 - .../org/neo4j/gds/doc/ModelCatalogDocTestBase.java | 12 +++++++++--- .../java/org/neo4j/gds/doc/GraphSageDocTest.java | 8 ++------ 3 files changed, 11 insertions(+), 10 deletions(-) diff --git a/doc-test-tools/src/main/java/org/neo4j/gds/doc/MultiFileDocTestBase.java b/doc-test-tools/src/main/java/org/neo4j/gds/doc/MultiFileDocTestBase.java index a2e61f3fdf5..968b6293c3a 100644 --- a/doc-test-tools/src/main/java/org/neo4j/gds/doc/MultiFileDocTestBase.java +++ b/doc-test-tools/src/main/java/org/neo4j/gds/doc/MultiFileDocTestBase.java @@ -57,7 +57,6 @@ import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.AssertionsForClassTypes.assertThatNoException; import static org.junit.jupiter.api.DynamicTest.dynamicTest; -import static org.neo4j.gds.compat.GraphDatabaseApiProxy.registerAggregationFunctions; import static org.neo4j.gds.compat.GraphDatabaseApiProxy.registerFunctions; import static org.neo4j.gds.compat.GraphDatabaseApiProxy.registerProcedures; diff --git a/doc-test/src/main/java/org/neo4j/gds/doc/ModelCatalogDocTestBase.java b/doc-test/src/main/java/org/neo4j/gds/doc/ModelCatalogDocTestBase.java index 85b1f65df57..88c2cacddf7 100644 --- a/doc-test/src/main/java/org/neo4j/gds/doc/ModelCatalogDocTestBase.java +++ b/doc-test/src/main/java/org/neo4j/gds/doc/ModelCatalogDocTestBase.java @@ -21,7 +21,9 @@ import org.junit.jupiter.api.AfterEach; import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.io.TempDir; import org.neo4j.gds.api.schema.GraphSchema; +import org.neo4j.gds.compat.GraphDatabaseApiProxy; import org.neo4j.gds.core.Username; import org.neo4j.gds.core.model.Model; import org.neo4j.gds.core.model.ModelCatalog; @@ -32,14 +34,18 @@ import java.util.Map; -@Neo4jModelCatalogExtension +import java.io.File; + public abstract class ModelCatalogDocTestBase extends SingleFileDocTestBase { - @Inject ModelCatalog modelCatalog; @BeforeEach - void loadModel() { + @Override + void setUp(@TempDir File workingDirectory) throws Exception { + super.setUp(workingDirectory); + this.modelCatalog = GraphDatabaseApiProxy.resolveDependency(defaultDb, ModelCatalog.class); + var exampleModel1 = Model.of( "example-model-type", GraphSchema.empty(), diff --git a/doc-test/src/test/java/org/neo4j/gds/doc/GraphSageDocTest.java b/doc-test/src/test/java/org/neo4j/gds/doc/GraphSageDocTest.java index cd88d7a2593..0cf87f7efbc 100644 --- a/doc-test/src/test/java/org/neo4j/gds/doc/GraphSageDocTest.java +++ b/doc-test/src/test/java/org/neo4j/gds/doc/GraphSageDocTest.java @@ -20,6 +20,7 @@ package org.neo4j.gds.doc; import org.neo4j.gds.catalog.GraphProjectProc; +import org.neo4j.gds.compat.GraphDatabaseApiProxy; import org.neo4j.gds.core.loading.GraphStoreCatalog; import org.neo4j.gds.core.model.ModelCatalog; import org.neo4j.gds.degree.DegreeCentralityMutateProc; @@ -27,17 +28,11 @@ import org.neo4j.gds.embeddings.graphsage.GraphSageStreamProc; import org.neo4j.gds.embeddings.graphsage.GraphSageTrainProc; import org.neo4j.gds.embeddings.graphsage.GraphSageWriteProc; -import org.neo4j.gds.extension.Inject; -import org.neo4j.gds.extension.Neo4jModelCatalogExtension; import java.util.List; -@Neo4jModelCatalogExtension class GraphSageDocTest extends SingleFileDocTestBase { - @Inject - ModelCatalog modelCatalog; - @Override protected List> procedures() { return List.of( @@ -57,6 +52,7 @@ protected String adocFile() { @Override protected Runnable cleanup() { + var modelCatalog = GraphDatabaseApiProxy.resolveDependency(defaultDb, ModelCatalog.class); return () -> { GraphStoreCatalog.removeAllLoadedGraphs(); modelCatalog.removeAllLoadedModels(); From 2f68b6c9e31176b3881829c072c8dd87b7b29926 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Florentin=20D=C3=B6rre?= Date: Thu, 5 Oct 2023 10:28:00 +0200 Subject: [PATCH 6/7] Fix rebase Disable write part --- .../java/org/neo4j/gds/doc/ModelCatalogDocTestBase.java | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/doc-test/src/main/java/org/neo4j/gds/doc/ModelCatalogDocTestBase.java b/doc-test/src/main/java/org/neo4j/gds/doc/ModelCatalogDocTestBase.java index 88c2cacddf7..db546f3c906 100644 --- a/doc-test/src/main/java/org/neo4j/gds/doc/ModelCatalogDocTestBase.java +++ b/doc-test/src/main/java/org/neo4j/gds/doc/ModelCatalogDocTestBase.java @@ -24,17 +24,13 @@ import org.junit.jupiter.api.io.TempDir; import org.neo4j.gds.api.schema.GraphSchema; import org.neo4j.gds.compat.GraphDatabaseApiProxy; -import org.neo4j.gds.core.Username; import org.neo4j.gds.core.model.Model; import org.neo4j.gds.core.model.ModelCatalog; import org.neo4j.gds.core.model.TestCustomInfo; -import org.neo4j.gds.extension.Inject; -import org.neo4j.gds.extension.Neo4jModelCatalogExtension; import org.neo4j.gds.model.catalog.TestTrainConfig; -import java.util.Map; - import java.io.File; +import java.util.Map; public abstract class ModelCatalogDocTestBase extends SingleFileDocTestBase { From 74ec5ec1296c8fa1292fc0a2e1542e32bb3e535c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Florentin=20D=C3=B6rre?= Date: Thu, 5 Oct 2023 10:42:39 +0200 Subject: [PATCH 7/7] Use new naming for ephemeral db --- .../src/main/java/org/neo4j/gds/doc/syntax/SyntaxMode.java | 4 ++-- .../partials/management-ops/ephemeral-db/create-syntax.adoc | 2 +- .../partials/management-ops/ephemeral-db/drop-syntax.adoc | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/doc-test-tools/src/main/java/org/neo4j/gds/doc/syntax/SyntaxMode.java b/doc-test-tools/src/main/java/org/neo4j/gds/doc/syntax/SyntaxMode.java index b10f8d2d48a..381bdedf397 100644 --- a/doc-test-tools/src/main/java/org/neo4j/gds/doc/syntax/SyntaxMode.java +++ b/doc-test-tools/src/main/java/org/neo4j/gds/doc/syntax/SyntaxMode.java @@ -76,8 +76,8 @@ public enum SyntaxMode { WRITE_NODE_LABEL("include-with-write-node-label", false), MUTATE_NODE_LABEL("include-with-mutate-node-label", false), GRAPH_GENERATE("include-with-graph-generate"), - DB_CREATE("create-cypher-db-syntax", false), - DB_DROP("drop-cypher-db-syntax", false); + DB_CREATE("create-ephemeral-db-syntax", false), + DB_DROP("drop-ephemeral-db-syntax", false); private final String mode; public final boolean hasParameters; diff --git a/doc/modules/ROOT/partials/management-ops/ephemeral-db/create-syntax.adoc b/doc/modules/ROOT/partials/management-ops/ephemeral-db/create-syntax.adoc index 1fdb4578001..fb76cbf770d 100644 --- a/doc/modules/ROOT/partials/management-ops/ephemeral-db/create-syntax.adoc +++ b/doc/modules/ROOT/partials/management-ops/ephemeral-db/create-syntax.adoc @@ -1,4 +1,4 @@ -[.create-cypher-db-syntax] +[.create-ephemeral-db-syntax] -- [source, cypher, role=noplay] ---- diff --git a/doc/modules/ROOT/partials/management-ops/ephemeral-db/drop-syntax.adoc b/doc/modules/ROOT/partials/management-ops/ephemeral-db/drop-syntax.adoc index bc53a466f77..574a4f618a5 100644 --- a/doc/modules/ROOT/partials/management-ops/ephemeral-db/drop-syntax.adoc +++ b/doc/modules/ROOT/partials/management-ops/ephemeral-db/drop-syntax.adoc @@ -1,4 +1,4 @@ -[.drop-cypher-db-syntax] +[.drop-ephemeral-db-syntax] -- [source, cypher, role=noplay] ----