|
| 1 | +/* |
| 2 | + * Copyright (c) "Neo4j" |
| 3 | + * Neo4j Sweden AB [http://neo4j.com] |
| 4 | + * |
| 5 | + * This file is part of Neo4j. |
| 6 | + * |
| 7 | + * Licensed under the Apache License, Version 2.0 (the "License"); |
| 8 | + * you may not use this file except in compliance with the License. |
| 9 | + * You may obtain a copy of the License at |
| 10 | + * |
| 11 | + * http://www.apache.org/licenses/LICENSE-2.0 |
| 12 | + * |
| 13 | + * Unless required by applicable law or agreed to in writing, software |
| 14 | + * distributed under the License is distributed on an "AS IS" BASIS, |
| 15 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 16 | + * See the License for the specific language governing permissions and |
| 17 | + * limitations under the License. |
| 18 | + */ |
| 19 | +package org.neo4j.driver.tck.reactive; |
| 20 | + |
| 21 | +import org.reactivestreams.Publisher; |
| 22 | +import org.reactivestreams.tck.PublisherVerification; |
| 23 | +import org.reactivestreams.tck.TestEnvironment; |
| 24 | +import org.testcontainers.DockerClientFactory; |
| 25 | +import org.testcontainers.containers.Neo4jContainer; |
| 26 | +import org.testcontainers.junit.jupiter.Testcontainers; |
| 27 | +import org.testng.SkipException; |
| 28 | +import org.testng.annotations.BeforeClass; |
| 29 | + |
| 30 | +import java.time.Duration; |
| 31 | + |
| 32 | +import org.neo4j.driver.Driver; |
| 33 | +import org.neo4j.driver.GraphDatabase; |
| 34 | +import org.neo4j.driver.Record; |
| 35 | +import org.neo4j.driver.reactive.RxResult; |
| 36 | +import org.neo4j.driver.reactive.RxSession; |
| 37 | + |
| 38 | +import static org.neo4j.driver.Values.parameters; |
| 39 | + |
| 40 | +@Testcontainers( disabledWithoutDocker = true ) |
| 41 | +public class RxResultRecordPublisherVerificationIT extends PublisherVerification<Record> |
| 42 | +{ |
| 43 | + private static final Neo4jContainer<?> NEO4J_CONTAINER = new Neo4jContainer<>( "neo4j:4.4" ) |
| 44 | + .withAdminPassword( null ); |
| 45 | + |
| 46 | + private final static long MAX_NUMBER_OF_RECORDS = 30000; |
| 47 | + |
| 48 | + private static final Duration TIMEOUT = Duration.ofSeconds( 10 ); |
| 49 | + private static final Duration TIMEOUT_FOR_NO_SIGNALS = Duration.ofSeconds( 1 ); |
| 50 | + private static final Duration PUBLISHER_REFERENCE_CLEANUP_TIMEOUT_MILLIS = Duration.ofSeconds( 1 ); |
| 51 | + |
| 52 | + private final static String QUERY = "UNWIND RANGE(1, $numberOfRecords) AS n RETURN 'String Number' + n"; |
| 53 | + |
| 54 | + private Driver driver; |
| 55 | + |
| 56 | + public RxResultRecordPublisherVerificationIT() |
| 57 | + { |
| 58 | + super( new TestEnvironment( TIMEOUT.toMillis(), TIMEOUT_FOR_NO_SIGNALS.toMillis() ), |
| 59 | + PUBLISHER_REFERENCE_CLEANUP_TIMEOUT_MILLIS.toMillis() ); |
| 60 | + } |
| 61 | + |
| 62 | + @BeforeClass |
| 63 | + public void beforeClass() |
| 64 | + { |
| 65 | + if ( !isDockerAvailable() ) |
| 66 | + { |
| 67 | + throw new SkipException( "Docker is unavailable" ); |
| 68 | + } |
| 69 | + NEO4J_CONTAINER.start(); |
| 70 | + driver = GraphDatabase.driver( NEO4J_CONTAINER.getBoltUrl() ); |
| 71 | + } |
| 72 | + |
| 73 | + public void afterClass() |
| 74 | + { |
| 75 | + NEO4J_CONTAINER.stop(); |
| 76 | + } |
| 77 | + |
| 78 | + @Override |
| 79 | + public long maxElementsFromPublisher() |
| 80 | + { |
| 81 | + return MAX_NUMBER_OF_RECORDS; |
| 82 | + } |
| 83 | + |
| 84 | + @Override |
| 85 | + public Publisher<Record> createPublisher( long elements ) |
| 86 | + { |
| 87 | + RxSession session = driver.rxSession(); |
| 88 | + RxResult result = session.run( QUERY, parameters( "numberOfRecords", elements ) ); |
| 89 | + return result.records(); |
| 90 | + } |
| 91 | + |
| 92 | + @Override |
| 93 | + public Publisher<Record> createFailedPublisher() |
| 94 | + { |
| 95 | + RxSession session = driver.rxSession(); |
| 96 | + RxResult result = session.run( "INVALID" ); |
| 97 | + return result.records(); |
| 98 | + } |
| 99 | + |
| 100 | + boolean isDockerAvailable() |
| 101 | + { |
| 102 | + try |
| 103 | + { |
| 104 | + DockerClientFactory.instance().client(); |
| 105 | + return true; |
| 106 | + } |
| 107 | + catch ( Throwable ex ) |
| 108 | + { |
| 109 | + return false; |
| 110 | + } |
| 111 | + } |
| 112 | +} |
0 commit comments