Skip to content

Commit 89fcbf0

Browse files
committed
Merge branch '1.0' into 1.1
2 parents 7aa4045 + d92bfec commit 89fcbf0

File tree

6 files changed

+177
-12
lines changed

6 files changed

+177
-12
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ bower install neo4j-driver
1414
```
1515

1616
```javascript
17-
var neo4j = require('neo4j-driver').v1;
17+
var neo4j = require('neo4j-driver');
1818
```
1919

2020
## Include in web browser

src/v1/internal/ch-node.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,7 @@ const TrustStrategy = {
9191
onSuccess();
9292
}
9393
});
94+
socket.on('error', onFailure);
9495
return socket;
9596
},
9697
TRUST_ON_FIRST_USE : function( opts, onSuccess, onFailure ) {
@@ -139,13 +140,16 @@ const TrustStrategy = {
139140
}
140141
});
141142
});
143+
socket.on('error', onFailure);
142144
return socket;
143145
}
144146
};
145147

146148
function connect( opts, onSuccess, onFailure=(()=>null) ) {
147149
if( opts.encrypted === false ) {
148-
return net.connect(opts.port, opts.host, onSuccess);
150+
var conn = net.connect(opts.port, opts.host, onSuccess);
151+
conn.on('error', onFailure);
152+
return conn;
149153
} else if( TrustStrategy[opts.trust]) {
150154
return TrustStrategy[opts.trust](opts, onSuccess, onFailure);
151155
} else {

src/v1/internal/ch-websocket.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,13 @@ class WebSocketChannel {
5757
this._ws.binaryType = "arraybuffer";
5858

5959
let self = this;
60+
//All connection errors are not sent to the error handler
61+
//we must also check for dirty close calls
62+
this._ws.onclose = function(e) {
63+
if (!e.wasClean) {
64+
self._handleConnectionError();
65+
}
66+
};
6067
this._ws.onopen = function() {
6168
// Drain all pending messages
6269
let pending = self._pending;

test/v1/driver.test.js

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,4 +32,19 @@ describe('driver', function() {
3232
expect( session ).not.toBeNull();
3333
driver.close();
3434
});
35+
36+
it('should handle connection errors', function(done) {
37+
// Given
38+
var driver = neo4j.driver("bolt://localhoste", neo4j.auth.basic("neo4j", "neo4j"));
39+
40+
// Expect
41+
driver.onError = function (err) {
42+
//the error message is different whether in browser or node
43+
expect(err.message).not.toBeNull();
44+
done();
45+
};
46+
47+
// When
48+
driver.session();
49+
});
3550
});

test/v1/examples.test.js

Lines changed: 148 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -17,16 +17,25 @@
1717
* limitations under the License.
1818
*/
1919

20-
var neo4j = require("../../lib/v1");
20+
var neo4jv1 = require("../../lib/v1");
2121

2222
var _console = console;
2323

24-
describe('examples', function() {
24+
/**
25+
* The tests below are examples that get pulled into the Driver Manual using the tags inside the tests.
26+
*
27+
* DO NOT add tests to this file that are not for that exact purpose.
28+
* DO NOT modify these tests without ensuring they remain consistent with the equivalent examples in other drivers
29+
*/
30+
fdescribe('examples', function() {
2531

2632
var driver, session, out, console;
2733

2834
beforeEach(function(done) {
29-
driver = neo4j.driver("bolt://localhost", neo4j.auth.basic("neo4j", "neo4j"));
35+
var neo4j = neo4jv1;
36+
// tag::construct-driver[]
37+
driver = neo4j.driver("bolt://localhost", neo4jv1.auth.basic("neo4j", "neo4j"));
38+
//end::construct-driver[]
3039
session = driver.session();
3140

3241
// Override console.log, to assert on stdout output
@@ -40,13 +49,18 @@ describe('examples', function() {
4049
driver.close();
4150
});
4251

43-
it('should document a minimum viable snippet', function(done) {
44-
// tag::minimum-snippet[]
52+
it('should document a minimal import and usage example', function (done) {
53+
//OH my is this a hack
54+
var require = function (arg) {
55+
return {v1: neo4jv1}
56+
};
57+
// tag::minimal-example-import[]
58+
var neo4j = require('neo4j-driver').v1;
59+
// end::minimal-example-import[]
60+
// tag::minimal-example[]
4561
var driver = neo4j.driver("bolt://localhost", neo4j.auth.basic("neo4j", "neo4j"));
4662
var session = driver.session();
47-
4863
session.run( "CREATE (neo:Person {name:'Neo', age:23})" );
49-
5064
session
5165
.run( "MATCH (p:Person) WHERE p.name = 'Neo' RETURN p.age" )
5266
.then( function( result ) {
@@ -56,14 +70,30 @@ describe('examples', function() {
5670
driver.close();
5771
done();
5872
});
59-
// end::minimum-snippet[]
73+
// tag::minimal-example[]
74+
});
75+
76+
it('should be able to configure session pool size', function (done) {
77+
var neo4j = neo4jv1;
78+
// tag::configuration[]
79+
driver = neo4j.driver("bolt://localhost", neo4jv1.auth.basic("neo4j", "neo4j"), {connectionPoolSize: 10});
80+
//end::configuration[]
81+
82+
session.run( "CREATE (neo:Person {name:'Neo', age:23})" );
83+
session
84+
.run( "MATCH (p:Person) WHERE p.name = 'Neo' RETURN p.age" )
85+
.then( function( result ) {
86+
session.close();
87+
driver.close();
88+
done();
89+
});
6090
});
6191

6292
it('should document a statement', function(done) {
6393
var resultPromise =
6494
// tag::statement[]
6595
session
66-
.run( "CREATE (p:Person { name: {name} })", {"name": "The One"} )
96+
.run( "CREATE (p:Person { name: {name} })", {name: "The One"} )
6797
.then( function(result) {
6898
var theOnesCreated = result.summary.updateStatistics.nodesCreated();
6999
console.log("There were " + theOnesCreated + " the ones created.")
@@ -96,6 +126,112 @@ describe('examples', function() {
96126
})
97127
});
98128

129+
it('should be able to iterate results', function(done) {
130+
// tag::retain-result-query[]
131+
session
132+
.run( "MATCH (p:Person { name: {name} }) RETURN p.age", {name : "The One"} )
133+
.subscribe({
134+
onNext: function(record) {
135+
console.log(record);
136+
},
137+
onCompleted: function() {
138+
// Completed!
139+
session.close();
140+
},
141+
onError: function(error) {
142+
console.log(error);
143+
}
144+
});
145+
// end::result-cursor[]
146+
// Then
147+
done();
148+
});
149+
150+
it('should be able to do nested queries', function(done) {
151+
session.run("CREATE (:Person {name:'The One'})").then(function() {
152+
// tag::result-cursor[]
153+
session
154+
.run("MATCH (p:Person { name: {name} }) RETURN id(p)", {name: "The One"})
155+
.then(function (result) {
156+
var id = result.records[0].get('id(p)');
157+
session.run( "MATCH (p) WHERE id(p) = {id} CREATE (p)-[:HAS_TRAIT]->(:Trait {type:'Immortal'})", {id: id })
158+
.then(function (neoRecord) {
159+
var immortalsCreated = neoRecord.summary.updateStatistics.nodesCreated();
160+
var relationshipCreated = neoRecord.summary.updateStatistics.relationshipsCreated();
161+
console.log("There were " + immortalsCreated + " immortal and " + relationshipCreated +
162+
" relationships created");
163+
});
164+
});
165+
// tag::result-cursor[]
166+
});
167+
168+
//await the result
169+
setTimeout(function() {
170+
expect(out[0]).toBe("There were 1 immortal and 1 relationships created");
171+
done();
172+
}, 500);
173+
});
174+
175+
it('should be able to retain for later processing', function(done) {
176+
session.run("CREATE (:Person {name:'The One', age: 23})").then(function() {
177+
// tag::retain-result-process[]
178+
session
179+
.run("MATCH (p:Person { name: {name} }) RETURN p.age", {name: "The One"})
180+
.then(function (result) {
181+
for (i = 0; i < result.records.length; i++) {
182+
result.records[i].forEach(function (value, key, record) {
183+
console.log("Value for key " + key + " has value " + value);
184+
});
185+
}
186+
187+
});
188+
// end::retain-result-process[]
189+
});
190+
191+
//await the result
192+
setTimeout(function() {
193+
expect(out[0]).toBe("Value for key p.age has value 23");
194+
done();
195+
}, 500);
196+
});
197+
198+
199+
it('should be able to profile', function(done) {
200+
session.run("CREATE (:Person {name:'The One', age: 23})").then(function() {
201+
// tag::retain-result-process[]
202+
session
203+
.run("PROFILE MATCH (p:Person { name: {name} }) RETURN id(p)", {name: "The One"})
204+
.then(function (result) {
205+
console.log(result.summary.profile);
206+
});
207+
// end::retain-result-process[]
208+
});
209+
210+
//await the result
211+
setTimeout(function() {
212+
expect(out.length).toBe(1);
213+
done();
214+
}, 500);
215+
});
216+
217+
it('should be able to see notifications', function(done) {
218+
// tag::retain-result-process[]
219+
session
220+
.run("EXPLAIN MATCH (a), (b) RETURN a,b")
221+
.then(function (result) {
222+
var notifications = result.summary.notifications, i;
223+
for (i = 0; i < notifications.length; i++) {
224+
console.log(notifications[i].code);
225+
}
226+
});
227+
// end::retain-result-process[]
228+
229+
setTimeout(function () {
230+
expect(out[0]).toBe("Neo.ClientNotification.Statement.CartesianProductWarning");
231+
done();
232+
}, 500);
233+
});
234+
99235
it('should document committing a transaction', function() {
100236
// tag::transaction-commit[]
101237
var tx = session.beginTransaction();
@@ -113,6 +249,7 @@ describe('examples', function() {
113249
});
114250

115251
it('should document how to require encryption', function() {
252+
var neo4j = neo4jv1;
116253
// tag::tls-require-encryption[]
117254
var driver = neo4j.driver("bolt://localhost", neo4j.auth.basic("neo4j", "neo4j"), {
118255
// In NodeJS, encryption is on by default. In the web bundle, it is off.
@@ -123,6 +260,7 @@ describe('examples', function() {
123260
});
124261

125262
it('should document how to configure trust-on-first-use', function() {
263+
var neo4j = neo4jv1;
126264
// tag::tls-trust-on-first-use[]
127265
var driver = neo4j.driver("bolt://localhost", neo4j.auth.basic("neo4j", "neo4j"), {
128266
// Note that trust-on-first-use is not available in the browser bundle,
@@ -136,6 +274,7 @@ describe('examples', function() {
136274
});
137275

138276
it('should document how to configure a trusted signing certificate', function() {
277+
var neo4j = neo4jv1;
139278
// tag::tls-signed[]
140279
var driver = neo4j.driver("bolt://localhost", neo4j.auth.basic("neo4j", "neo4j"), {
141280
trust: "TRUST_SIGNED_CERTIFICATES",

test/v1/session.test.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ describe('session', function() {
4646
expect(counter).toBe(1);
4747
_session.close();
4848
expect(counter).toBe(1);
49-
})
49+
});
5050

5151
it('should expose basic run/subscribe ', function(done) {
5252
// Given

0 commit comments

Comments
 (0)