Skip to content

Ensure error is propagated from rx queries correctly. #681

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 3 commits into from
Apr 9, 2020
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 @@ -30,7 +30,6 @@
import java.lang.management.OperatingSystemMXBean;
import java.lang.reflect.Method;
import java.net.URI;
import java.time.Duration;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
Expand Down Expand Up @@ -99,7 +98,6 @@ abstract class AbstractStressTestBase<C extends AbstractContext>

private static final int BIG_DATA_TEST_NODE_COUNT = Integer.getInteger( "bigDataTestNodeCount", 30_000 );
private static final int BIG_DATA_TEST_BATCH_SIZE = Integer.getInteger( "bigDataTestBatchSize", 10_000 );
private static final Duration DEFAULT_BLOCKING_TIME_OUT = Duration.ofMinutes( 10 );

private LoggerNameTrackingLogging logging;
private ExecutorService executor;
Expand Down Expand Up @@ -638,7 +636,7 @@ private Bookmark createNodesRx( int batchCount, int batchSize, InternalDriver dr

Flux.concat( Flux.range( 0, batchCount ).map( batchIndex ->
session.writeTransaction( tx -> createNodesInTxRx( tx, batchIndex, batchSize ) )
) ).blockLast( DEFAULT_BLOCKING_TIME_OUT ); // throw any error if happened
) ).blockLast(); // throw any error if happened

long end = System.nanoTime();
System.out.println( "Node creation with reactive API took: " + NANOSECONDS.toMillis( end - start ) + "ms" );
Expand Down Expand Up @@ -673,7 +671,7 @@ private void readNodesRx( InternalDriver driver, Bookmark bookmark, int expected
verifyNodeProperties( node );
} ).then() );

Flux.from( readQuery ).blockLast( DEFAULT_BLOCKING_TIME_OUT );
Flux.from( readQuery ).blockLast();

assertEquals( expectedNodeCount, nodesSeen.get() );

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ public CompletionStage<Void> execute( C context )
}
else
{
context.setBookmark( session.lastBookmark() );
assertEquals( 1, summary.counters().nodesCreated() );
context.nodeCreated();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,10 @@ public CompletionStage<Void> execute( C context )

CompletionStage<ResultSummary> txCommitted = session.beginTransactionAsync().thenCompose( tx ->
tx.runAsync( "CREATE ()" ).thenCompose( cursor ->
cursor.consumeAsync().thenCompose( summary ->
tx.commitAsync().thenApply( ignore -> summary ) ) ) );
cursor.consumeAsync().thenCompose( summary -> tx.commitAsync().thenApply( ignore -> {
context.setBookmark( session.lastBookmark() );
return summary;
} ) ) ) );

