Skip to content

Commit eddeff7

Browse files
committed
Merge pull request neo4j#58 from neo4j/1.0-tck
1.0 tck
2 parents cbe8d30 + cc21f43 commit eddeff7

File tree

6 files changed

+98
-10
lines changed

6 files changed

+98
-10
lines changed

gulpfile.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -216,7 +216,7 @@ gulp.task('run-tck', ['download-tck', 'nodejs'], function() {
216216
return gulp.src(featureHome + "/*").pipe(cucumber({
217217
'steps': 'test/v1/tck/steps/*.js',
218218
'format': 'pretty',
219-
'tags' : ['~@in_dev', '~@db', '~@equality', '~@streaming_and_cursor_navigation']
219+
'tags' : ['~@fixed_session_pool', '~@db', '~@equality', '~@streaming_and_cursor_navigation', '~@tls']
220220
}));
221221
});
222222

src/v1/session.js

+7-3
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
import StreamObserver from './internal/stream-observer';
2121
import Result from './result';
2222
import Transaction from './transaction';
23+
import {newError} from "./error";
2324

2425
/**
2526
* A Session instance is used for handling the connection and
@@ -58,8 +59,9 @@ class Session {
5859
this._conn.pullAll(streamObserver);
5960
this._conn.sync();
6061
} else {
61-
streamObserver.onError({error: "Please close the currently open transaction object before running " +
62-
"more statements/transactions in the current session." });
62+
streamObserver.onError(newError("Statements cannot be run directly on a "
63+
+ "session with an open transaction; either run from within the "
64+
+ "transaction or use a different session."));
6365
}
6466
return new Result( streamObserver, statement, parameters );
6567
}
@@ -74,7 +76,9 @@ class Session {
7476
*/
7577
beginTransaction() {
7678
if (this._hasTx) {
77-
throw new newError("Cannot have multiple transactions open for the session. Use multiple sessions or close the transaction before opening a new one.")
79+
throw new newError("You cannot begin a transaction on a session with an "
80+
+ "open transaction; either run from within the transaction or use a "
81+
+ "different session.")
7882
}
7983

8084
this._hasTx = true;

test/v1/session.test.js

+3-2
Original file line numberDiff line numberDiff line change
@@ -234,8 +234,9 @@ describe('session', function() {
234234
//Then
235235
session.run("RETURN 42")
236236
.catch(function (error) {
237-
expect(error.error).toBe("Please close the currently open transaction object before running " +
238-
"more statements/transactions in the current session." );
237+
expect(error.message).toBe("Statements cannot be run directly on a "
238+
+ "session with an open transaction; either run from within the "
239+
+ "transaction or use a different session." );
239240
done();
240241
})
241242
});

test/v1/tck/steps/authsteps.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ module.exports = function () {
5959
var expectedStartOfMessage = 'The client is unauthorized due to authentication failure.'
6060
var expectedCode = 'Neo.ClientError.Security.Unauthorized'
6161

62-
if (! message.startsWith(expectedStartOfMessage)) {
62+
if (message.indexOf(expectedStartOfMessage) != 0) {
6363
throw new Error("Wrong error messsage. Expected: '" + expectedStartOfMessage + "'. Got: '" + message + "'");
6464
}
6565

+78
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
/**
2+
* Copyright (c) 2002-2016 "Neo Technology,"
3+
* Network Engine for Objects in Lund AB [http://neotechnology.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+
20+
var neo4j = require("../../../../lib/v1");
21+
var util = require("./util");
22+
23+
module.exports = function () {
24+
25+
this.Given(/^I have a driver$/, function () {
26+
});
27+
28+
this.When(/^I start a `Transaction` through a session$/, function () {
29+
this.transaction = this.session.beginTransaction()
30+
});
31+
32+
this.When(/^`run` a query with that same session without closing the transaction first$/, function (callback) {
33+
self = this;
34+
this.session.run("CREATE (:n)").then(function(result) {callback()}).catch(function(err) {self.error = err; callback()})
35+
});
36+
37+
this.Then(/^it throws a `ClientException`$/, function (table) {
38+
expected = table.rows()[0][0];
39+
if (this.error === undefined) {
40+
throw new Error("Exepcted an error but got none.")
41+
}
42+
if (this.error.message.indexOf(expected) != 0) {
43+
if (!(expected == "Unsupported URI scheme:" || expected == "Unable to connect to" ))
44+
{
45+
throw new Error("Error messages do not match. Given: '" + this.error.message + "'. Expected: '" + expected + "'");
46+
}
47+
}
48+
});
49+
50+
this.When(/^I start a new `Transaction` with the same session before closing the previous$/, function () {
51+
try {
52+
this.session.beginTransaction();
53+
} catch (e) {
54+
this.error = e;
55+
}
56+
57+
});
58+
59+
this.When(/^I run a non valid cypher statement$/, function (callback) {
60+
self = this;
61+
this.session.run("CRETE (:n)").then(function(result) {callback()}).catch(function(err) {self.error = err.fields[0]; callback()})
62+
});
63+
64+
this.When(/^I set up a driver to an incorrect port$/, function (callback) {
65+
self = this;
66+
driver = neo4j.driver("bolt://localhost:7777", neo4j.auth.basic("neo4j", "neo4j"));
67+
driver.session();
68+
driver.onError = function (error) { self.error = error; callback()};
69+
});
70+
71+
this.When(/^I set up a driver with wrong scheme$/, function (callback) {
72+
self = this;
73+
driver = neo4j.driver("wrong://localhost:7474", neo4j.auth.basic("neo4j", "neo4j"));
74+
driver.session();
75+
driver.onError = function (error) { self.error = error; callback()};
76+
});
77+
78+
}

test/v1/tck/steps/util.js

+8-3
Original file line numberDiff line numberDiff line change
@@ -281,6 +281,9 @@ function getLiteralArray(result) {
281281
}
282282

283283
function compareValues(given, expected) {
284+
if(given === undefined || expected === undefined) {
285+
throw new Error("Got undefined");
286+
}
284287
if (neo4j.isInt(given)) {
285288
if (given.equals(expected)) {
286289
return true;
@@ -357,14 +360,15 @@ function restart(callback) {
357360
startDatabase();
358361
setTimeout(function () {
359362
callback();}, 5000);
360-
}, 500);
363+
}, 5000);
361364
}
362365

363366
function startDatabase() {
364367
if(isWin) {
365368
return runPowershell(neo4jHome + '/bin/neo4j.bat install-service;' + neo4jHome + '/bin/neo4j.bat start');
366369
} else {
367-
childProcess.execSync(neo4jHome + '/bin/neo4j start', function (err, stdout, stderr) {
370+
childProcess.exec(neo4jHome + '/bin/neo4j start', function (err, stdout, stderr) {
371+
console.log("starting");
368372
if (err) throw err;
369373
});
370374
}
@@ -374,7 +378,8 @@ function stopDatabase() {
374378
if(isWin) {
375379
runPowershell(neo4jHome + '/bin/neo4j.bat stop;' + neo4jHome + '/bin/neo4j.bat uninstall-service');
376380
} else {
377-
childProcess.execSync(neo4jHome + '/bin/neo4j stop', function (err, stdout, stderr) {
381+
childProcess.exec(neo4jHome + '/bin/neo4j stop', function (err, stdout, stderr) {
382+
console.log("stopping");
378383
if (err) throw err;
379384
});
380385
}

0 commit comments

Comments
 (0)