Skip to content

Commit df85520

Browse files
committed
Migrate java-driver-rx-tck
This update migrates verification tests from `java-driver-rx-tck` to this project.
1 parent 09e325a commit df85520

File tree

3 files changed

+133
-0
lines changed

3 files changed

+133
-0
lines changed

driver/pom.xml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,10 @@
6565
<groupId>org.junit.jupiter</groupId>
6666
<artifactId>junit-jupiter</artifactId>
6767
</dependency>
68+
<dependency>
69+
<groupId>org.junit.support</groupId>
70+
<artifactId>testng-engine</artifactId>
71+
</dependency>
6872
<dependency>
6973
<groupId>org.rauschig</groupId>
7074
<artifactId>jarchivelib</artifactId>
@@ -92,6 +96,10 @@
9296
<artifactId>neo4j</artifactId>
9397
<scope>test</scope>
9498
</dependency>
99+
<dependency>
100+
<groupId>org.reactivestreams</groupId>
101+
<artifactId>reactive-streams-tck</artifactId>
102+
</dependency>
95103
</dependencies>
96104

97105
<build>
Lines changed: 112 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,112 @@
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+
}

pom.xml

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@
4444
<hamcrest-junit.version>2.0.0.0</hamcrest-junit.version>
4545
<mockito-core.version>4.4.0</mockito-core.version>
4646
<junit.version>5.8.2</junit.version>
47+
<testng-engine.version>1.0.2</testng-engine.version>
4748
<jarchivelib.version>1.2.0</jarchivelib.version>
4849
<bouncycastle-jdk15on.version>1.70</bouncycastle-jdk15on.version>
4950
<logback-classic.version>1.2.11</logback-classic.version>
@@ -147,6 +148,12 @@
147148
<version>${junit.version}</version>
148149
<scope>test</scope>
149150
</dependency>
151+
<dependency>
152+
<groupId>org.junit.support</groupId>
153+
<artifactId>testng-engine</artifactId>
154+
<version>${testng-engine.version}</version>
155+
<scope>test</scope>
156+
</dependency>
150157
<dependency>
151158
<groupId>org.rauschig</groupId>
152159
<artifactId>jarchivelib</artifactId>
@@ -171,6 +178,12 @@
171178
<version>${logback-classic.version}</version>
172179
<scope>test</scope>
173180
</dependency>
181+
<dependency>
182+
<groupId>org.reactivestreams</groupId>
183+
<artifactId>reactive-streams-tck</artifactId>
184+
<version>${reactive-streams.version}</version>
185+
<scope>test</scope>
186+
</dependency>
174187
<dependency>
175188
<groupId>org.testcontainers</groupId>
176189
<artifactId>testcontainers-bom</artifactId>

0 commit comments

Comments
 (0)