@@ -23,7 +23,8 @@ import parallelLimit from 'async/parallelLimit'
2323import _ from 'lodash'
2424import {
2525 ServerVersion ,
26- VERSION_3_2_0
26+ VERSION_3_2_0 ,
27+ VERSION_4_0_0
2728} from '../../src/v1/internal/server-version'
2829import sharedNeo4j from '../internal/shared-neo4j'
2930
@@ -43,13 +44,22 @@ describe('stress tests', () => {
4344
4445 const READ_QUERY = 'MATCH (n) RETURN n LIMIT 1'
4546 const WRITE_QUERY =
46- 'CREATE (person:Person:Employee {name: { name} , salary: { salary} }) RETURN person'
47+ 'CREATE (person:Person:Employee {name: $ name, salary: $ salary}) RETURN person'
4748
4849 const TEST_MODE = modeFromEnvOrDefault ( 'STRESS_TEST_MODE' )
4950 const DATABASE_URI = fromEnvOrDefault (
5051 'STRESS_TEST_DATABASE_URI' ,
5152 'bolt://localhost'
5253 )
54+
55+ const USERNAME = fromEnvOrDefault (
56+ 'NEO4J_USERNAME' ,
57+ sharedNeo4j . authToken . principal
58+ )
59+ const PASSWORD = fromEnvOrDefault (
60+ 'NEO4J_PASSWORD' ,
61+ sharedNeo4j . authToken . credentials
62+ )
5363 const LOGGING_ENABLED = fromEnvOrDefault ( 'STRESS_TEST_LOGGING_ENABLED' , false )
5464
5565 let originalTimeout
@@ -62,7 +72,11 @@ describe('stress tests', () => {
6272 const config = {
6373 logging : neo4j . logging . console ( LOGGING_ENABLED ? 'debug' : 'info' )
6474 }
65- driver = neo4j . driver ( DATABASE_URI , sharedNeo4j . authToken , config )
75+ driver = neo4j . driver (
76+ DATABASE_URI ,
77+ neo4j . auth . basic ( USERNAME , PASSWORD ) ,
78+ config
79+ )
6680
6781 cleanupDb ( driver ) . then ( ( ) => done ( ) )
6882 } )
@@ -237,7 +251,7 @@ describe('stress tests', () => {
237251 . run ( query , params )
238252 . then ( result => {
239253 context . queryCompleted ( result , accessMode )
240- context . log ( commandId , ` Query completed successfully` )
254+ context . log ( commandId , ' Query completed successfully' )
241255
242256 session . close ( ( ) => {
243257 const possibleError = verifyQueryResult ( result )
@@ -278,7 +292,7 @@ describe('stress tests', () => {
278292 resultPromise
279293 . then ( result => {
280294 context . queryCompleted ( result , accessMode , session . lastBookmark ( ) )
281- context . log ( commandId , ` Transaction function executed successfully` )
295+ context . log ( commandId , ' Transaction function executed successfully' )
282296
283297 session . close ( ( ) => {
284298 const possibleError = verifyQueryResult ( result )
@@ -328,7 +342,7 @@ describe('stress tests', () => {
328342 } )
329343 . then ( ( ) => {
330344 context . queryCompleted ( result , accessMode , session . lastBookmark ( ) )
331- context . log ( commandId , ` Transaction committed successfully` )
345+ context . log ( commandId , ' Transaction committed successfully' )
332346
333347 session . close ( ( ) => {
334348 callback ( commandError )
@@ -347,7 +361,7 @@ describe('stress tests', () => {
347361
348362 function verifyQueryResult ( result ) {
349363 if ( ! result ) {
350- return new Error ( ` Received undefined result` )
364+ return new Error ( ' Received undefined result' )
351365 } else if ( result . records . length === 0 ) {
352366 // it is ok to receive no nodes back for read queries at the beginning of the test
353367 return null
@@ -467,13 +481,27 @@ describe('stress tests', () => {
467481 session . close ( )
468482 const records = result . records
469483
470- const followers = addressesWithRole ( records , 'FOLLOWER' )
471- const readReplicas = addressesWithRole ( records , 'READ_REPLICA' )
484+ const version = ServerVersion . fromString ( result . summary . server . version )
485+ const supportsMultiDb = version . compareTo ( VERSION_4_0_0 ) >= 0
486+ const followers = supportsMultiDb
487+ ? addressesForMultiDb ( records , 'FOLLOWER' )
488+ : addressesWithRole ( records , 'FOLLOWER' )
489+ const readReplicas = supportsMultiDb
490+ ? addressesForMultiDb ( records , 'READ_REPLICA' )
491+ : addressesWithRole ( records , 'READ_REPLICA' )
472492
473493 return new ClusterAddresses ( followers , readReplicas )
474494 } )
475495 }
476496
497+ function addressesForMultiDb ( records , role , db = 'neo4j' ) {
498+ return _ . uniq (
499+ records
500+ . filter ( record => record . get ( 'databases' ) [ db ] === role )
501+ . map ( record => record . get ( 'addresses' ) [ 0 ] . replace ( 'bolt://' , '' ) )
502+ )
503+ }
504+
477505 function addressesWithRole ( records , role ) {
478506 return _ . uniq (
479507 records
0 commit comments