Skip to content

Migrate tests to Testkit #977

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
Aug 11, 2021
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
Expand Up @@ -117,31 +117,6 @@ void shouldCloseChannelWhenResetFails() throws Exception
}
}

@Test
void shouldPropagateTransactionRollbackErrorWhenSessionClosed() throws Exception
{
StubServer server = stubController.startStub( "rollback_error.script", 9001 );
try
{
try ( Driver driver = GraphDatabase.driver( "bolt://localhost:9001", INSECURE_CONFIG ) )
{
Session session = driver.session();

Transaction tx = session.beginTransaction();
Result result = tx.run( "CREATE (n {name:'Alice'}) RETURN n.name AS name" );
assertEquals( "Alice", result.single().get( "name" ).asString() );

TransientException e = assertThrows( TransientException.class, session::close );
assertEquals( "Neo.TransientError.General.DatabaseUnavailable", e.code() );
assertEquals( "Unable to rollback", e.getMessage() );
}
}
finally
{
assertEquals( 0, server.exitStatus() );
}
}

@Test
void shouldStreamingRecordsInBatchesRx() throws Exception
{
Expand All @@ -162,46 +137,6 @@ void shouldStreamingRecordsInBatchesRx() throws Exception
}
}

@Test
void shouldStreamingRecordsInBatches() throws Exception
{
StubServer server = stubController.startStub( "streaming_records_v4.script", 9001 );
try
{
try ( Driver driver = GraphDatabase.driver( "bolt://localhost:9001", insecureBuilder().withFetchSize( 2 ).build() ) )
{
Session session = driver.session();
Result result = session.run( "MATCH (n) RETURN n.name" );
List<String> list = result.list( record -> record.get( "n.name" ).asString() );
assertEquals( list, asList( "Bob", "Alice", "Tina" ) );
}
}
finally
{
assertEquals( 0, server.exitStatus() );
}
}

@Test
void shouldChangeFetchSize() throws Exception
{
StubServer server = stubController.startStub( "streaming_records_v4.script", 9001 );
try
{
try ( Driver driver = GraphDatabase.driver( "bolt://localhost:9001", INSECURE_CONFIG ) )
{
Session session = driver.session( builder().withFetchSize( 2 ).build() );
Result result = session.run( "MATCH (n) RETURN n.name" );
List<String> list = result.list( record -> record.get( "n.name" ).asString() );
assertEquals( list, asList( "Bob", "Alice", "Tina" ) );
}
}
finally
{
assertEquals( 0, server.exitStatus() );
}
}

@Test
void shouldOnlyPullRecordsWhenNeededSimpleSession() throws Exception
{
Expand Down Expand Up @@ -297,19 +232,6 @@ void shouldThrowCommitErrorWhenTransactionCommit() throws Exception
testTxCloseErrorPropagation( "commit_error.script", Transaction::commit, "Unable to commit" );
}

@Test
void shouldThrowRollbackErrorWhenTransactionRollback() throws Exception
{
testTxCloseErrorPropagation( "rollback_error.script", Transaction::rollback, "Unable to rollback" );
}

@Test
void shouldThrowRollbackErrorWhenTransactionClose() throws Exception
{
testTxCloseErrorPropagation( "rollback_error.script", Transaction::close, "Unable to rollback" );
}


@Test
void shouldThrowCorrectErrorOnRunFailure() throws Throwable
{
Expand Down
17 changes: 0 additions & 17 deletions driver/src/test/resources/rollback_error.script

This file was deleted.

14 changes: 0 additions & 14 deletions driver/src/test/resources/streaming_records_v4.script

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,7 @@ private DriverError driverError( String id, Neo4jException e )
.id( id )
.errorType( e.getClass().getName() )
.code( e.code() )
.msg( e.getMessage() )
.build() )
.build();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,9 @@ public class GetFeatures implements TestkitRequest
private static final Set<String> FEATURES = new HashSet<>( Arrays.asList(
"AuthorizationExpiredTreatment",
"Optimization:PullPipelining",
"ConfHint:connection.recv_timeout_seconds"
"ConfHint:connection.recv_timeout_seconds",
"Temporary:TransactionClose",
"Temporary:DriverFetchSize"
) );

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ public TestkitResponse process( TestkitState testkitState )
}
Optional.ofNullable( data.userAgent ).ifPresent( configBuilder::withUserAgent );
Optional.ofNullable( data.connectionTimeoutMs ).ifPresent( timeout -> configBuilder.withConnectionTimeout( timeout, TimeUnit.MILLISECONDS ) );
Optional.ofNullable( data.fetchSize ).ifPresent( configBuilder::withFetchSize );
org.neo4j.driver.Driver driver;
try
{
Expand Down Expand Up @@ -179,6 +180,7 @@ public static class NewDriverBody
private boolean resolverRegistered;
private boolean domainNameResolverRegistered;
private Long connectionTimeoutMs;
private Integer fetchSize;
}

@RequiredArgsConstructor
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
@JsonSubTypes.Type( ResolverResolutionCompleted.class ), @JsonSubTypes.Type( CheckMultiDBSupport.class ),
@JsonSubTypes.Type( DomainNameResolutionCompleted.class ), @JsonSubTypes.Type( StartTest.class ),
@JsonSubTypes.Type( TransactionRollback.class ), @JsonSubTypes.Type( GetFeatures.class ),
@JsonSubTypes.Type( GetRoutingTable.class )
@JsonSubTypes.Type( GetRoutingTable.class ), @JsonSubTypes.Type( TransactionClose.class )
} )
public interface TestkitRequest
{
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
/*
* 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 neo4j.org.testkit.backend.messages.requests;

import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;
import neo4j.org.testkit.backend.TestkitState;
import neo4j.org.testkit.backend.messages.responses.TestkitResponse;
import neo4j.org.testkit.backend.messages.responses.Transaction;

import java.util.Optional;

@Setter
@Getter
@NoArgsConstructor
public class TransactionClose implements TestkitRequest
{
private TransactionCloseBody data;

@Override
public TestkitResponse process( TestkitState testkitState )
{
return Optional.ofNullable( testkitState.getTransactions().get( data.txId ) )
.map( tx ->
{
tx.close();
return transaction( data.txId );
} )
.orElseThrow( () -> new RuntimeException( "Could not find transaction" ) );
}

private Transaction transaction( String txId )
{
return Transaction.builder().data( Transaction.TransactionBody.builder().id( txId ).build() ).build();
}

@Setter
@Getter
@NoArgsConstructor
private static class TransactionCloseBody
{
private String txId;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -45,5 +45,7 @@ public static class DriverErrorBody
private String errorType;

private String code;

private String msg;
}
}