Skip to content

Commit fa50a4f

Browse files
committed
Create bolt protocol 4.2
It creates all the infrastructure for handle the 4.2 handshake and test if all the existing behaviours on the 4.1 still working on the new version. It also removes the version 2 from the handshake and remove older versions test resources which are not used anymore.
1 parent fea6bae commit fa50a4f

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

46 files changed

+454
-141
lines changed

src/internal/bolt-protocol-v4x2.js

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
/**
2+
* Copyright (c) 2002-2020 "Neo4j,"
3+
* Neo4j Sweden AB [http://neo4j.com]
4+
*
5+
* This file is part of Neo4j.
6+
*
7+
* Licensed under the Apache License, Version 2.0 (the "License");
8+
* you may not use this file except in compliance with the License.
9+
* You may obtain a copy of the License at
10+
*
11+
* http://www.apache.org/licenses/LICENSE-2.0
12+
*
13+
* Unless required by applicable law or agreed to in writing, software
14+
* distributed under the License is distributed on an "AS IS" BASIS,
15+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16+
* See the License for the specific language governing permissions and
17+
* limitations under the License.
18+
*/
19+
import BoltProtocolV41 from './bolt-protocol-v4x1'
20+
import { BOLT_PROTOCOL_V4_2 } from './constants'
21+
22+
export default class BoltProtocol extends BoltProtocolV41 {
23+
/**
24+
* @constructor
25+
* @param {Connection} connection the connection.
26+
* @param {Chunker} chunker the chunker.
27+
* @param {boolean} disableLosslessIntegers if this connection should convert all received integers to native JS numbers.
28+
* @param {Object} serversideRouting
29+
*/
30+
constructor (connection, chunker, disableLosslessIntegers, serversideRouting) {
31+
super(connection, chunker, disableLosslessIntegers, serversideRouting)
32+
}
33+
34+
get version () {
35+
return BOLT_PROTOCOL_V4_2
36+
}
37+
}

src/internal/constants.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ const BOLT_PROTOCOL_V2 = 2
2525
const BOLT_PROTOCOL_V3 = 3
2626
const BOLT_PROTOCOL_V4_0 = 4.0
2727
const BOLT_PROTOCOL_V4_1 = 4.1
28+
const BOLT_PROTOCOL_V4_2 = 4.2
2829

2930
export {
3031
ACCESS_MODE_READ,
@@ -33,5 +34,6 @@ export {
3334
BOLT_PROTOCOL_V2,
3435
BOLT_PROTOCOL_V3,
3536
BOLT_PROTOCOL_V4_0,
36-
BOLT_PROTOCOL_V4_1
37+
BOLT_PROTOCOL_V4_1,
38+
BOLT_PROTOCOL_V4_2
3739
}

src/internal/protocol-handshaker.js

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ import BoltProtocolV2 from './bolt-protocol-v2'
2424
import BoltProtocolV3 from './bolt-protocol-v3'
2525
import BoltProtocolV4x0 from './bolt-protocol-v4x0'
2626
import BoltProtocolV4x1 from './bolt-protocol-v4x1'
27+
import BoltProtocolV4x2 from './bolt-protocol-v4x2'
2728

2829
const BOLT_MAGIC_PREAMBLE = 0x6060b017
2930

@@ -124,6 +125,13 @@ export default class ProtocolHandshaker {
124125
this._disableLosslessIntegers,
125126
this._serversideRouting
126127
)
128+
case 4.2:
129+
return new BoltProtocolV4x2(
130+
this._connection,
131+
this._chunker,
132+
this._disableLosslessIntegers,
133+
this._serversideRouting
134+
)
127135
default:
128136
throw newError('Unknown Bolt protocol version: ' + version)
129137
}
@@ -141,10 +149,10 @@ function newHandshakeBuffer () {
141149
handshakeBuffer.writeInt32(BOLT_MAGIC_PREAMBLE)
142150

143151
// proposed versions
152+
handshakeBuffer.writeInt32((2 << 8) | 4)
144153
handshakeBuffer.writeInt32((1 << 8) | 4)
145154
handshakeBuffer.writeInt32(4)
146155
handshakeBuffer.writeInt32(3)
147-
handshakeBuffer.writeInt32(2)
148156

149157
// reset the reader position
150158
handshakeBuffer.reset()

test/internal/connection-channel.test.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -123,12 +123,12 @@ describe('#integration ChannelConnection', () => {
123123
connection._negotiateProtocol()
124124

125125
const boltMagicPreamble = '60 60 b0 17'
126+
const protocolVersion4x2 = '00 00 02 04'
126127
const protocolVersion4x1 = '00 00 01 04'
127128
const protocolVersion4x0 = '00 00 00 04'
128129
const protocolVersion3 = '00 00 00 03'
129-
const protocolVersion2 = '00 00 00 02'
130130
expect(channel.toHex()).toBe(
131-
`${boltMagicPreamble} ${protocolVersion4x1} ${protocolVersion4x0} ${protocolVersion3} ${protocolVersion2}`
131+
`${boltMagicPreamble} ${protocolVersion4x2} ${protocolVersion4x1} ${protocolVersion4x0} ${protocolVersion3}`
132132
)
133133
})
134134

test/internal/node/direct.driver.boltkit.test.js

Lines changed: 26 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -58,11 +58,11 @@ describe('#stub-direct direct driver with stub server', () => {
5858
await server.exit()
5959
}
6060

61-
it('v2', () => verifyShouldRunQuery('v2'))
62-
6361
it('v3', () => verifyShouldRunQuery('v3'))
6462

6563
it('v4', () => verifyShouldRunQuery('v4'))
64+
65+
it('v4.2', () => verifyShouldRunQuery('v4.2'))
6666
})
6767