return txCommitted.handle( ( summary, error ) ->
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
import org.neo4j.driver.AccessMode;
import org.neo4j.driver.Driver;
import org.neo4j.driver.Session;
import org.neo4j.driver.Result;
import org.neo4j.driver.summary.ResultSummary;

import static org.junit.jupiter.api.Assertions.assertEquals;

Expand All @@ -38,12 +38,13 @@ public BlockingWriteQuery( AbstractStressTestBase<C> stressTest, Driver driver,
@Override
public void execute( C context )
{
Result result = null;
ResultSummary summary = null;
Throwable queryError = null;

try ( Session session = newSession( AccessMode.WRITE, context ) )
{
result = session.run( "CREATE ()" );
summary = session.run( "CREATE ()" ).consume();
context.setBookmark( session.lastBookmark() );
}
catch ( Throwable error )
{
Expand All @@ -54,9 +55,9 @@ public void execute( C context )
}
}

if ( queryError == null && result != null )
if ( queryError == null && summary != null )
{
assertEquals( 1, result.consume().counters().nodesCreated() );
assertEquals( 1, summary.counters().nodesCreated() );
context.nodeCreated();
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@

import java.util.concurrent.CompletableFuture;
import java.util.concurrent.CompletionStage;
import java.util.concurrent.atomic.AtomicInteger;

import org.neo4j.driver.AccessMode;
import org.neo4j.driver.Driver;
Expand Down Expand Up @@ -51,8 +52,7 @@ public CompletionStage<Void> execute( C context )
RxSession::close )
.subscribe( record -> {
assertThat( record.get( 0 ).asInt(), either( equalTo( 1 ) ).or( equalTo( 2 ) ) );
queryFinished.complete( null );
}, error -> {
}, error -> {
Throwable cause = Futures.completionExceptionCause( error );
assertThat( cause, is( arithmeticError() ) );
queryFinished.complete( null );
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,6 @@ public CompletionStage<Void> execute( C context )
RxTransaction::commit, ( tx, error ) -> tx.rollback(), null )
.subscribe( record -> {
assertThat( record.get( 0 ).asInt(), either( equalTo( 1 ) ).or( equalTo( 2 ) ) );
queryFinished.complete( null );
}, error -> {
Throwable cause = Futures.completionExceptionCause( error );
assertThat( cause, is( arithmeticError() ) );
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,6 @@ public CompletionStage<Void> execute( C context )
RxSession::close )
.subscribe( record -> {
assertThat( record.get( 0 ).asInt(), either( equalTo( 1 ) ).or( equalTo( 2 ) ) );
queryFinished.complete( null );
}, error -> {
Throwable cause = Futures.completionExceptionCause( error );
assertThat( cause, is( arithmeticError() ) );
Expand Down
17 changes: 10 additions & 7 deletions driver/src/test/java/org/neo4j/driver/stress/RxWriteQuery.java
Original file line number Diff line number Diff line change
Expand Up @@ -47,24 +47,27 @@ public CompletionStage<Void> execute( C context )
{
CompletableFuture<Void> queryFinished = new CompletableFuture<>();
Flux.usingWhen( Mono.fromSupplier( () -> newSession( AccessMode.WRITE, context ) ),
session -> session.run( "CREATE ()" ).consume(), RxSession::close )
session -> Flux.from( session.run( "CREATE ()" ).consume() )
.doOnComplete( () -> context.setBookmark( session.lastBookmark() ) ),
RxSession::close )
.subscribe( summary -> {
queryFinished.complete( null );
assertEquals( 1, summary.counters().nodesCreated() );
context.nodeCreated();
}, error -> {
queryFinished.complete( null );
handleError( Futures.completionExceptionCause( error ), context );
} );
}, error -> handleError( Futures.completionExceptionCause( error ), context, queryFinished ) );

return queryFinished;
}

private void handleError( Throwable error, C context )
private void handleError( Throwable error, C context, CompletableFuture<Void> queryFinished )
{
if ( !stressTest.handleWriteFailure( error, context ) )
{
throw new RuntimeException( error );
queryFinished.completeExceptionally( error );
}
else
{
queryFinished.complete( null );
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -49,22 +49,26 @@ public CompletionStage<Void> execute( C context )
Flux.usingWhen( session.beginTransaction(), tx -> tx.run( "CREATE ()" ).consume(),
RxTransaction::commit, ( tx, error ) -> tx.rollback(), null ).subscribe(
summary -> {
context.setBookmark( session.lastBookmark() );
assertEquals( 1, summary.counters().nodesCreated() );
context.nodeCreated();
queryFinished.complete( null );
}, error -> {
handleError( Futures.completionExceptionCause( error ), context );
queryFinished.complete( null );
handleError( Futures.completionExceptionCause( error ), context, queryFinished );
} );

return queryFinished;
}

private void handleError( Throwable error, C context )
private void handleError( Throwable error, C context, CompletableFuture<Void> queryFinished )
{
if ( !stressTest.handleWriteFailure( error, context ) )
{
throw new RuntimeException( error );
queryFinished.completeExceptionally( error );
}
else
{
queryFinished.complete( null );
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -50,22 +50,23 @@ public CompletionStage<Void> execute( C context )
Flux.usingWhen( Mono.fromSupplier( () -> newSession( AccessMode.WRITE, context ) ),
session -> session.writeTransaction( tx -> tx.run( "CREATE ()" ).consume() ), RxSession::close )
.subscribe( summary -> {
queryFinished.complete( null );
assertEquals( 1, summary.counters().nodesCreated() );
context.nodeCreated();
}, error -> {
queryFinished.complete( null );
handleError( Futures.completionExceptionCause( error ), context );
} );
}, error -> handleError( Futures.completionExceptionCause( error ), context, queryFinished ) );

return queryFinished;
}

private void handleError( Throwable error, C context )
private void handleError( Throwable error, C context, CompletableFuture<Void> queryFinished )
{
if ( !stressTest.handleWriteFailure( error, context ) )
{
throw new RuntimeException( error );
queryFinished.completeExceptionally( error );
}
else
{
queryFinished.complete( null );
}
}
}