Skip to content

Commit 7a824c5

Browse files
authored
Migrate tests to Testkit (#976)
This updated also includes: - TransactionClose request support (`Temporary:TransactionClose` feature) - Driver fetch size configuration (`Temporary:DriverFetchSize` feature) Migrated tests: - shouldThrowRollbackErrorWhenTransactionRollback -> test_should_error_on_rollback_failure_using_tx_rollback - shouldThrowRollbackErrorWhenTransactionClose -> test_should_error_on_rollback_failure_using_tx_close - shouldPropagateTransactionRollbackErrorWhenSessionClosed -> test_should_error_on_rollback_failure_using_session_close - shouldStreamingRecordsInBatches -> test_should_accept_custom_fetch_size_using_driver_configuration (protocol bump from 4 to 4.1) - shouldChangeFetchSize -> test_should_accept_custom_fetch_size_using_session_configuration (protocol bump from 4 to 4.1)
1 parent 62af57c commit 7a824c5

File tree

9 files changed

+70
-111
lines changed

9 files changed

+70
-111
lines changed

driver/src/test/java/org/neo4j/driver/internal/DirectDriverBoltKitIT.java

Lines changed: 0 additions & 78 deletions
Original file line numberDiff line numberDiff line change
@@ -117,31 +117,6 @@ void shouldCloseChannelWhenResetFails() throws Exception
117117
}
118118
}
119119

120-
@Test
121-
void shouldPropagateTransactionRollbackErrorWhenSessionClosed() throws Exception
122-
{
123-
StubServer server = stubController.startStub( "rollback_error.script", 9001 );
124-
try
125-
{
126-
try ( Driver driver = GraphDatabase.driver( "bolt://localhost:9001", INSECURE_CONFIG ) )
127-
{
128-
Session session = driver.session();
129-
130-
Transaction tx = session.beginTransaction();
131-
Result result = tx.run( "CREATE (n {name:'Alice'}) RETURN n.name AS name" );
132-
assertEquals( "Alice", result.single().get( "name" ).asString() );
133-
134-
TransientException e = assertThrows( TransientException.class, session::close );
135-
assertEquals( "Neo.TransientError.General.DatabaseUnavailable", e.code() );
136-
assertEquals( "Unable to rollback", e.getMessage() );
137-
}
138-
}
139-
finally
140-
{
141-
assertEquals( 0, server.exitStatus() );
142-
}
143-
}
144-
145120
@Test
146121
void shouldStreamingRecordsInBatchesRx() throws Exception
147122
{
@@ -162,46 +137,6 @@ void shouldStreamingRecordsInBatchesRx() throws Exception
162137
}
163138
}
164139

165-
@Test
166-
void shouldStreamingRecordsInBatches() throws Exception
167-
{
168-
StubServer server = stubController.startStub( "streaming_records_v4.script", 9001 );
169-
try
170-
{
171-
try ( Driver driver = GraphDatabase.driver( "bolt://localhost:9001", insecureBuilder().withFetchSize( 2 ).build() ) )
172-
{
173-
Session session = driver.session();
174-
Result result = session.run( "MATCH (n) RETURN n.name" );
175-
List<String> list = result.list( record -> record.get( "n.name" ).asString() );
176-
assertEquals( list, asList( "Bob", "Alice", "Tina" ) );
177-
}
178-
}
179-
finally
180-
{
181-
assertEquals( 0, server.exitStatus() );
182-
}
183-
}
184-
185-
@Test
186-
void shouldChangeFetchSize() throws Exception
187-
{
188-
StubServer server = stubController.startStub( "streaming_records_v4.script", 9001 );
189-
try
190-
{
191-
try ( Driver driver = GraphDatabase.driver( "bolt://localhost:9001", INSECURE_CONFIG ) )
192-
{
193-
Session session = driver.session( builder().withFetchSize( 2 ).build() );
194-
Result result = session.run( "MATCH (n) RETURN n.name" );
195-
List<String> list = result.list( record -> record.get( "n.name" ).asString() );
196-
assertEquals( list, asList( "Bob", "Alice", "Tina" ) );
197-
}
198-
}
199-
finally
200-
{
201-
assertEquals( 0, server.exitStatus() );
202-
}
203-
}
204-
205140
@Test
206141
void shouldOnlyPullRecordsWhenNeededSimpleSession() throws Exception
207142
{
@@ -297,19 +232,6 @@ void shouldThrowCommitErrorWhenTransactionCommit() throws Exception
297232
testTxCloseErrorPropagation( "commit_error.script", Transaction::commit, "Unable to commit" );
298233
}
299234

