BoltProtocolV3 implements BoltProtocol { @Override public CompletionStage<Void> beginTransaction( Connection connection, Bookmark bookmark, TransactionConfig config ) { try { verifyDatabaseNameBeforeTransaction( connection.databaseName() ); } catch ( Exception error ) { return Futures.failedFuture( error ); } BeginMessage beginMessage = new BeginMessage( bookmark, config, connection.databaseName(), connection.mode() ); if ( bookmark.isEmpty() ) { connection.write( beginMessage, NoOpResponseHandler.INSTANCE ); return Futures.completedWithNull(); } else { CompletableFuture<Void> beginTxFuture = new CompletableFuture<>(); connection.writeAndFlush( beginMessage, new BeginTxResponseHandler( beginTxFuture ) ); return beginTxFuture; } }  @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 shouldBeginTransactionWithoutBookmark() { Connection connection = connectionMock( protocol ); CompletionStage<Void> stage = protocol.beginTransaction( connection, InternalBookmark.empty(), TransactionConfig.empty() ); verify( connection ).write( new BeginMessage( InternalBookmark.empty(), TransactionConfig.empty(), defaultDatabase(), WRITE ), NoOpResponseHandler.INSTANCE ); assertNull( await( stage ) ); }
@Test void shouldBeginTransactionWithBookmarks() { Connection connection = connectionMock( protocol ); Bookmark bookmark = InternalBookmark.parse( "neo4j:bookmark:v1:tx100" ); CompletionStage<Void> stage = protocol.beginTransaction( connection, bookmark, TransactionConfig.empty() ); verify( connection ).writeAndFlush( eq( new BeginMessage( bookmark, TransactionConfig.empty(), defaultDatabase(), WRITE ) ), any( BeginTxResponseHandler.class ) ); assertNull( await( stage ) ); }
@Test void shouldBeginTransactionWithConfig() { Connection connection = connectionMock( protocol ); CompletionStage<Void> stage = protocol.beginTransaction( connection, InternalBookmark.empty(), txConfig ); verify( connection ).write( new BeginMessage( InternalBookmark.empty(), txConfig, defaultDatabase(), WRITE ), NoOpResponseHandler.INSTANCE ); assertNull( await( stage ) ); }
@Test void shouldBeginTransactionWithBookmarksAndConfig() { Connection connection = connectionMock( protocol ); Bookmark bookmark = InternalBookmark.parse( "neo4j:bookmark:v1:tx4242" ); CompletionStage<Void> stage = protocol.beginTransaction( connection, bookmark, txConfig ); verify( connection ).writeAndFlush( eq( new BeginMessage( bookmark, txConfig, defaultDatabase(), WRITE ) ), any( BeginTxResponseHandler.class ) ); assertNull( await( stage ) ); }
@Test void shouldNotSupportDatabaseNameInBeginTransaction() { CompletionStage<Void> txStage = protocol.beginTransaction( connectionMock( "foo", protocol ), InternalBookmark.empty(), TransactionConfig.empty() ); ClientException e = assertThrows( ClientException.class, () -> await( txStage ) ); assertThat( e.getMessage(), startsWith( "Database name parameter for selecting database is not supported" ) ); }