Skip to content

Commit ccc86fe

Browse files
committed
Address review comments:
* improve naming of functions and variables in `ProtocolHandshaker` * preserve statement for commit and rollback results for backwards compatibility
1 parent 00eb396 commit ccc86fe

File tree

4 files changed

+13
-13
lines changed

4 files changed

+13
-13
lines changed

src/v1/internal/connector.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -179,7 +179,7 @@ class Connection {
179179
_initializeProtocol(buffer, protocolHandshaker) {
180180
try {
181181
// re-assign the protocol because version might be lower than we initially assumed
182-
this._protocol = protocolHandshaker.readHandshakeResponse(buffer);
182+
this._protocol = protocolHandshaker.createNegotiatedProtocol(buffer);
183183

184184
// Ok, protocol running. Simply forward all messages to the dechunker
185185
this._ch.onmessage = buf => this._dechunker.write(buf);

src/v1/internal/protocol-handshaker.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -61,17 +61,17 @@ export default class ProtocolHandshaker {
6161
}
6262

6363
/**
64-
* Read and interpret the Bolt handshake response from the given buffer.
64+
* Read the given handshake response and create the negotiated bolt protocol.
6565
* @param {BaseBuffer} buffer byte buffer containing the handshake response.
6666
* @return {BoltProtocol} bolt protocol corresponding to the version suggested by the database.
6767
* @throws {Neo4jError} when bolt protocol can't be instantiated.
6868
*/
69-
readHandshakeResponse(buffer) {
70-
const proposedVersion = buffer.readInt32();
69+
createNegotiatedProtocol(buffer) {
70+
const negotiatedVersion = buffer.readInt32();
7171
if (this._log.isDebugEnabled()) {
72-
this._log.debug(`${this._connection} negotiated protocol version ${proposedVersion}`);
72+
this._log.debug(`${this._connection} negotiated protocol version ${negotiatedVersion}`);
7373
}
74-
return this._createProtocolWithVersion(proposedVersion);
74+
return this._createProtocolWithVersion(negotiatedVersion);
7575
}
7676

7777
/**

src/v1/transaction.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -241,7 +241,7 @@ function finishTransaction(commit, connectionHolder, observer) {
241241

242242
// for commit & rollback we need result that uses real connection holder and notifies it when
243243
// connection is not needed and can be safely released to the pool
244-
return new Result(observer, '', {}, emptyMetadataSupplier, connectionHolder);
244+
return new Result(observer, commit ? 'COMMIT' : 'ROLLBACK', {}, emptyMetadataSupplier, connectionHolder);
245245
}
246246

247247
/**

test/internal/protocol-handshaker.test.js

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -54,35 +54,35 @@ describe('ProtocolHandshaker', () => {
5454
expect(writtenBuffers[0].toHex()).toEqual(`${boltMagicPreamble} ${protocolVersion2} ${protocolVersion1} ${noProtocolVersion} ${noProtocolVersion} `);
5555
});
5656

57-
it('should read handshake response containing valid protocol version', () => {
57+
it('should create protocol with valid version', () => {
5858
const handshaker = new ProtocolHandshaker(null, null, null, false, Logger.noOp());
5959

6060
// buffer with Bolt V1
6161
const buffer = handshakeResponse(1);
6262

63-
const protocol = handshaker.readHandshakeResponse(buffer);
63+
const protocol = handshaker.createNegotiatedProtocol(buffer);
6464

6565
expect(protocol).toBeDefined();
6666
expect(protocol).not.toBeNull();
6767
expect(protocol instanceof BoltProtocol).toBeTruthy();
6868
});
6969

70-
it('should read handshake response containing invalid protocol version', () => {
70+
it('should fail to create protocol from invalid version', () => {
7171
const handshaker = new ProtocolHandshaker(null, null, null, false, Logger.noOp());
7272

7373
// buffer with Bolt V42 which is invalid
7474
const buffer = handshakeResponse(42);
7575

76-
expect(() => handshaker.readHandshakeResponse(buffer)).toThrow();
76+
expect(() => handshaker.createNegotiatedProtocol(buffer)).toThrow();
7777
});
7878

79-
it('should read handshake response containing HTTP as the protocol version', () => {
79+
it('should fail to create protocol from HTTP as invalid version', () => {
8080
const handshaker = new ProtocolHandshaker(null, null, null, false, Logger.noOp());
8181

8282
// buffer with HTTP magic int
8383
const buffer = handshakeResponse(1213486160);
8484

85-
expect(() => handshaker.readHandshakeResponse(buffer)).toThrow();
85+
expect(() => handshaker.createNegotiatedProtocol(buffer)).toThrow();
8686
});
8787

8888
});

0 commit comments

Comments
 (0)