@@ -640,6 +640,7 @@ describe('routing driver ', function () {
640640 } ) ;
641641 } ) ;
642642 } ) ;
643+
643644 it ( 'should re-use connections' , function ( done ) {
644645 if ( ! boltkit . BoltKitSupport ) {
645646 done ( ) ;
@@ -674,10 +675,118 @@ describe('routing driver ', function () {
674675 } ) ;
675676 } ) ;
676677
677- function newDriver ( url ) {
678- // BoltKit currently does not support encryption, create driver with encryption turned off
679- return neo4j . driver ( url , neo4j . auth . basic ( "neo4j" , "neo4j" ) , {
680- encrypted : "ENCRYPTION_OFF"
678+ it ( 'should expose server info in cluster' , function ( done ) {
679+ if ( ! boltkit . BoltKitSupport ) {
680+ done ( ) ;
681+ return ;
682+ }
683+
684+ // Given
685+ const kit = new boltkit . BoltKit ( ) ;
686+ const routingServer = kit . start ( './test/resources/boltkit/acquire_endpoints.script' , 9001 ) ;
687+ const writeServer = kit . start ( './test/resources/boltkit/write_server_with_version.script' , 9007 ) ;
688+ const readServer = kit . start ( './test/resources/boltkit/read_server_with_version.script' , 9005 ) ;
689+
690+ kit . run ( function ( ) {
691+ const driver = newDriver ( "bolt+routing://127.0.0.1:9001" ) ;
692+ // When
693+ const readSession = driver . session ( neo4j . session . READ ) ;
694+ readSession . run ( 'MATCH (n) RETURN n.name' ) . then ( readResult => {
695+ const writeSession = driver . session ( neo4j . session . WRITE ) ;
696+ writeSession . run ( "CREATE (n {name:'Bob'})" ) . then ( writeResult => {
697+ const readServerInfo = readResult . summary . server ;
698+ const writeServerInfo = writeResult . summary . server ;
699+
700+ readSession . close ( ) ;
701+ writeSession . close ( ) ;
702+ driver . close ( ) ;
703+
704+ routingServer . exit ( routingServerExitCode => {
705+ writeServer . exit ( writeServerExitCode => {
706+ readServer . exit ( readServerExitCode => {
707+
708+ expect ( readServerInfo . address ) . toBe ( '127.0.0.1:9005' ) ;
709+ expect ( readServerInfo . version ) . toBe ( 'TheReadServerV1' ) ;
710+
711+ expect ( writeServerInfo . address ) . toBe ( '127.0.0.1:9007' ) ;
712+ expect ( writeServerInfo . version ) . toBe ( 'TheWriteServerV1' ) ;
713+
714+ expect ( routingServerExitCode ) . toEqual ( 0 ) ;
715+ expect ( writeServerExitCode ) . toEqual ( 0 ) ;
716+ expect ( readServerExitCode ) . toEqual ( 0 ) ;
717+
718+ done ( ) ;
719+ } ) ;
720+ } ) ;
721+ } ) ;
722+ } )
681723 } ) ;
724+ } ) ;
725+ } ) ;
726+
727+ it ( 'should expose server info in cluster using observer' , function ( done ) {
728+ if ( ! boltkit . BoltKitSupport ) {
729+ done ( ) ;
730+ return ;
731+ }
732+
733+ // Given
734+ const kit = new boltkit . BoltKit ( ) ;
735+ const routingServer = kit . start ( './test/resources/boltkit/acquire_endpoints.script' , 9001 ) ;
736+ const writeServer = kit . start ( './test/resources/boltkit/write_server_with_version.script' , 9007 ) ;
737+ const readServer = kit . start ( './test/resources/boltkit/read_server_with_version.script' , 9005 ) ;
738+
739+ kit . run ( function ( ) {
740+ const driver = newDriver ( "bolt+routing://127.0.0.1:9001" ) ;
741+ // When
742+ const readSession = driver . session ( neo4j . session . READ ) ;
743+ readSession . run ( 'MATCH (n) RETURN n.name' ) . subscribe ( {
744+ onNext : ( ) => {
745+ } ,
746+ onError : ( ) => {
747+ } ,
748+ onCompleted : readSummary => {
749+ const writeSession = driver . session ( neo4j . session . WRITE ) ;
750+ writeSession . run ( "CREATE (n {name:'Bob'})" ) . subscribe ( {
751+ onNext : ( ) => {
752+ } ,
753+ onError : ( ) => {
754+ } ,
755+ onCompleted : writeSummary => {
756+ readSession . close ( ) ;
757+ writeSession . close ( ) ;
758+ driver . close ( ) ;
759+
760+ routingServer . exit ( function ( routingServerExitCode ) {
761+ writeServer . exit ( function ( writeServerExitCode ) {
762+ readServer . exit ( function ( readServerExitCode ) {
763+
764+ expect ( readSummary . server . address ) . toBe ( '127.0.0.1:9005' ) ;
765+ expect ( readSummary . server . version ) . toBe ( 'TheReadServerV1' ) ;
766+
767+ expect ( writeSummary . server . address ) . toBe ( '127.0.0.1:9007' ) ;
768+ expect ( writeSummary . server . version ) . toBe ( 'TheWriteServerV1' ) ;
769+
770+ expect ( routingServerExitCode ) . toEqual ( 0 ) ;
771+ expect ( writeServerExitCode ) . toEqual ( 0 ) ;
772+ expect ( readServerExitCode ) . toEqual ( 0 ) ;
773+
774+ done ( ) ;
775+ } ) ;
776+ } ) ;
777+ } ) ;
778+ }
779+ } )
780+ }
781+ } ) ;
782+ } ) ;
783+ } ) ;
784+
785+ function newDriver ( url ) {
786+ // BoltKit currently does not support encryption, create driver with encryption turned off
787+ return neo4j . driver ( url , neo4j . auth . basic ( "neo4j" , "neo4j" ) , {
788+ encrypted : "ENCRYPTION_OFF"
789+ } ) ;
682790 }
791+
683792} ) ;
0 commit comments