BoltProtocolV3 implements BoltProtocol { @Override public void initializeChannel( String userAgent, AuthToken authToken, RoutingContext routingContext, ChannelPromise channelInitializedPromise ) { Channel channel = channelInitializedPromise.channel(); HelloMessage message; if ( routingContext.isServerRoutingEnabled() ) { message = new HelloMessage( userAgent, ( ( InternalAuthToken ) authToken ).toMap(), routingContext.toMap() ); } else { message = new HelloMessage( userAgent, ( ( InternalAuthToken ) authToken ).toMap(), null ); } HelloResponseHandler handler = new HelloResponseHandler( channelInitializedPromise, version() ); messageDispatcher( channel ).enqueue( handler ); channel.writeAndFlush( message, channel.voidPromise() ); }  @Override MessageFormat createMessageFormat(); @Override void initializeChannel( String userAgent, AuthToken authToken, RoutingContext routingContext, ChannelPromise channelInitializedPromise ); @Override void prepareToCloseChannel( Channel channel ); @Override CompletionStage<Void> beginTransaction( Connection connection, Bookmark bookmark, TransactionConfig config ); @Override CompletionStage<Bookmark> commitTransaction( Connection connection ); @Override CompletionStage<Void> rollbackTransaction( Connection connection ); @Override ResultCursorFactory runInAutoCommitTransaction(Connection connection, Query query, BookmarkHolder bookmarkHolder,
                                                          TransactionConfig config, boolean waitForRunResponse, long fetchSize ); @Override ResultCursorFactory runInUnmanagedTransaction(Connection connection, Query query, UnmanagedTransaction tx,
                                                         boolean waitForRunResponse, long fetchSize ); @Override BoltProtocolVersion version(); static final BoltProtocolVersion VERSION; static final BoltProtocol INSTANCE; static final MetadataExtractor METADATA_EXTRACTOR; }
@Test void shouldInitializeChannel() { ChannelPromise promise = channel.newPromise(); protocol.initializeChannel( "MyDriver/0.0.1", dummyAuthToken(), RoutingContext.EMPTY, promise ); assertThat( channel.outboundMessages(), hasSize( 1 ) ); assertThat( channel.outboundMessages().poll(), instanceOf( HelloMessage.class ) ); assertEquals( 1, messageDispatcher.queuedHandlersCount() ); assertFalse( promise.isDone() ); Map<String,Value> metadata = new HashMap<>(); metadata.put( "server", value( anyServerVersion().toString() ) ); metadata.put( "connection_id", value( "bolt-42" ) ); messageDispatcher.handleSuccessMessage( metadata ); assertTrue( promise.isDone() ); assertTrue( promise.isSuccess() ); }
@Test void shouldFailToInitializeChannelWhenErrorIsReceived() { ChannelPromise promise = channel.newPromise(); protocol.initializeChannel( "MyDriver/2.2.1", dummyAuthToken(), RoutingContext.EMPTY, promise ); assertThat( channel.outboundMessages(), hasSize( 1 ) ); assertThat( channel.outboundMessages().poll(), instanceOf( HelloMessage.class ) ); assertEquals( 1, messageDispatcher.queuedHandlersCount() ); assertFalse( promise.isDone() ); messageDispatcher.handleFailureMessage( "Neo.TransientError.General.DatabaseUnavailable", "Error!" ); assertTrue( promise.isDone() ); assertFalse( promise.isSuccess() ); }