Skip to content

Commit eef0e45

Browse files
author
Zhen
committed
Change the java driver to use neokit to manage server start
1 parent 32e209d commit eef0e45

File tree

7 files changed

+85
-134
lines changed

7 files changed

+85
-134
lines changed

.gitmodules

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
[submodule "neokit"]
2+
path = neokit
3+
url = https://github.com/neo-technology/neokit.git

gulpfile.js

Lines changed: 32 additions & 75 deletions
Original file line numberDiff line numberDiff line change
@@ -165,46 +165,9 @@ gulp.task('watch-n-test', ['test-nodejs'], function () {
165165
return gulp.watch(['src/**/*.js', "test/**/*.js"], ['test-nodejs'] );
166166
});
167167

168-
var neo4jLinuxUrl = 'http://alpha.neohq.net/dist/neo4j-enterprise-3.0.0-NIGHTLY-unix.tar.gz';
169-
var neo4jWinUrl = 'http://alpha.neohq.net/dist/neo4j-enterprise-3.0.0-NIGHTLY-windows.zip';
170-
var neo4jHome = './build/neo4j-enterprise-3.0.0';
171-
var isWin = /^win/.test(process.platform);
172-
173-
gulp.task('download-neo4j', function() {
174-
if( !fs.existsSync(neo4jHome) ) {
175-
// Need to download
176-
if(isWin) {
177-
return download(neo4jWinUrl)
178-
.pipe(decompress({strip: 1}))
179-
.pipe(gulp.dest(neo4jHome));
180-
}
181-
else {
182-
return download(neo4jLinuxUrl)
183-
.pipe(decompress({strip: 1}))
184-
.pipe(gulp.dest(neo4jHome));
185-
}
186-
}
187-
});
188-
189-
gulp.task('set-password', ['download-neo4j'], function() {
190-
var setPassword = gulp.src('test/resources/auth')
191-
.pipe(gulp.dest(neo4jHome + "/data/dbms/"));
192-
193-
if(isWin)
194-
{
195-
var setServerName = gulp.src('test/resources/neo4j-wrapper.conf')
196-
.pipe(gulp.dest(neo4jHome + "/conf/"));
197-
198-
return merge(setPassword, setServerName);
199-
}
200-
else
201-
{
202-
return setPassword;
203-
}
204-
});
205168

206169
var featureFiles = 'https://s3-eu-west-1.amazonaws.com/remoting.neotechnology.com/driver-compliance/tck.tar.gz';
207-
var featureHome = './build/tck';
170+
var featureHome = './build/tck';
208171

209172
gulp.task('download-tck', function() {
210173
return download(featureFiles)
@@ -220,21 +183,6 @@ gulp.task('run-tck', ['download-tck', 'nodejs'], function() {
220183
}));
221184
});
222185

