Skip to content

Commit 8e0d645

Browse files
committed
Implements bookmarks in the ROUTE message
This important in the case of a creation of a new database to make sure the database is running in all the clusters nodes returned. This change also skips a test which depends on feature which doesn't exists on the javascript driver.
1 parent 14b91ee commit 8e0d645

File tree

6 files changed

+51
-13
lines changed

6 files changed

+51
-13
lines changed

bolt-connection/src/bolt/bolt-protocol-v4x0.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,6 @@ export default class BoltProtocol extends BoltProtocolV3 {
149149
routingContext = {},
150150
databaseName = null,
151151
sessionContext = {},
152-
initialAddress = null,
153152
onError,
154153
onCompleted
155154
}) {

bolt-connection/src/bolt/bolt-protocol-v4x3.js

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ import { RouteObserver } from './stream-observers'
2323
import { internal } from 'neo4j-driver-core'
2424

2525
const {
26+
bookmark: { Bookmark },
2627
constants: { BOLT_PROTOCOL_V4_3 }
2728
} = internal
2829

@@ -38,14 +39,15 @@ export default class BoltProtocol extends BoltProtocolV42 {
3839
* @param {object} param.routingContext The routing context used to define the routing table.
3940
* Multi-datacenter deployments is one of its use cases
4041
* @param {string} param.databaseName The database name
42+
* @param {Bookmark} params.sessionContext.bookmark The bookmark used for request the routing table
4143
* @param {function(err: Error)} param.onError
4244
* @param {function(RawRoutingTable)} param.onCompleted
4345
* @returns {RouteObserver} the route observer
4446
*/
4547
requestRoutingInformation ({
4648
routingContext = {},
4749
databaseName = null,
48-
initialAddress = null,
50+
sessionContext = {},
4951
onError,
5052
onCompleted
5153
}) {
@@ -54,9 +56,9 @@ export default class BoltProtocol extends BoltProtocolV42 {
5456
onError,
5557
onCompleted
5658
})
57-
59+
const bookmark = sessionContext.bookmark || Bookmark.empty()
5860
this.write(
59-
RequestMessage.route(routingContext, databaseName),
61+
RequestMessage.route(routingContext, bookmark.values(), databaseName),
6062
observer,
6163
true
6264
)

bolt-connection/src/bolt/request-message.js

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -223,14 +223,18 @@ export default class RequestMessage {
223223
* Generate the ROUTE message, this message is used to fetch the routing table from the server
224224
*
225225
* @param {object} routingContext The routing context used to define the routing table. Multi-datacenter deployments is one of its use cases
226+
* @param {string[]} bookmarks The list of the bookmark should be used
226227
* @param {string} databaseName The name of the database to get the routing table for.
227228
* @return {RequestMessage} the ROUTE message.
228229
*/
229-
static route (routingContext = {}, databaseName = null) {
230+
static route (routingContext = {}, bookmarks = [], databaseName = null) {
230231
return new RequestMessage(
231232
ROUTE,
232-
[routingContext, databaseName],
233-
() => `ROUTE ${json.stringify(routingContext)} ${databaseName}`
233+
[routingContext, bookmarks, databaseName],
234+
() =>
235+
`ROUTE ${json.stringify(routingContext)} ${json.stringify(
236+
bookmarks
237+
)} ${databaseName}`
234238
)
235239
}
236240
}

bolt-connection/test/bolt/bolt-protocol-v4x3.test.js

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,31 @@ describe('#unit BoltProtocolV4x3', () => {
4949

5050
protocol.verifyMessageCount(1)
5151
expect(protocol.messages[0]).toBeMessage(
52-
RequestMessage.route(routingContext, databaseName)
52+
RequestMessage.route(routingContext, [], databaseName)
53+
)
54+
expect(protocol.observers).toEqual([observer])
55+
expect(observer).toEqual(jasmine.any(RouteObserver))
56+
expect(protocol.flushes).toEqual([true])
57+
})
58+
59+
it('should request routing information sending bookmarks', () => {
60+
const recorder = new utils.MessageRecordingConnection()
61+
const protocol = new BoltProtocolV4x3(recorder, null, false)
62+
utils.spyProtocolWrite(protocol)
63+
const routingContext = { someContextParam: 'value' }
64+
const listOfBookmarks = ['a', 'b', 'c']
65+
const bookmark = new Bookmark(listOfBookmarks)
66+
const databaseName = 'name'
67+
68+
const observer = protocol.requestRoutingInformation({
69+
routingContext,
70+
databaseName,
71+
sessionContext: { bookmark }
72+
})
73+
74+
protocol.verifyMessageCount(1)
75+
expect(protocol.messages[0]).toBeMessage(
76+
RequestMessage.route(routingContext, listOfBookmarks, databaseName)
5377
)
5478
expect(protocol.observers).toEqual([observer])
5579
expect(observer).toEqual(jasmine.any(RouteObserver))

bolt-connection/test/bolt/request-message.test.js

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -242,23 +242,28 @@ describe('#unit RequestMessage', () => {
242242
describe('BoltV4.3', () => {
243243
it('should create ROUTE message', () => {
244244
const requestContext = { someValue: '1234' }
245+
const bookmarks = ['a', 'b']
245246
const database = 'user_db'
246247

247-
const message = RequestMessage.route(requestContext, database)
248+
const message = RequestMessage.route(requestContext, bookmarks, database)
248249

249250
expect(message.signature).toEqual(0x66)
250-
expect(message.fields).toEqual([requestContext, database])
251+
expect(message.fields).toEqual([requestContext, bookmarks, database])
251252
expect(message.toString()).toEqual(
252-
`ROUTE ${json.stringify(requestContext)} ${database}`
253+
`ROUTE ${json.stringify(requestContext)} ${json.stringify(
254+
bookmarks
255+
)} ${database}`
253256
)
254257
})
255258

256259
it('should create ROUTE message with default values', () => {
257260
const message = RequestMessage.route()
258261

259262
expect(message.signature).toEqual(0x66)
260-
expect(message.fields).toEqual([{}, null])
261-
expect(message.toString()).toEqual(`ROUTE ${json.stringify({})} ${null}`)
263+
expect(message.fields).toEqual([{}, [], null])
264+
expect(message.toString()).toEqual(
265+
`ROUTE ${json.stringify({})} ${json.stringify([])} ${null}`
266+
)
262267
})
263268
})
264269
})

testkit-backend/src/skipped-tests.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,10 @@ const skippedTests = [
2323
'Routing tests are disabled until the fix on the test scenario be merged',
2424
or(ifStartsWith('stub.routing'), ifStartsWith('stub.retry.TestRetry'))
2525
),
26+
skip(
27+
'The driver no support domain_name_resolver',
28+
ifEndsWith('test_should_successfully_acquire_rt_when_router_ip_changes')
29+
),
2630
skip(
2731
'Driver is failing trying to update the routing table using the original routing server',
2832
ifEndsWith(

0 commit comments

Comments
 (0)