300-
@Test
301-
void shouldThrowRollbackErrorWhenTransactionRollback() throws Exception
302-
{
303-
testTxCloseErrorPropagation( "rollback_error.script", Transaction::rollback, "Unable to rollback" );
304-
}
305-
306-
@Test
307-
void shouldThrowRollbackErrorWhenTransactionClose() throws Exception
308-
{
309-
testTxCloseErrorPropagation( "rollback_error.script", Transaction::close, "Unable to rollback" );
310-
}
311-
312-
313235
@Test
314236
void shouldThrowCorrectErrorOnRunFailure() throws Throwable
315237
{

driver/src/test/resources/rollback_error.script

Lines changed: 0 additions & 17 deletions
This file was deleted.

driver/src/test/resources/streaming_records_v4.script

Lines changed: 0 additions & 14 deletions
This file was deleted.

testkit-backend/src/main/java/neo4j/org/testkit/backend/CommandProcessor.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -180,6 +180,7 @@ private DriverError driverError( String id, Neo4jException e )
180180
.id( id )
181181
.errorType( e.getClass().getName() )
182182
.code( e.code() )
183+
.msg( e.getMessage() )
183184
.build() )
184185
.build();
185186
}

testkit-backend/src/main/java/neo4j/org/testkit/backend/messages/requests/GetFeatures.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,9 @@ public class GetFeatures implements TestkitRequest
3737
private static final Set<String> FEATURES = new HashSet<>( Arrays.asList(
3838
"AuthorizationExpiredTreatment",
3939
"Optimization:PullPipelining",
40-
"ConfHint:connection.recv_timeout_seconds"
40+
"ConfHint:connection.recv_timeout_seconds",
41+
"Temporary:TransactionClose",
42+
"Temporary:DriverFetchSize"
4143
) );
4244

4345
@Override

testkit-backend/src/main/java/neo4j/org/testkit/backend/messages/requests/NewDriver.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,7 @@ public TestkitResponse process( TestkitState testkitState )
8989
}
9090
Optional.ofNullable( data.userAgent ).ifPresent( configBuilder::withUserAgent );
9191
Optional.ofNullable( data.connectionTimeoutMs ).ifPresent( timeout -> configBuilder.withConnectionTimeout( timeout, TimeUnit.MILLISECONDS ) );
92+
Optional.ofNullable( data.fetchSize ).ifPresent( configBuilder::withFetchSize );
9293
org.neo4j.driver.Driver driver;
9394
try
9495
{
@@ -179,6 +180,7 @@ public static class NewDriverBody
179180
private boolean resolverRegistered;
180181
private boolean domainNameResolverRegistered;
181182
private Long connectionTimeoutMs;
183+
private Integer fetchSize;
182184
}
183185

184186
@RequiredArgsConstructor

testkit-backend/src/main/java/neo4j/org/testkit/backend/messages/requests/TestkitRequest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@
3636
@JsonSubTypes.Type( ResolverResolutionCompleted.class ), @JsonSubTypes.Type( CheckMultiDBSupport.class ),
3737
@JsonSubTypes.Type( DomainNameResolutionCompleted.class ), @JsonSubTypes.Type( StartTest.class ),
3838
@JsonSubTypes.Type( TransactionRollback.class ), @JsonSubTypes.Type( GetFeatures.class ),
39-
@JsonSubTypes.Type( GetRoutingTable.class )
39+
@JsonSubTypes.Type( GetRoutingTable.class ), @JsonSubTypes.Type( TransactionClose.class )
4040
} )
4141
public interface TestkitRequest
4242
{
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
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 neo4j.org.testkit.backend.messages.requests;
20+
21+
import lombok.Getter;
22+
import lombok.NoArgsConstructor;
23+
import lombok.Setter;
24+
import neo4j.org.testkit.backend.TestkitState;
25+
import neo4j.org.testkit.backend.messages.responses.TestkitResponse;
26+
import neo4j.org.testkit.backend.messages.responses.Transaction;
27+
28+
import java.util.Optional;
29+
30+
@Setter
31+
@Getter
32+
@NoArgsConstructor
33+
public class TransactionClose implements TestkitRequest
34+
{
35+
private TransactionCloseBody data;
36+
37+
@Override
38+
public TestkitResponse process( TestkitState testkitState )
39+
{
40+
return Optional.ofNullable( testkitState.getTransactions().get( data.txId ) )
41+
.map( tx ->
42+
{
43+
tx.close();
44+
return transaction( data.txId );
45+
} )
46+
.orElseThrow( () -> new RuntimeException( "Could not find transaction" ) );
47+
}
48+
49+
private Transaction transaction( String txId )
50+
{
51+
return Transaction.builder().data( Transaction.TransactionBody.builder().id( txId ).build() ).build();
52+
}
53+
54+
@Setter
55+
@Getter
56+
@NoArgsConstructor
57+
private static class TransactionCloseBody
58+
{
59+
private String txId;
60+
}
61+
}

testkit-backend/src/main/java/neo4j/org/testkit/backend/messages/responses/DriverError.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,5 +45,7 @@ public static class DriverErrorBody
4545
private String errorType;
4646

4747
private String code;
48+
49+
private String msg;
4850
}
4951
}

0 commit comments

Comments
 (0)