@@ -23,7 +23,7 @@ import parallelLimit from 'async/parallelLimit'
23
23
import _ from 'lodash'
24
24
import {
25
25
ServerVersion ,
26
- VERSION_3_2_0
26
+ VERSION_4_0_0
27
27
} from '../../src/v1/internal/server-version'
28
28
import sharedNeo4j from '../internal/shared-neo4j'
29
29
@@ -43,13 +43,22 @@ describe('stress tests', () => {
43
43
44
44
const READ_QUERY = 'MATCH (n) RETURN n LIMIT 1'
45
45
const WRITE_QUERY =
46
- 'CREATE (person:Person:Employee {name: { name} , salary: { salary} }) RETURN person'
46
+ 'CREATE (person:Person:Employee {name: $ name, salary: $ salary}) RETURN person'
47
47
48
48
const TEST_MODE = modeFromEnvOrDefault ( 'STRESS_TEST_MODE' )
49
49
const DATABASE_URI = fromEnvOrDefault (
50
50
'STRESS_TEST_DATABASE_URI' ,
51
51
'bolt://localhost'
52
52
)
53
+
54
+ const USERNAME = fromEnvOrDefault (
55
+ 'NEO4J_USERNAME' ,
56
+ sharedNeo4j . authToken . principal
57
+ )
58
+ const PASSWORD = fromEnvOrDefault (
59
+ 'NEO4J_PASSWORD' ,
60
+ sharedNeo4j . authToken . credentials
61
+ )
53
62
const LOGGING_ENABLED = fromEnvOrDefault ( 'STRESS_TEST_LOGGING_ENABLED' , false )
54
63
55
64
let originalTimeout
@@ -62,7 +71,11 @@ describe('stress tests', () => {
62
71
const config = {
63
72
logging : neo4j . logging . console ( LOGGING_ENABLED ? 'debug' : 'info' )
64
73
}
65
- driver = neo4j . driver ( DATABASE_URI , sharedNeo4j . authToken , config )
74
+ driver = neo4j . driver (
75
+ DATABASE_URI ,
76
+ neo4j . auth . basic ( USERNAME , PASSWORD ) ,
77
+ config
78
+ )
66
79
67
80
cleanupDb ( driver ) . then ( ( ) => done ( ) )
68
81
} )
@@ -237,7 +250,7 @@ describe('stress tests', () => {
237
250
. run ( query , params )
238
251
. then ( result => {
239
252
context . queryCompleted ( result , accessMode )
240
- context . log ( commandId , ` Query completed successfully` )
253
+ context . log ( commandId , ' Query completed successfully' )
241
254
242
255
session . close ( ( ) => {
243
256
const possibleError = verifyQueryResult ( result )
@@ -278,7 +291,7 @@ describe('stress tests', () => {
278
291
resultPromise
279
292
. then ( result => {
280
293
context . queryCompleted ( result , accessMode , session . lastBookmark ( ) )
281
- context . log ( commandId , ` Transaction function executed successfully` )
294
+ context . log ( commandId , ' Transaction function executed successfully' )
282
295
283
296
session . close ( ( ) => {
284
297
const possibleError = verifyQueryResult ( result )
@@ -328,7 +341,7 @@ describe('stress tests', () => {
328
341
} )
329
342
. then ( ( ) => {
330
343
context . queryCompleted ( result , accessMode , session . lastBookmark ( ) )
331
- context . log ( commandId , ` Transaction committed successfully` )
344
+ context . log ( commandId , ' Transaction committed successfully' )
332
345
333
346
session . close ( ( ) => {
334
347
callback ( commandError )
@@ -347,7 +360,7 @@ describe('stress tests', () => {
347
360
348
361
function verifyQueryResult ( result ) {
349
362
if ( ! result ) {
350
- return new Error ( ` Received undefined result` )
363
+ return new Error ( ' Received undefined result' )
351
364
} else if ( result . records . length === 0 ) {
352
365
// it is ok to receive no nodes back for read queries at the beginning of the test
353
366
return null
@@ -467,13 +480,27 @@ describe('stress tests', () => {
467
480
session . close ( )
468
481
const records = result . records
469
482
470
- const followers = addressesWithRole ( records , 'FOLLOWER' )
471
- const readReplicas = addressesWithRole ( records , 'READ_REPLICA' )
483
+ const version = ServerVersion . fromString ( result . summary . server . version )
484
+ const supportsMultiDb = version . compareTo ( VERSION_4_0_0 ) >= 0
485
+ const followers = supportsMultiDb
486
+ ? addressesForMultiDb ( records , 'FOLLOWER' )
487
+ : addressesWithRole ( records , 'FOLLOWER' )
488
+ const readReplicas = supportsMultiDb
489
+ ? addressesForMultiDb ( records , 'READ_REPLICA' )
490
+ : addressesWithRole ( records , 'READ_REPLICA' )
472
491
473
492
return new ClusterAddresses ( followers , readReplicas )
474
493
} )
475
494
}
476
495
496
+ function addressesForMultiDb ( records , role , db = 'neo4j' ) {
497
+ return _ . uniq (
498
+ records
499
+ . filter ( record => record . get ( 'databases' ) [ db ] === role )
500
+ . map ( record => record . get ( 'addresses' ) [ 0 ] . replace ( 'bolt://' , '' ) )
501
+ )
502
+ }
503
+
477
504
function addressesWithRole ( records , role ) {
478
505
return _ . uniq (
479
506
records
0 commit comments