@@ -23,7 +23,8 @@ import parallelLimit from 'async/parallelLimit'
23
23
import _ from 'lodash'
24
24
import {
25
25
ServerVersion ,
26
- VERSION_3_2_0
26
+ VERSION_3_2_0 ,
27
+ VERSION_4_0_0
27
28
} from '../../src/v1/internal/server-version'
28
29
import sharedNeo4j from '../internal/shared-neo4j'
29
30
@@ -43,13 +44,22 @@ describe('stress tests', () => {
43
44
44
45
const READ_QUERY = 'MATCH (n) RETURN n LIMIT 1'
45
46
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'
47
48
48
49
const TEST_MODE = modeFromEnvOrDefault ( 'STRESS_TEST_MODE' )
49
50
const DATABASE_URI = fromEnvOrDefault (
50
51
'STRESS_TEST_DATABASE_URI' ,
51
52
'bolt://localhost'
52
53
)
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
+ )
53
63
const LOGGING_ENABLED = fromEnvOrDefault ( 'STRESS_TEST_LOGGING_ENABLED' , false )
54
64
55
65
let originalTimeout
@@ -62,7 +72,11 @@ describe('stress tests', () => {
62
72
const config = {
63
73
logging : neo4j . logging . console ( LOGGING_ENABLED ? 'debug' : 'info' )
64
74
}
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
+ )
66
80
67
81
cleanupDb ( driver ) . then ( ( ) => done ( ) )
68
82
} )
@@ -237,7 +251,7 @@ describe('stress tests', () => {
237
251
. run ( query , params )
238
252
. then ( result => {
239
253
context . queryCompleted ( result , accessMode )
240
- context . log ( commandId , ` Query completed successfully` )
254
+ context . log ( commandId , ' Query completed successfully' )
241
255
242
256
session . close ( ( ) => {
243
257
const possibleError = verifyQueryResult ( result )
@@ -278,7 +292,7 @@ describe('stress tests', () => {
278
292
resultPromise
279
293
. then ( result => {
280
294
context . queryCompleted ( result , accessMode , session . lastBookmark ( ) )
281
- context . log ( commandId , ` Transaction function executed successfully` )
295
+ context . log ( commandId , ' Transaction function executed successfully' )
282
296
283
297
session . close ( ( ) => {
284
298
const possibleError = verifyQueryResult ( result )
@@ -328,7 +342,7 @@ describe('stress tests', () => {
328
342
} )
329
343
. then ( ( ) => {
330
344
context . queryCompleted ( result , accessMode , session . lastBookmark ( ) )
331
- context . log ( commandId , ` Transaction committed successfully` )
345
+ context . log ( commandId , ' Transaction committed successfully' )
332
346
333
347
session . close ( ( ) => {
334
348
callback ( commandError )
@@ -347,7 +361,7 @@ describe('stress tests', () => {
347
361
348
362
function verifyQueryResult ( result ) {
349
363
if ( ! result ) {
350
- return new Error ( ` Received undefined result` )
364
+ return new Error ( ' Received undefined result' )
351
365
} else if ( result . records . length === 0 ) {
352
366
// it is ok to receive no nodes back for read queries at the beginning of the test
353
367
return null
@@ -467,13 +481,27 @@ describe('stress tests', () => {
467
481
session . close ( )
468
482
const records = result . records
469
483
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' )
472
492
473
493
return new ClusterAddresses ( followers , readReplicas )
474
494
} )
475
495
}
476
496
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
+
477
505
function addressesWithRole ( records , role ) {
478
506
return _ . uniq (
479
507
records
0 commit comments