DirectConnectionProvider implements ConnectionProvider { @Override public CompletionStage<Connection> acquireConnection( ConnectionContext context ) { return acquireConnection().thenApply( connection -> new DirectConnection( connection, context.databaseName(), context.mode() ) ); } DirectConnectionProvider( BoltServerAddress address, ConnectionPool connectionPool ); @Override CompletionStage<Connection> acquireConnection( ConnectionContext context ); @Override CompletionStage<Void> verifyConnectivity(); @Override CompletionStage<Void> close(); @Override CompletionStage<Boolean> supportsMultiDb(); BoltServerAddress getAddress();  }
@Test void acquiresConnectionsFromThePool() { BoltServerAddress address = BoltServerAddress.LOCAL_DEFAULT; Connection connection1 = mock( Connection.class ); Connection connection2 = mock( Connection.class ); ConnectionPool pool = poolMock( address, connection1, connection2 ); DirectConnectionProvider provider = new DirectConnectionProvider( address, pool ); Connection acquired1 = await( provider.acquireConnection( contextWithMode( READ ) ) ); assertThat( acquired1, instanceOf( DirectConnection.class ) ); assertSame( connection1, ((DirectConnection) acquired1).connection() ); Connection acquired2 = await( provider.acquireConnection( contextWithMode( WRITE ) ) ); assertThat( acquired2, instanceOf( DirectConnection.class ) ); assertSame( connection2, ((DirectConnection) acquired2).connection() ); }
@Test void shouldIgnoreDatabaseNameAndAccessModeWhenObtainConnectionFromPool() throws Throwable { BoltServerAddress address = BoltServerAddress.LOCAL_DEFAULT; Connection connection = mock( Connection.class ); ConnectionPool pool = poolMock( address, connection ); DirectConnectionProvider provider = new DirectConnectionProvider( address, pool ); Connection acquired1 = await( provider.acquireConnection( contextWithMode( READ ) ) ); assertThat( acquired1, instanceOf( DirectConnection.class ) ); assertSame( connection, ((DirectConnection) acquired1).connection() ); verify( pool ).acquire( address ); }