diff --git a/driver/src/test/java/org/neo4j/driver/tck/reactive/Neo4jManager.java b/driver/src/test/java/org/neo4j/driver/tck/reactive/Neo4jManager.java new file mode 100644 index 0000000000..955ced9a88 --- /dev/null +++ b/driver/src/test/java/org/neo4j/driver/tck/reactive/Neo4jManager.java @@ -0,0 +1,68 @@ +/* + * Copyright (c) "Neo4j" + * Neo4j Sweden AB [http://neo4j.com] + * + * This file is part of Neo4j. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.neo4j.driver.tck.reactive; + +import org.testcontainers.DockerClientFactory; +import org.testcontainers.containers.Neo4jContainer; +import org.testng.SkipException; + +import org.neo4j.driver.Driver; +import org.neo4j.driver.GraphDatabase; + +public class Neo4jManager +{ + private final Neo4jContainer NEO4J = new Neo4jContainer<>( "neo4j:4.4" ) + .withAdminPassword( null ); + + public void start() + { + NEO4J.start(); + } + + public void stop() + { + NEO4J.stop(); + } + + public Driver getDriver() + { + return GraphDatabase.driver( NEO4J.getBoltUrl() ); + } + + public void skipIfDockerUnavailable() + { + if ( !isDockerAvailable() ) + { + throw new SkipException( "Docker is unavailable" ); + } + } + + private boolean isDockerAvailable() + { + try + { + DockerClientFactory.instance().client(); + return true; + } + catch ( Throwable ex ) + { + return false; + } + } +} diff --git a/driver/src/test/java/org/neo4j/driver/tck/reactive/ReactiveResultPublisherVerificationIT.java b/driver/src/test/java/org/neo4j/driver/tck/reactive/ReactiveResultPublisherVerificationIT.java new file mode 100644 index 0000000000..5d7324cf00 --- /dev/null +++ b/driver/src/test/java/org/neo4j/driver/tck/reactive/ReactiveResultPublisherVerificationIT.java @@ -0,0 +1,85 @@ +/* + * Copyright (c) "Neo4j" + * Neo4j Sweden AB [http://neo4j.com] + * + * This file is part of Neo4j. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.neo4j.driver.tck.reactive; + +import org.reactivestreams.Publisher; +import org.reactivestreams.tck.PublisherVerification; +import org.reactivestreams.tck.TestEnvironment; +import org.testcontainers.junit.jupiter.Testcontainers; +import org.testng.annotations.AfterClass; +import org.testng.annotations.BeforeClass; +import reactor.core.publisher.Mono; + +import java.time.Duration; + +import org.neo4j.driver.Driver; +import org.neo4j.driver.reactive.ReactiveResult; +import org.neo4j.driver.reactive.ReactiveSession; + +@Testcontainers( disabledWithoutDocker = true ) +public class ReactiveResultPublisherVerificationIT extends PublisherVerification +{ + private final Neo4jManager NEO4J = new Neo4jManager(); + private static final Duration TIMEOUT = Duration.ofSeconds( 10 ); + private static final Duration TIMEOUT_FOR_NO_SIGNALS = Duration.ofSeconds( 1 ); + private static final Duration PUBLISHER_REFERENCE_CLEANUP_TIMEOUT_MILLIS = Duration.ofSeconds( 1 ); + + private Driver driver; + + public ReactiveResultPublisherVerificationIT() + { + super( new TestEnvironment( TIMEOUT.toMillis(), TIMEOUT_FOR_NO_SIGNALS.toMillis() ), + PUBLISHER_REFERENCE_CLEANUP_TIMEOUT_MILLIS.toMillis() ); + } + + @BeforeClass + public void beforeClass() + { + NEO4J.skipIfDockerUnavailable(); + NEO4J.start(); + driver = NEO4J.getDriver(); + } + + @AfterClass + public void afterClass() + { + NEO4J.stop(); + } + + @Override + public long maxElementsFromPublisher() + { + return 1; + } + + @Override + public Publisher createPublisher( long elements ) + { + ReactiveSession session = driver.reactiveSession(); + return Mono.fromDirect( session.run( "RETURN 1" ) ); + } + + @Override + public Publisher createFailedPublisher() + { + ReactiveSession session = driver.reactiveSession(); + // Please note that this publisher fails on run stage. + return Mono.fromDirect( session.run( "RETURN 5/0" ) ); + } +} diff --git a/driver/src/test/java/org/neo4j/driver/tck/reactive/ReactiveResultRecordPublisherVerificationIT.java b/driver/src/test/java/org/neo4j/driver/tck/reactive/ReactiveResultRecordPublisherVerificationIT.java new file mode 100644 index 0000000000..79672c0f63 --- /dev/null +++ b/driver/src/test/java/org/neo4j/driver/tck/reactive/ReactiveResultRecordPublisherVerificationIT.java @@ -0,0 +1,94 @@ +/* + * Copyright (c) "Neo4j" + * Neo4j Sweden AB [http://neo4j.com] + * + * This file is part of Neo4j. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.neo4j.driver.tck.reactive; + +import org.reactivestreams.Publisher; +import org.reactivestreams.tck.PublisherVerification; +import org.reactivestreams.tck.TestEnvironment; +import org.testcontainers.junit.jupiter.Testcontainers; +import org.testng.annotations.AfterClass; +import org.testng.annotations.BeforeClass; +import reactor.core.publisher.Flux; +import reactor.core.publisher.Mono; + +import java.time.Duration; + +import org.neo4j.driver.Driver; +import org.neo4j.driver.Record; +import org.neo4j.driver.reactive.ReactiveSession; + +import static org.neo4j.driver.Values.parameters; + +@Testcontainers( disabledWithoutDocker = true ) +public class ReactiveResultRecordPublisherVerificationIT extends PublisherVerification +{ + private final Neo4jManager NEO4J = new Neo4jManager(); + private final static long MAX_NUMBER_OF_RECORDS = 30000; + + private static final Duration TIMEOUT = Duration.ofSeconds( 10 ); + private static final Duration TIMEOUT_FOR_NO_SIGNALS = Duration.ofSeconds( 1 ); + private static final Duration PUBLISHER_REFERENCE_CLEANUP_TIMEOUT_MILLIS = Duration.ofSeconds( 1 ); + + private final static String QUERY = "UNWIND RANGE(1, $numberOfRecords) AS n RETURN 'String Number' + n"; + + private Driver driver; + + public ReactiveResultRecordPublisherVerificationIT() + { + super( new TestEnvironment( TIMEOUT.toMillis(), TIMEOUT_FOR_NO_SIGNALS.toMillis() ), + PUBLISHER_REFERENCE_CLEANUP_TIMEOUT_MILLIS.toMillis() ); + } + + @BeforeClass + public void beforeClass() + { + NEO4J.skipIfDockerUnavailable(); + NEO4J.start(); + driver = NEO4J.getDriver(); + } + + @AfterClass + public void afterClass() + { + NEO4J.stop(); + } + + @Override + public long maxElementsFromPublisher() + { + return MAX_NUMBER_OF_RECORDS; + } + + @Override + public Publisher createPublisher( long elements ) + { + ReactiveSession session = driver.reactiveSession(); + return Mono.fromDirect( session.run( QUERY, parameters( "numberOfRecords", elements ) ) ) + .flatMapMany( r -> Flux.from( r.records() ) ); + } + + @Override + public Publisher createFailedPublisher() + { + ReactiveSession session = driver.reactiveSession(); + // Please note that this publisher fails on run stage. + return Mono.fromDirect( session.run( "RETURN 5/0" ) ) + .flatMapMany( r -> Flux.from( r.records() ) ); + } +} diff --git a/driver/src/test/java/org/neo4j/driver/tck/reactive/RxResultRecordPublisherVerificationIT.java b/driver/src/test/java/org/neo4j/driver/tck/reactive/RxResultRecordPublisherVerificationIT.java index f3c2f90281..ec92a540cc 100644 --- a/driver/src/test/java/org/neo4j/driver/tck/reactive/RxResultRecordPublisherVerificationIT.java +++ b/driver/src/test/java/org/neo4j/driver/tck/reactive/RxResultRecordPublisherVerificationIT.java @@ -21,16 +21,13 @@ import org.reactivestreams.Publisher; import org.reactivestreams.tck.PublisherVerification; import org.reactivestreams.tck.TestEnvironment; -import org.testcontainers.DockerClientFactory; -import org.testcontainers.containers.Neo4jContainer; import org.testcontainers.junit.jupiter.Testcontainers; -import org.testng.SkipException; +import org.testng.annotations.AfterClass; import org.testng.annotations.BeforeClass; import java.time.Duration; import org.neo4j.driver.Driver; -import org.neo4j.driver.GraphDatabase; import org.neo4j.driver.Record; import org.neo4j.driver.reactive.RxResult; import org.neo4j.driver.reactive.RxSession; @@ -40,9 +37,7 @@ @Testcontainers( disabledWithoutDocker = true ) public class RxResultRecordPublisherVerificationIT extends PublisherVerification { - private static final Neo4jContainer NEO4J_CONTAINER = new Neo4jContainer<>( "neo4j:4.4" ) - .withAdminPassword( null ); - + private final Neo4jManager NEO4J = new Neo4jManager(); private final static long MAX_NUMBER_OF_RECORDS = 30000; private static final Duration TIMEOUT = Duration.ofSeconds( 10 ); @@ -62,17 +57,15 @@ public RxResultRecordPublisherVerificationIT() @BeforeClass public void beforeClass() { - if ( !isDockerAvailable() ) - { - throw new SkipException( "Docker is unavailable" ); - } - NEO4J_CONTAINER.start(); - driver = GraphDatabase.driver( NEO4J_CONTAINER.getBoltUrl() ); + NEO4J.skipIfDockerUnavailable(); + NEO4J.start(); + driver = NEO4J.getDriver(); } + @AfterClass public void afterClass() { - NEO4J_CONTAINER.stop(); + NEO4J.stop(); } @Override @@ -96,17 +89,4 @@ public Publisher createFailedPublisher() RxResult result = session.run( "INVALID" ); return result.records(); } - - boolean isDockerAvailable() - { - try - { - DockerClientFactory.instance().client(); - return true; - } - catch ( Throwable ex ) - { - return false; - } - } }