223-
var runPowershell = function( cmd ) {
224-
var spawn = childProcess.spawn, child;
225-
child = spawn("powershell.exe",[cmd]);
226-
child.stdout.on("data",function(data){
227-
console.log("Powershell Data: " + data);
228-
});
229-
child.stderr.on("data",function(data){
230-
console.error("Powershell Errors: " + data);
231-
});
232-
child.on("exit",function(){
233-
console.log("Powershell Script finished");
234-
});
235-
child.stdin.end(); //end input
236-
};
237-
238186
/** Set the project version, controls package.json and version.js */
239187
gulp.task('set', function() {
240188
// Get the --version arg from command line
@@ -247,28 +195,37 @@ gulp.task('set', function() {
247195

248196
});
249197

250-
gulp.task('start-neo4j', ['set-password'], function() {
251-
if(isWin) {
252-
return runPowershell(neo4jHome + '/bin/neo4j.bat install-service;' + neo4jHome + '/bin/neo4j.bat start');
253-
}
254-
else {
255-
return gulp.src('').pipe(shell([
256-
'mkdir -p ' + neo4jHome + '/logs',
257-
'mkdir -p ' + neo4jHome + '/run',
258-
'mkdir -p ' + neo4jHome + '/plugins',
259-
'mkdir -p ' + neo4jHome + '/import',
260-
'chmod +x ' + neo4jHome + '/bin/neo4j',
261-
neo4jHome + '/bin/neo4j start',
262-
]));
263-
}
198+
199+
var neo4jHome = path.resolve('./build/neo4j');
200+
var neorunPath = path.resolve('./neokit/neorun.py');
201+
202+
gulp.task('start-neo4j', function() {
203+
204+
//var neorunArgs = minimist(process.argv.slice(2), { string: 'opts' }).opts;
205+
var neorunArgs;
206+
neorunArgs = neorunArgs || '-v 3.0.1 -p neo4j';
207+
208+
return runScript([
209+
neorunPath, '--start=' + neo4jHome
210+
].concat( neorunArgs.split(" ") ) );
264211
});
265212

266213
gulp.task('stop-neo4j', function() {
267-
if(isWin) {
268-
return runPowershell(neo4jHome + '/bin/neo4j.bat stop;' + neo4jHome + '/bin/neo4j.bat uninstall-service');
269-
} else {
270-
return gulp.src('').pipe(shell([
271-
neo4jHome + '/bin/neo4j stop',
272-
]));
273-
}
274-
});
214+
return runScript([
215+
neorunPath, '--stop=' + neo4jHome
216+
]);
217+
});
218+
219+
var runScript = function(cmd) {
220+
var spawnSync = childProcess.spawnSync, child, code;
221+
child = spawnSync('python', cmd);
222+
console.log("Script Outputs:\n" + child.stdout.toString());
223+
var error = child.stderr.toString();
224+
if (error.trim() !== "")
225+
console.log("Script Errors:\n"+ error);
226+
code = child.status;
227+
if( code !==0 )
228+
{
229+
throw "Script finished with code " + code
230+
}
231+
};

neokit

Submodule neokit added at 03df88a

test/internal/tls.test.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ describe('trust-signed-certificates', function() {
5757
driver = neo4j.driver("bolt://localhost", neo4j.auth.basic("neo4j", "neo4j"), {
5858
encrypted: true,
5959
trust: "TRUST_SIGNED_CERTIFICATES",
60-
trustedCertificates: ["build/neo4j-enterprise-3.0.0/certificates/neo4j.cert"]
60+
trustedCertificates: ["build/neo4j/certificates/neo4j.cert"]
6161
});
6262

6363
// When

test/resources/auth

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

test/v1/tck/steps/tlssteps.js

Lines changed: 25 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,24 @@
11
var neo4j = require("../../../../lib/v1");
22
var util = require("./util");
33

4+
var CALLBACK_TIMEOUT = 60 * 1000;
5+
46
module.exports = function () {
57

6-
this.Given(/^a running Neo(\d+)j Database$/, {timeout: 60 * 1000}, function (ignored, callback) {
8+
this.Given(/^a running Neo(\d+)j Database$/, {timeout: CALLBACK_TIMEOUT}, function (ignored, callback) {
79
if (this.driver1) this.driver1.close();
810
if (this.driver2) this.driver2.close();
911
util.changeCertificates('./test/resources/derived.key', './test/resources/derived.cert');
10-
util.restart(callback);
12+
util.restart();
13+
callback();
1114
});
1215

1316
this.When(/^I connect via a TLS\-enabled transport for the first time for the given hostname and port$/, function (callback) {
1417
this.driver1 = _connectWithHostFile(this.knownHosts1);
1518
callback();
1619
});
1720

18-
this.Then(/^sessions should simply work$/, {timeout: 60 * 1000}, function (callback) {
21+
this.Then(/^sessions should simply work$/, {timeout: CALLBACK_TIMEOUT}, function (callback) {
1922
var session = this.driver1.session();
2023
session.run("RETURN 1").then(function (result) {
2124
session.close();
@@ -26,15 +29,14 @@ module.exports = function () {
2629
});
2730

2831
this.Given(/^a running Neo(\d+)j Database that I have connected to with a TLS\-enabled transport in the past$/,
29-
{timeout: 60 * 1000}, function (arg1, callback) {
32+
{timeout: CALLBACK_TIMEOUT}, function (arg1, callback) {
3033
util.changeCertificates('./test/resources/derived.key', './test/resources/derived.cert');
3134
var self = this;
32-
util.restart(function () {
33-
var driver = _connectWithHostFile(self.knownHosts1);
34-
driver.session().run("RETURN 1").then(function (result) {
35-
driver.close();
36-
callback();
37-
});
35+
util.restart();
36+
var driver = _connectWithHostFile(self.knownHosts1);
37+
driver.session().run("RETURN 1").then(function (result) {
38+
driver.close();
39+
callback();
3840
});
3941
});
4042

@@ -43,9 +45,10 @@ module.exports = function () {
4345
callback();
4446
});
4547

46-
this.Given(/^the database has changed which certificate it uses$/, {timeout: 60 * 1000}, function (callback) {
48+
this.Given(/^the database has changed which certificate it uses$/, {timeout: CALLBACK_TIMEOUT}, function (callback) {
4749
util.changeCertificates('./test/resources/other.key', './test/resources/other.cert');
48-
util.restart(callback);
50+
util.restart();
51+
callback();
4952
});
5053

5154
this.Then(/^creating sessions should fail$/, function (callback) {
@@ -114,17 +117,18 @@ module.exports = function () {
114117
});
115118

116119
this.Given(/^a running Neo(\d+)j Database using a certificate signed by the same trusted certificate$/,
117-
{timeout: 60 * 1000}, function (arg1, callback) {
120+
{timeout: CALLBACK_TIMEOUT}, function (arg1, callback) {
118121
util.changeCertificates('./test/resources/derived.key', './test/resources/derived.cert');
119-
util.restart(callback);
122+
util.restart();
123+
callback();
120124
});
121125

122126
this.When(/^I connect via a TLS\-enabled transport$/, function (callback) {
123127
this.driver1 = neo4j.driver("bolt://localhost", neo4j.auth.basic("neo4j", "neo4j"), this.config);
124128
callback();
125129
});
126130

127-
this.Given(/^a running Neo(\d+)j Database using that exact trusted certificate$/, {timeout: 60 * 1000}, function (arg1, callback) {
131+
this.Given(/^a running Neo(\d+)j Database using that exact trusted certificate$/, {timeout: CALLBACK_TIMEOUT}, function (arg1, callback) {
128132
//will have to hack a little bit here since the root cert cannot be used by the server since its
129133
//common name is not set to localhost
130134
this.config = {
@@ -135,13 +139,15 @@ module.exports = function () {
135139
};
136140

137141
util.changeCertificates('./test/resources/other.key', './test/resources/other.cert');
138-
util.restart(callback);
142+
util.restart();
143+
callback();
139144
});
140145

141-
this.Given(/^a running Neo(\d+)j Database using a certificate not signed by the trusted certificate$/, {timeout: 60 * 1000},
146+
this.Given(/^a running Neo(\d+)j Database using a certificate not signed by the trusted certificate$/, {timeout: CALLBACK_TIMEOUT},
142147
function (arg1, callback) {
143148
util.changeCertificates('./test/resources/other.key', './test/resources/other.cert');
144-
util.restart(callback);
149+
util.restart();
150+
callback();
145151
});
146152

147153
this.Then(/^I should get a helpful error explaining that no trusted certificate found$/, function (callback) {
@@ -165,4 +171,4 @@ module.exports = function () {
165171
encrypted: true
166172
});
167173
}
168-
};
174+
};

test/v1/tck/steps/util.js

Lines changed: 23 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,8 @@ NULL = 'null';
2727
RELATIONSHIP = 'relationship';
2828
NODE = 'node';
2929
PATH = 'path';
30-
var isWin = /^win/.test(process.platform);
31-
var neo4jHome = './build/neo4j-enterprise-3.0.0';
30+
var neorunPath = './neokit/neorun.py';
31+
var neo4jHome = './build/neo4j';
3232
var neo4jCert = neo4jHome + '/certificates/neo4j.cert';
3333
var neo4jKey = neo4jHome + '/certificates/neo4j.key';
3434
var childProcess = require("child_process");
@@ -354,48 +354,33 @@ function changeCertificates(keyFile, certFile) {
354354
fs.writeFileSync(neo4jCert, cert);
355355
}
356356

357-
function restart(callback) {
357+
function restart() {
358358
stopDatabase();
359-
setTimeout(function () {
360-
startDatabase();
361-
setTimeout(function () {
362-
callback();}, 5000);
363-
}, 5000);
359+
startDatabase();
364360
}
365361

366362
function startDatabase() {
367-
if(isWin) {
368-
return runPowershell(neo4jHome + '/bin/neo4j.bat install-service;' + neo4jHome + '/bin/neo4j.bat start');
369-
} else {
370-
childProcess.exec(neo4jHome + '/bin/neo4j start', function (err, stdout, stderr) {
371-
console.log("starting");
372-
if (err) throw err;
373-
});
374-
}
363+
return runScript([
364+
neorunPath, '--start=' + neo4jHome
365+
]);
375366
}
376367

377368
function stopDatabase() {
378-
if(isWin) {
379-
runPowershell(neo4jHome + '/bin/neo4j.bat stop;' + neo4jHome + '/bin/neo4j.bat uninstall-service');
380-
} else {
381-
childProcess.exec(neo4jHome + '/bin/neo4j stop', function (err, stdout, stderr) {
382-
console.log("stopping");
383-
if (err) throw err;
384-
});
385-
}
369+
return runScript([
370+
neorunPath, '--stop=' + neo4jHome
371+
]);
386372
}
387373

388-
var runPowershell = function( cmd ) {
389-
var spawn = childProcess.spawn, child;
390-
child = spawn("powershell.exe",[cmd]);
391-
child.stdout.on("data",function(data){
392-
console.log("Powershell Data: " + data);
393-
});
394-
child.stderr.on("data",function(data){
395-
console.error("Powershell Errors: " + data);
396-
});
397-
child.on("exit",function(){
398-
console.log("Powershell Script finished");
399-
});
400-
child.stdin.end(); //end input
401-
};
374+
var runScript = function(cmd) {
375+
var spawnSync = childProcess.spawnSync, child, code;
376+
child = spawnSync('python', cmd);
377+
console.log("Script Outputs:\n" + child.stdout.toString());
378+
var error = child.stderr.toString();
379+
if (error.trim() !== "")
380+
console.log("Script Errors:\n"+ error);
381+
code = child.status;
382+
if( code !==0 )
383+
{
384+
throw "Script finished with code " + code
385+
}
386+
};

0 commit comments

Comments
 (0)