Skip to content

Commit 074ed24

Browse files
committed
Add BoltKitIt for the new routing
1 parent 77cf8fa commit 074ed24

File tree

2 files changed

+47
-0
lines changed

2 files changed

+47
-0
lines changed

driver/src/test/java/org/neo4j/driver/integration/RoutingDriverBoltKitIT.java

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -613,6 +613,40 @@ void shouldHandleLeaderSwitchAndRetryWhenWritingInTxFunctionAsync() throws IOExc
613613
assertThat( writeServer.exitStatus(), equalTo( 0 ) );
614614
}
615615

616+
@Test
617+
void shouldHandleLeaderSwitchAndRetryWhenWritingInTxFunctionAsyncV43() throws IOException, InterruptedException
618+
{
619+
// Given
620+
StubServer server = stubController.startStub( "acquire_endpoints_twice_v43.script", 9001 );
621+
622+
// START a write server that fails on the first write attempt but then succeeds on the second
623+
StubServer writeServer = stubController.startStub( "not_able_to_write_server_tx_func_retries.script", 9007 );
624+
URI uri = URI.create( "neo4j://127.0.0.1:9001" );
625+
626+
Driver driver = GraphDatabase.driver( uri, Config.builder().withMaxTransactionRetryTime( 1, TimeUnit.MILLISECONDS ).build() );
627+
AsyncSession session = driver.asyncSession( builder().withDatabase( "mydatabase" ).build() );
628+
List<String> names = Futures.blockingGet( session.writeTransactionAsync(
629+
tx -> tx.runAsync( "RETURN 1" )
630+
.thenComposeAsync( ignored -> {
631+
try
632+
{
633+
Thread.sleep( 100 );
634+
}
635+
catch ( InterruptedException ex )
636+
{
637+
}
638+
return tx.runAsync( "MATCH (n) RETURN n.name" );
639+
} )
640+
.thenComposeAsync( cursor -> cursor.listAsync( RoutingDriverBoltKitIT::extractNameField ) ) ) );
641+
642+
assertEquals( asList( "Foo", "Bar" ), names );
643+
644+
// Finally
645+
driver.close();
646+
assertThat( server.exitStatus(), equalTo( 0 ) );
647+
assertThat( writeServer.exitStatus(), equalTo( 0 ) );
648+
}
649+
616650
private static String extractNameField(Record record)
617651
{
618652
return record.get( 0 ).asString();
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
!: BOLT 4.3
2+
!: AUTO RESET
3+
!: AUTO HELLO
4+
!: AUTO GOODBYE
5+
6+
C: ROUTE { "address": "127.0.0.1:9001"} "mydatabase"
7+
S: SUCCESS {"rt": { "ttl": 9223372036854775807, "servers": [{"addresses": ["127.0.0.1:9007"],"role": "WRITE"}, {"addresses": ["127.0.0.1:9005","127.0.0.1:9006"], "role": "READ"},{"addresses": ["127.0.0.1:9001","127.0.0.1:9002","127.0.0.1:9003"], "role": "ROUTE"}] }}
8+
C: RUN "CALL dbms.routing.getRoutingTable($context, $database)" {"context": { "address": "127.0.0.1:9001"}, "database": "mydatabase"} {"mode": "r", "db": "system"}
9+
PULL {"n": -1}
10+
S: SUCCESS {"fields": ["ttl", "servers"]}
11+
RECORD [9223372036854775807, [{"addresses": ["127.0.0.1:9007"],"role": "WRITE"}, {"addresses": ["127.0.0.1:9005","127.0.0.1:9006"], "role": "READ"},{"addresses": ["127.0.0.1:9001","127.0.0.1:9002","127.0.0.1:9003"], "role": "ROUTE"}]]
12+
SUCCESS {}
13+
<EXIT>

0 commit comments

Comments
 (0)