Skip to content

Commit b26a781

Browse files
committed
Add sub milliseconds behaviour to Rx
1 parent b9d0cff commit b26a781

File tree

4 files changed

+126
-6
lines changed

4 files changed

+126
-6
lines changed

packages/neo4j-driver/src/driver.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -72,9 +72,11 @@ class Driver extends CoreDriver {
7272
reactive: false,
7373
fetchSize: validateFetchSizeValue(fetchSize, this._config.fetchSize),
7474
bookmarkManager,
75-
notificationFilter
75+
notificationFilter,
76+
log: this._log
7677
}),
77-
config: this._config
78+
config: this._config,
79+
log: this._log
7880
})
7981
}
8082
}

packages/neo4j-driver/src/session-rx.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,9 +41,10 @@ export default class RxSession {
4141
* @param {Object} param - Object parameter
4242
* @param {Session} param.session - The underlying session instance to relay requests
4343
*/
44-
constructor ({ session, config } = {}) {
44+
constructor ({ session, config, log } = {}) {
4545
this._session = session
4646
this._retryLogic = _createRetryLogic(config)
47+
this._log = log
4748
}
4849

4950
/**
@@ -200,7 +201,7 @@ export default class RxSession {
200201
_beginTransaction (accessMode, transactionConfig) {
201202
let txConfig = TxConfig.empty()
202203
if (transactionConfig) {
203-
txConfig = new TxConfig(transactionConfig)
204+
txConfig = new TxConfig(transactionConfig, this._log)
204205
}
205206

206207
return new Observable(observer => {

packages/neo4j-driver/test/driver.test.js

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -174,6 +174,18 @@ describe('#unit driver', () => {
174174
expect(session._session._bookmarkManager).toEqual(configuredBookmarkManager)
175175
})
176176
})
177+
178+
it('should redirect logger to session', () => {
179+
driver = neo4j.driver(
180+
`neo4j+ssc://${sharedNeo4j.hostname}`,
181+
sharedNeo4j.authToken
182+
)
183+
184+
const session = driver.rxSession()
185+
186+
expect(session._log).toBe(driver._log)
187+
expect(session._session._log).toBe(driver._log)
188+
})
177189
})
178190
})
179191

packages/neo4j-driver/test/rx/session.test.js

Lines changed: 107 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919

2020
import { Notification, throwError } from 'rxjs'
2121
import { map, materialize, toArray, concatWith } from 'rxjs/operators'
22-
import neo4j from '../../src'
22+
import neo4j, { ResultSummary, int } from '../../src'
2323
import RxSession from '../../src/session-rx'
2424
import sharedNeo4j from '../internal/shared-neo4j'
2525
import {
@@ -31,7 +31,7 @@ import {
3131
} from 'neo4j-driver-core'
3232

3333
const { SERVICE_UNAVAILABLE, SESSION_EXPIRED } = error
34-
const { bookmarks } = internal
34+
const { bookmarks, logger } = internal
3535

3636
describe('#integration rx-session', () => {
3737
let driver
@@ -442,6 +442,111 @@ describe('#unit rx-session', () => {
442442
})
443443
})
444444

445+
describe('.run()', () => {
446+
it('should redirect run to the underline session', () => {
447+
const capture = []
448+
const _session = {
449+
run: (...args) => {
450+
capture.push(args)
451+
const summary = new ResultSummary(args[0], args[1], {}, 5.3)
452+
return {
453+
async * [Symbol.asyncIterator] () {
454+
return summary
455+
},
456+
async summary () {
457+
return summary
458+
}
459+
}
460+
}
461+
}
462+
const session = new RxSession({ session: _session })
463+
const query = 'the query'
464+
const params = {}
465+
const txConfig = { timeout: 1000 }
466+
467+
session.run(query, params, txConfig).records().subscribe()
468+
469+
expect(capture).toEqual([[query, params, txConfig]])
470+
})
471+
})
472+
473+
describe('._beginTransaction()', () => {
474+
it('should round up sub milliseconds transaction timeouts', () => {
475+
const capture = []
476+
const _session = {
477+
_beginTransaction: async (...args) => {
478+
capture.push(args)
479+
return {}
480+
}
481+
}
482+
483+
const session = new RxSession({
484+
session: _session
485+
})
486+
487+
const accessMode = 'READ'
488+
const timeout = 0.2
489+
490+
session._beginTransaction(accessMode, { timeout })
491+
.subscribe()
492+
493+
expect(capture[0][1].timeout).toEqual(int(1))
494+
})
495+
496+
it('should log a warning for timeout configurations with sub milliseconds', () => {
497+
const capture = []
498+
const loggerFunction = (...args) => capture.push(args)
499+
const log = new logger.Logger('debug', loggerFunction)
500+
501+
const _session = {
502+
_beginTransaction: async (...args) => {
503+
return {}
504+
}
505+
}
506+
507+
const session = new RxSession({
508+
session: _session,
509+
log
510+
})
511+
512+
const accessMode = 'READ'
513+
const timeout = 0.2
514+
515+
session._beginTransaction(accessMode, { timeout })
516+
.subscribe()
517+
518+
expect(capture[0]).toEqual([
519+
'info',
520+
`Transaction timeout expected to be an integer, got: ${timeout}. The value will be round up.`
521+
])
522+
})
523+
524+
it('should not log a warning for timeout configurations without sub milliseconds', () => {
525+
const capture = []
526+
const loggerFunction = (...args) => capture.push(args)
527+
const log = new logger.Logger('debug', loggerFunction)
528+
529+
const _session = {
530+
_beginTransaction: async (...args) => {
531+
return {}
532+
}
533+
}
534+
535+
const session = new RxSession({
536+
session: _session,
537+
log
538+
})
539+
540+
const accessMode = 'READ'
541+
const timeout = 1
542+
543+
session._beginTransaction(accessMode, { timeout })
544+
.subscribe()
545+
546+
expect(capture.length).toEqual(0)
547+
})
548+
})
549+
445550
function newSession (lastBookmarks = bookmarks.Bookmarks.empty()) {
446551
const connectionProvider = new ConnectionProvider()
447552
connectionProvider.acquireConnection = () => Promise.resolve(null)

0 commit comments

Comments
 (0)