Skip to content

Commit

Permalink
Add Temporary:ResultKeys support in Testkit backend (#1113)
Browse files Browse the repository at this point in the history
  • Loading branch information
injectives authored Jan 14, 2022
1 parent 47442f5 commit 868f846
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,8 @@ public class GetFeatures implements TestkitRequest
"Temporary:ConnectionAcquisitionTimeout",
"Temporary:GetConnectionPoolMetrics",
"Temporary:CypherPathAndRelationship",
"Temporary:FullSummary"
"Temporary:FullSummary",
"Temporary:ResultKeys"
) );

private static final Set<String> SYNC_FEATURES = new HashSet<>( Arrays.asList(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
import reactor.core.publisher.Mono;

import java.time.Duration;
import java.util.List;
import java.util.Map;
import java.util.Optional;
import java.util.concurrent.CompletionStage;
Expand Down Expand Up @@ -63,7 +64,7 @@ public TestkitResponse process( TestkitState testkitState )
org.neo4j.driver.Result result = session.run( query, transactionConfig.build() );
String id = testkitState.addResultHolder( new ResultHolder( sessionHolder, result ) );

return createResponse( id );
return createResponse( id, result.keys() );
}

@Override
Expand All @@ -86,7 +87,7 @@ public CompletionStage<TestkitResponse> processAsync( TestkitState testkitState
{
String id = testkitState.addAsyncResultHolder(
new ResultCursorHolder( sessionHolder, resultCursor ) );
return createResponse( id );
return createResponse( id, resultCursor.keys() );
} );
} );
}
Expand All @@ -111,13 +112,13 @@ public Mono<TestkitResponse> processRx( TestkitState testkitState )
// The keys() method causes RUN message exchange.
// However, it does not currently report errors.
return Mono.fromDirect( result.keys() )
.map( ignored -> createResponse( id ) );
.map( keys -> createResponse( id, keys ) );
} );
}

private Result createResponse( String resultId )
private Result createResponse( String resultId, List<String> keys )
{
return Result.builder().data( Result.ResultBody.builder().id( resultId ).build() ).build();
return Result.builder().data( Result.ResultBody.builder().id( resultId ).keys( keys ).build() ).build();
}

@Setter
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
import reactor.core.publisher.Mono;

import java.util.Collections;
import java.util.List;
import java.util.Map;
import java.util.concurrent.CompletionStage;

Expand All @@ -50,7 +51,7 @@ public TestkitResponse process( TestkitState testkitState )
org.neo4j.driver.Result result = transactionHolder.getTransaction()
.run( data.getCypher(), data.getParams() != null ? data.getParams() : Collections.emptyMap() );
String resultId = testkitState.addResultHolder( new ResultHolder( transactionHolder, result ) );
return createResponse( resultId );
return createResponse( resultId, result.keys() );
}

@Override
Expand All @@ -65,7 +66,7 @@ public CompletionStage<TestkitResponse> processAsync( TestkitState testkitState
String resultId = testkitState.addAsyncResultHolder(
new ResultCursorHolder( transactionHolder,
resultCursor ) );
return createResponse( resultId );
return createResponse( resultId, resultCursor.keys() );
} ) );
}

Expand All @@ -81,13 +82,13 @@ public Mono<TestkitResponse> processRx( TestkitState testkitState )
String resultId = testkitState.addRxResultHolder( new RxResultHolder( transactionHolder, result ) );
// The keys() method causes RUN message exchange.
// However, it does not currently report errors.
return Mono.fromDirect( result.keys() ).then( Mono.just( createResponse( resultId ) ) );
return Mono.fromDirect( result.keys() ).map( keys -> createResponse( resultId, keys ) );
} );
}

protected Result createResponse( String resultId )
protected Result createResponse( String resultId, List<String> keys )
{
return Result.builder().data( Result.ResultBody.builder().id( resultId ).build() ).build();
return Result.builder().data( Result.ResultBody.builder().id( resultId ).keys( keys ).build() ).build();
}

@Setter
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@
import lombok.Builder;
import lombok.Getter;

import java.util.List;

@Getter
@Builder
public class Result implements TestkitResponse
Expand All @@ -38,5 +40,7 @@ public String testkitName()
public static class ResultBody
{
private String id;

private List<String> keys;
}
}

0 comments on commit 868f846

Please sign in to comment.