Skip to content

Commit 9d64b63

Browse files
committed
Guard tests that use bookmarks with server version check
1 parent a84ddcf commit 9d64b63

File tree

11 files changed

+542
-449
lines changed

11 files changed

+542
-449
lines changed

lib/v1/driver.js

Lines changed: 63 additions & 89 deletions
Original file line numberDiff line numberDiff line change
@@ -1,68 +1,54 @@
1-
"use strict";
1+
'use strict';
22

33
Object.defineProperty(exports, "__esModule", {
44
value: true
55
});
66
exports.WRITE = exports.READ = exports.Driver = undefined;
77

8-
var _getPrototypeOf = require("babel-runtime/core-js/object/get-prototype-of");
8+
var _getPrototypeOf = require('babel-runtime/core-js/object/get-prototype-of');
99

1010
var _getPrototypeOf2 = _interopRequireDefault(_getPrototypeOf);
1111

12-
var _possibleConstructorReturn2 = require("babel-runtime/helpers/possibleConstructorReturn");
12+
var _possibleConstructorReturn2 = require('babel-runtime/helpers/possibleConstructorReturn');
1313

1414
var _possibleConstructorReturn3 = _interopRequireDefault(_possibleConstructorReturn2);
1515

16-
var _get2 = require("babel-runtime/helpers/get");
16+
var _get2 = require('babel-runtime/helpers/get');
1717

1818
var _get3 = _interopRequireDefault(_get2);
1919

20-
var _inherits2 = require("babel-runtime/helpers/inherits");
20+
var _inherits2 = require('babel-runtime/helpers/inherits');
2121

2222
var _inherits3 = _interopRequireDefault(_inherits2);
2323

24-
var _promise = require("babel-runtime/core-js/promise");
25-
26-
var _promise2 = _interopRequireDefault(_promise);
27-
28-
var _classCallCheck2 = require("babel-runtime/helpers/classCallCheck");
24+
var _classCallCheck2 = require('babel-runtime/helpers/classCallCheck');
2925

3026
var _classCallCheck3 = _interopRequireDefault(_classCallCheck2);
3127

32-
var _createClass2 = require("babel-runtime/helpers/createClass");
28+
var _createClass2 = require('babel-runtime/helpers/createClass');
3329

3430
var _createClass3 = _interopRequireDefault(_createClass2);
3531

36-
var _session = require("./session");
32+
var _session = require('./session');
3733

3834
var _session2 = _interopRequireDefault(_session);
3935

40-
var _pool = require("./internal/pool");
36+
var _pool = require('./internal/pool');
4137

4238
var _pool2 = _interopRequireDefault(_pool);
4339

44-
var _connector = require("./internal/connector");
40+
var _connector = require('./internal/connector');
4541

46-
var _streamObserver = require("./internal/stream-observer");
42+
var _streamObserver = require('./internal/stream-observer');
4743

4844
var _streamObserver2 = _interopRequireDefault(_streamObserver);
4945

50-
var _error = require("./error");
46+
var _error = require('./error');
47+
48+
var _connectionProviders = require('./internal/connection-providers');
5149

5250
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
5351

54-
var READ = 'READ',
55-
WRITE = 'WRITE';
56-
/**
57-
* A driver maintains one or more {@link Session sessions} with a remote
58-
* Neo4j instance. Through the {@link Session sessions} you can send statements
59-
* and retrieve results from the database.
60-
*
61-
* Drivers are reasonably expensive to create - you should strive to keep one
62-
* driver instance around per Neo4j Instance you connect to.
63-
*
64-
* @access public
65-
*/
6652
/**
6753
* Copyright (c) 2002-2017 "Neo Technology,","
6854
* Network Engine for Objects in Lund AB [http://neotechnology.com]
@@ -82,6 +68,19 @@ var READ = 'READ',
8268
* limitations under the License.
8369
*/
8470

