Skip to content

Add TCK tests for ReactiveResult and ReactiveResult Record #1226

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

Merged
merged 1 commit into from
May 19, 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
Original file line number Diff line number Diff line change
@@ -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;
}
}
}
Original file line number Diff line number Diff line change
@@ -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<ReactiveResult>
{
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<ReactiveResult> createPublisher( long elements )
{
ReactiveSession session = driver.reactiveSession();
return Mono.fromDirect( session.run( "RETURN 1" ) );
}

@Override
public Publisher<ReactiveResult> createFailedPublisher()
{
ReactiveSession session = driver.reactiveSession();
// Please note that this publisher fails on run stage.
return Mono.fromDirect( session.run( "RETURN 5/0" ) );
}
}
Original file line number Diff line number Diff line change
@@ -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<Record>
{
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<Record> 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<Record> 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() ) );
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -40,9 +37,7 @@
@Testcontainers( disabledWithoutDocker = true )
public class RxResultRecordPublisherVerificationIT extends PublisherVerification<Record>
{
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 );
Expand All @@ -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
Expand All @@ -96,17 +89,4 @@ public Publisher<Record> createFailedPublisher()
RxResult result = session.run( "INVALID" );
return result.records();
}

boolean isDockerAvailable()
{
try
{
DockerClientFactory.instance().client();
return true;
}
catch ( Throwable ex )
{
return false;
}
}
}