6868
it('should use custom user agent', async () => {
@@ -103,6 +103,8 @@ describe('#stub-direct direct driver with stub server', () => {
103103
}
104104

105105
it('v4.1', () => verify('v4.1'))
106+
107+
it('v4.2', () => verify('v4.2'))
106108
})
107109

108110
describe('should send and receive bookmark for read transaction', () => {
@@ -136,11 +138,11 @@ describe('#stub-direct direct driver with stub server', () => {
136138
await server.exit()
137139
}
138140

139-
it('v2', () => verifyBookmarkForReadTxc('v2'))
140-
141141
it('v3', () => verifyBookmarkForReadTxc('v3'))
142142

143143
it('v4', () => verifyBookmarkForReadTxc('v4'))
144+
145+
it('v4.2', () => verifyBookmarkForReadTxc('v4.2'))
144146
})
145147

146148
describe('should send and receive bookmark for write transaction', () => {
@@ -172,11 +174,11 @@ describe('#stub-direct direct driver with stub server', () => {
172174
await server.exit()
173175
}
174176

175-
it('v2', () => verifyBookmarkForWriteTxc('v2'))
176-
177177
it('v3', () => verifyBookmarkForWriteTxc('v3'))
178178

179179
it('v4', () => verifyBookmarkForWriteTxc('v4'))
180+
181+
it('v4.2', () => verifyBookmarkForWriteTxc('v4.2'))
180182
})
181183

182184
describe('should send and receive bookmark between write and read transactions', () => {
@@ -217,11 +219,11 @@ describe('#stub-direct direct driver with stub server', () => {
217219
await server.exit()
218220
}
219221

220-
it('v2', () => verifyBookmark('v2'))
221-
222222
it('v3', () => verifyBookmark('v3'))
223223

224224
it('v4', () => verifyBookmark('v4'))
225+
226+
it('v4.2', () => verifyBookmark('v4.2'))
225227
})
226228

227229
describe('should throw service unavailable when server dies', () => {
@@ -250,11 +252,11 @@ describe('#stub-direct direct driver with stub server', () => {
250252
await server.exit()
251253
}
252254

253-
it('v2', () => verifyServiceUnavailable('v2'))
254-
255255
it('v3', () => verifyServiceUnavailable('v3'))
256256

257257
it('v4', () => verifyServiceUnavailable('v4'))
258+
259+
it('v4.2', () => verifyServiceUnavailable('v4.2'))
258260
})
259261

260262
describe('should close connection when RESET fails', () => {
@@ -283,11 +285,11 @@ describe('#stub-direct direct driver with stub server', () => {
283285
await server.exit()
284286
}
285287

286-
it('v2', () => verifyCloseConnection('v2'))
287-
288288
it('v3', () => verifyCloseConnection('v3'))
289289

290290
it('v4', () => verifyCloseConnection('v4'))
291+
292+
it('v4.2', () => verifyCloseConnection('v4.2'))
291293
})
292294

293295
describe('should send RESET on error', () => {
@@ -316,11 +318,11 @@ describe('#stub-direct direct driver with stub server', () => {
316318
await server.exit()
317319
}
318320

319-
it('v2', () => verifyReset('v2'))
320-
321321
it('v3', () => verifyReset('v3'))
322322

323323
it('v4', () => verifyReset('v4'))
324+
325+
it('v4.2', () => verifyReset('v4.2'))
324326
})
325327

326328
describe('should include database connection id in logs', () => {
@@ -367,6 +369,8 @@ describe('#stub-direct direct driver with stub server', () => {
367369
it('v3', () => verifyConnectionId('v3'))
368370

369371
it('v4', () => verifyConnectionId('v4'))
372+
373+
it('v4.2', () => verifyConnectionId('v4.2'))
370374
})
371375

372376
describe('should close connection if it dies sitting idle in connection pool', () => {
@@ -411,11 +415,11 @@ describe('#stub-direct direct driver with stub server', () => {
411415
await server.exit()
412416
}
413417

414-
it('v2', () => verifyConnectionCleanup('v2'))
415-
416418
it('v3', () => verifyConnectionCleanup('v3'))
417419

418420
it('v4', () => verifyConnectionCleanup('v4'))
421+
422+
it('v4.2', () => verifyConnectionCleanup('v4.2'))
419423
})
420424

421425
describe('should fail if commit fails due to broken connection', () => {
@@ -446,8 +450,6 @@ describe('#stub-direct direct driver with stub server', () => {
446450
await server.exit()
447451
}
448452

449-
it('v2', () => verifyFailureOnCommit('v2'))
450-
451453
it('v3', () => verifyFailureOnCommit('v3'))
452454
})
453455

@@ -470,9 +472,9 @@ describe('#stub-direct direct driver with stub server', () => {
470472
await server.exit()
471473
}
472474

473-
it('v2', () => verifySupportsMultiDb('v2', false))
474475
it('v3', () => verifySupportsMultiDb('v3', false))
475476
it('v4', () => verifySupportsMultiDb('v4', true))
477+
it('v4.2', () => verifySupportsMultiDb('v4.2', true))
476478
it('on error', async () => {
477479
const driver = boltStub.newDriver('bolt://127.0.0.1:9001')
478480

@@ -507,9 +509,9 @@ describe('#stub-direct direct driver with stub server', () => {
507509
await server.exit()
508510
}
509511

510-
it('v2', () => verifySupportsTransactionConfig('v2', false))
511512
it('v3', () => verifySupportsTransactionConfig('v3', true))
512513
it('v4', () => verifySupportsTransactionConfig('v4', true))
514+
it('v4.2', () => verifySupportsTransactionConfig('v4.2', true))
513515
it('on error', async () => {
514516
const driver = boltStub.newDriver('bolt://127.0.0.1:9001')
515517

@@ -568,6 +570,7 @@ describe('#stub-direct direct driver with stub server', () => {
568570
}
569571

570572
it('v4', () => verifyFailureOnCommit('v4'))
573+
it('v4.2', () => verifyFailureOnCommit('v4.2'))
571574
})
572575

573576
describe('should stream in many batches', () => {
@@ -613,6 +616,7 @@ describe('#stub-direct direct driver with stub server', () => {
613616
}
614617

615618
it('v4', () => verifyFailureOnCommit('v4'))
619+
it('v4.2', () => verifyFailureOnCommit('v4.2'))
616620
})
617621

618622
describe('should ignore fetchSize setting', () => {
@@ -658,7 +662,6 @@ describe('#stub-direct direct driver with stub server', () => {
658662
}
659663

660664
it('v3', () => verifyFailureOnCommit('v3'))
661-
it('v2', () => verifyFailureOnCommit('v2'))
662665
})
663666

664667
describe('should cancel stream with result summary method', () => {
@@ -704,6 +707,7 @@ describe('#stub-direct direct driver with stub server', () => {
704707
}
705708

706709
it('v4', () => verifyFailureOnCommit('v4'))
710+
it('v4.2', () => verifyFailureOnCommit('v4.2'))
707711
})
708712

709713
describe('should cancel stream with tx commit', () => {
@@ -752,6 +756,7 @@ describe('#stub-direct direct driver with stub server', () => {
752756
}
753757

754758
it('v4', () => verifyFailureOnCommit('v4'))
759+
it('v4.2', () => verifyFailureOnCommit('v4.2'))
755760
})
756761

757762
function connectionPool (driver, key) {

test/internal/node/routing.driver.boltkit.test.js

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2392,12 +2392,13 @@ describe('#stub-routing routing driver with stub server', () => {
23922392
await server.exit()
23932393
}
23942394

2395-
it('v2', () => verifySupportsMultiDb('v2', false))
23962395
it('v3', () => verifySupportsMultiDb('v3', false))
23972396
it('v4', () => verifySupportsMultiDb('v4', true))
2398-
it('v2 with resolver', () => verifySupportsMultiDbWithResolver('v2', false))
2397+
it('v4.2', () => verifySupportsMultiDb('v4.2', true))
23992398
it('v3 with resolver', () => verifySupportsMultiDbWithResolver('v3', false))
24002399
it('v4 with resolver', () => verifySupportsMultiDbWithResolver('v4', true))
2400+
it('v4.2 with resolver', () =>
2401+
verifySupportsMultiDbWithResolver('v4.2', true))
24012402
it('on error', async () => {
24022403
const driver = boltStub.newDriver('neo4j://127.0.0.1:9001')
24032404

@@ -2434,6 +2435,7 @@ describe('#stub-routing routing driver with stub server', () => {
24342435
}
24352436

24362437
it('v4.1', () => verify('v4.1'))
2438+
it('v4.2', () => verify('v4.2'))
24372439
})
24382440

24392441
describe('should send routing context with hello to enable server routing', () => {
@@ -2459,6 +2461,7 @@ describe('#stub-routing routing driver with stub server', () => {
24592461
}
24602462

24612463
it('v4.1', () => verify('v4.1'))
2464+
it('v4.2', () => verify('v4.2'))
24622465
})
24632466

24642467
describe('should send empty routing context with hello to enable server routing', () => {
@@ -2482,6 +2485,7 @@ describe('#stub-routing routing driver with stub server', () => {
24822485
}
24832486

24842487
it('v4.1', () => verify('v4.1'))
2488+
it('v4.2', () => verify('v4.2'))
24852489
})
24862490

24872491
describe('should report whether transaction config is supported', () => {
@@ -2534,15 +2538,15 @@ describe('#stub-routing routing driver with stub server', () => {
25342538
await server.exit()
25352539
}
25362540

2537-
it('v2', () => verifySupportsTransactionConfig('v2', false))
25382541
it('v3', () => verifySupportsTransactionConfig('v3', true))
25392542
it('v4', () => verifySupportsTransactionConfig('v4', true))
2540-
it('v2 with resolver', () =>
2541-
verifySupportsTransactionConfigWithResolver('v2', false))
2543+
it('v4.2', () => verifySupportsTransactionConfig('v4.2', true))
25422544
it('v3 with resolver', () =>
25432545
verifySupportsTransactionConfigWithResolver('v3', true))
25442546
it('v4 with resolver', () =>
25452547
verifySupportsTransactionConfigWithResolver('v4', true))
2548+
it('v4.2 with resolver', () =>
2549+
verifySupportsTransactionConfigWithResolver('v4.2', true))
25462550
it('on error', async () => {
25472551
const driver = boltStub.newDriver('neo4j://127.0.0.1:9001')
25482552

test/internal/protocol-handshaker.test.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,13 +42,13 @@ describe('#unit ProtocolHandshaker', () => {
4242
expect(writtenBuffers.length).toEqual(1)
4343

4444
const boltMagicPreamble = '60 60 b0 17'
45+
const protocolVersion4x2 = '00 00 02 04'
4546
const protocolVersion4x1 = '00 00 01 04'
4647
const protocolVersion4x0 = '00 00 00 04'
4748
const protocolVersion3 = '00 00 00 03'
48-
const protocolVersion2 = '00 00 00 02'
4949

5050
expect(writtenBuffers[0].toHex()).toEqual(
51-
`${boltMagicPreamble} ${protocolVersion4x1} ${protocolVersion4x0} ${protocolVersion3} ${protocolVersion2}`
51+
`${boltMagicPreamble} ${protocolVersion4x2} ${protocolVersion4x1} ${protocolVersion4x0} ${protocolVersion3}`
5252
)
5353
})
5454

test/resources/boltstub/v1/supports_protocol_version.script

Lines changed: 0 additions & 1 deletion
This file was deleted.

test/resources/boltstub/v2/connection_error_on_commit.script

Lines changed: 0 additions & 15 deletions
This file was deleted.

0 commit comments

Comments
 (0)