71+
var READ = 'READ',
72+
WRITE = 'WRITE';
73+
/**
74+
* A driver maintains one or more {@link Session sessions} with a remote
75+
* Neo4j instance. Through the {@link Session sessions} you can send statements
76+
* and retrieve results from the database.
77+
*
78+
* Drivers are reasonably expensive to create - you should strive to keep one
79+
* driver instance around per Neo4j Instance you connect to.
80+
*
81+
* @access public
82+
*/
83+
8584
var Driver = function () {
8685
/**
8786
* You should not be calling this directly, instead use {@link driver}.
@@ -104,6 +103,7 @@ var Driver = function () {
104103
this._token = token;
105104
this._config = config;
106105
this._pool = new _pool2.default(this._createConnection.bind(this), this._destroyConnection.bind(this), Driver._validateConnection.bind(this), config.connectionPoolSize);
106+
this._connectionProvider = this._createConnectionProvider(url, this._pool, this._driverOnErrorCallback.bind(this));
107107
}
108108

109109
/**
@@ -114,7 +114,7 @@ var Driver = function () {
114114

115115

116116
(0, _createClass3.default)(Driver, [{
117-
key: "_createConnection",
117+
key: '_createConnection',
118118
value: function _createConnection(url, release) {
119119
var sessionId = this._sessionIdGenerator++;
120120
var conn = (0, _connector.connect)(url, this._config);
@@ -136,7 +136,7 @@ var Driver = function () {
136136
**/
137137

138138
}, {
139-
key: "_destroyConnection",
139+
key: '_destroyConnection',
140140

141141

142142
/**
@@ -160,69 +160,43 @@ var Driver = function () {
160160
* it is returned to the pool, the session will be reset to a clean state and
161161
* made available for others to use.
162162
*
163-
* @param {String} mode of session - optional
163+
* @param {string} [mode=WRITE] the access mode of this session, allowed values are {@link READ} and {@link WRITE}.
164+
* @param {string} [bookmark=null] the initial reference to some previous transaction. Value is optional and
165+
* absence indicates that that the bookmark does not exist or is unknown.
164166
* @return {Session} new session.
165167
*/
166168

167169
}, {
168-
key: "session",
169-
value: function session(mode) {
170-
var _this = this;
171-
170+
key: 'session',
171+
value: function session(mode, bookmark) {
172172
var sessionMode = Driver._validateSessionMode(mode);
173-
var connectionPromise = this._acquireConnection(sessionMode);
174-
connectionPromise.catch(function (err) {
175-
if (_this.onError && err.code === _error.SERVICE_UNAVAILABLE) {
176-
_this.onError(err);
177-
} else {
178-
//we don't need to tell the driver about this error
179-
}
180-
});
181-
return this._createSession(connectionPromise, this._releaseConnection(connectionPromise));
182-
}
183-
184-
/**
185-
* The returned function gets called on Session#close(), and is where we return the pooled 'connection' instance.
186-
* We don't pool Session instances, to avoid users using the Session after they've called close.
187-
* The `Session` object is just a thin wrapper around Connection anyway, so it makes little difference.
188-
* @param {Promise} connectionPromise - promise resolved with the connection.
189-
* @return {function(callback: function)} - function that releases the connection and then executes an optional callback.
190-
* @protected
191-
*/
192-
193-
}, {
194-
key: "_releaseConnection",
195-
value: function _releaseConnection(connectionPromise) {
196-
return function (userDefinedCallback) {
197-
connectionPromise.then(function (conn) {
198-
// Queue up a 'reset', to ensure the next user gets a clean session to work with.
199-
conn.reset();
200-
conn.sync();
201-
202-
// Return connection to the pool
203-
conn._release();
204-
}).catch(function (ignoredError) {});
205-
206-
if (userDefinedCallback) {
207-
userDefinedCallback();
208-
}
209-
};
173+
return this._createSession(sessionMode, this._connectionProvider, bookmark, this._config);
210174
}
211175
}, {
212-
key: "_acquireConnection",
176+
key: '_createConnectionProvider',
213177

214178

215179
//Extension point
216-
value: function _acquireConnection(mode) {
217-
return _promise2.default.resolve(this._pool.acquire(this._url));
180+
value: function _createConnectionProvider(address, connectionPool, driverOnErrorCallback) {
181+
return new _connectionProviders.DirectConnectionProvider(address, connectionPool, driverOnErrorCallback);
218182
}
219183

220184
//Extension point
221185

222186
}, {
223-
key: "_createSession",
224-
value: function _createSession(connectionPromise, cb) {
225-
return new _session2.default(connectionPromise, cb);
187+
key: '_createSession',
188+
value: function _createSession(mode, connectionProvider, bookmark, config) {
189+
return new _session2.default(mode, connectionProvider, bookmark, config);
190+
}
191+
}, {
192+
key: '_driverOnErrorCallback',
193+
value: function _driverOnErrorCallback(error) {
194+
var userDefinedOnErrorCallback = this.onError;
195+
if (userDefinedOnErrorCallback && error.code === _error.SERVICE_UNAVAILABLE) {
196+
userDefinedOnErrorCallback(error);
197+
} else {
198+
// we don't need to tell the driver about this error
199+
}
226200
}
227201

228202
/**
@@ -232,7 +206,7 @@ var Driver = function () {
232206
*/
233207

234208
}, {
235-
key: "close",
209+
key: 'close',
236210
value: function close() {
237211
for (var sessionId in this._openSessions) {
238212
if (this._openSessions.hasOwnProperty(sessionId)) {
@@ -242,12 +216,12 @@ var Driver = function () {
242216
}
243217
}
244218
}], [{
245-
key: "_validateConnection",
219+
key: '_validateConnection',
246220
value: function _validateConnection(conn) {
247221
return conn.isOpen();
248222
}
249223
}, {
250-
key: "_validateSessionMode",
224+
key: '_validateSessionMode',
251225
value: function _validateSessionMode(rawMode) {
252226
var mode = rawMode || WRITE;
253227
if (mode !== READ && mode !== WRITE) {
@@ -268,27 +242,27 @@ var _ConnectionStreamObserver = function (_StreamObserver) {
268242
function _ConnectionStreamObserver(driver, conn) {
269243
(0, _classCallCheck3.default)(this, _ConnectionStreamObserver);
270244

271-
var _this2 = (0, _possibleConstructorReturn3.default)(this, (_ConnectionStreamObserver.__proto__ || (0, _getPrototypeOf2.default)(_ConnectionStreamObserver)).call(this));
245+
var _this = (0, _possibleConstructorReturn3.default)(this, (_ConnectionStreamObserver.__proto__ || (0, _getPrototypeOf2.default)(_ConnectionStreamObserver)).call(this));
272246

273-
_this2._driver = driver;
274-
_this2._conn = conn;
275-
_this2._hasFailed = false;
276-
return _this2;
247+
_this._driver = driver;
248+
_this._conn = conn;
249+
_this._hasFailed = false;
250+
return _this;
277251
}
278252

279253
(0, _createClass3.default)(_ConnectionStreamObserver, [{
280-
key: "onError",
254+
key: 'onError',
281255
value: function onError(error) {
282256
if (!this._hasFailed) {
283-
(0, _get3.default)(_ConnectionStreamObserver.prototype.__proto__ || (0, _getPrototypeOf2.default)(_ConnectionStreamObserver.prototype), "onError", this).call(this, error);
257+
(0, _get3.default)(_ConnectionStreamObserver.prototype.__proto__ || (0, _getPrototypeOf2.default)(_ConnectionStreamObserver.prototype), 'onError', this).call(this, error);
284258
if (this._driver.onError) {
285259
this._driver.onError(error);
286260
}
287261
this._hasFailed = true;
288262
}
289263
}
290264
}, {
291-
key: "onCompleted",
265+
key: 'onCompleted',
292266
value: function onCompleted(message) {
293267
if (this._driver.onCompleted) {
294268
this._driver.onCompleted(message);

lib/v1/graph-types.js

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { de
4848
var Node = function () {
4949
/**
5050
* @constructor
51-
* @param {string} identity - Unique identity
51+
* @param {Integer} identity - Unique identity
5252
* @param {Array} labels - Array for all labels
5353
* @param {Object} properties - Map with node properties
5454
*/
@@ -91,9 +91,9 @@ var Node = function () {
9191
var Relationship = function () {
9292
/**
9393
* @constructor
94-
* @param {string} identity - Unique identity
95-
* @param {string} start - Identity of start Node
96-
* @param {string} end - Identity of end Node
94+
* @param {Integer} identity - Unique identity
95+
* @param {Integer} start - Identity of start Node
96+
* @param {Integer} end - Identity of end Node
9797
* @param {string} type - Relationship type
9898
* @param {Object} properties - Map with relationship properties
9999
*/
@@ -136,7 +136,7 @@ var Relationship = function () {
136136
var UnboundRelationship = function () {
137137
/**
138138
* @constructor
139-
* @param {string} identity - Unique identity
139+
* @param {Integer} identity - Unique identity
140140
* @param {string} type - Relationship type
141141
* @param {Object} properties - Map with relationship properties
142142
*/
@@ -150,8 +150,8 @@ var UnboundRelationship = function () {
150150

151151
/**
152152
* Bind relationship
153-
* @param {string} start - Indentity of start node
154-
* @param {string} end - Indentity of end node
153+
* @param {Integer} start - Identity of start node
154+
* @param {Integer} end - Identity of end node
155155
* @return {Relationship} - Created relationship
156156
*/
157157

@@ -189,9 +189,9 @@ var UnboundRelationship = function () {
189189
var PathSegment =
190190
/**
191191
* @constructor
192-
* @param {string} start - Identity of start Node
193-
* @param {Relationship} rel - Relationship segment
194-
* @param {string} end - Identity of end Node
192+
* @param {Node} start - start node
193+
* @param {Relationship} rel - relationship that connects start and end node
194+
* @param {Node} end - end node
195195
*/
196196
function PathSegment(start, rel, end) {
197197
(0, _classCallCheck3.default)(this, PathSegment);

lib/v1/index.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,16 @@ var USER_AGENT = "neo4j-javascript/" + _version2.default;
131131
* // port, and this is then used to verify the host certificate does not change.
132132
* // This setting has no effect unless TRUST_ON_FIRST_USE is enabled.
133133
* knownHosts:"~/.neo4j/known_hosts",
134+
*
135+
* // The max number of connections that are allowed idle in the pool at any time.
136+
* // Connection will be destroyed if this threshold is exceeded.
137+
* connectionPoolSize: 50,
138+
*
139+
* // Specify the maximum time in milliseconds transactions are allowed to retry via
140+
* // {@link Session#readTransaction()} and {@link Session#writeTransaction()} functions. These functions
141+
* // will retry the given unit of work on `ServiceUnavailable`, `SessionExpired` and transient errors with
142+
* // exponential backoff using initial delay of 1 second. Default value is 30000 which is 30 seconds.
143+
* maxTransactionRetryTime: 30000,
134144
* }
135145
*
136146
* @param {string} url The URL for the Neo4j database, for instance "bolt://localhost"

0 commit comments

Comments
 (0)