From c69cd61203a14bfcc0d7e2420e22eb8b1b966496 Mon Sep 17 00:00:00 2001 From: Ali Ince Date: Wed, 15 May 2019 16:29:11 +0100 Subject: [PATCH 1/2] Add neo4j scheme as a direct alias for bolt+routing --- src/v1/index.js | 2 +- .../node/routing.driver.boltkit.test.js | 64 +++++++++++-------- test/internal/url-util.test.js | 2 +- test/v1/stress.test.js | 2 +- 4 files changed, 39 insertions(+), 31 deletions(-) diff --git a/src/v1/index.js b/src/v1/index.js index 5d73b17df..cba614ced 100644 --- a/src/v1/index.js +++ b/src/v1/index.js @@ -227,7 +227,7 @@ const logging = { function driver(url, authToken, config = {}) { assertString(url, 'Bolt URL'); const parsedUrl = urlUtil.parseDatabaseUrl(url); - if (parsedUrl.scheme === 'bolt+routing') { + if (['bolt+routing', 'neo4j'].indexOf(parsedUrl.scheme) !== -1) { return new RoutingDriver(ServerAddress.fromUrl(parsedUrl.hostAndPort), parsedUrl.query, USER_AGENT, authToken, config); } else if (parsedUrl.scheme === 'bolt') { if (!isEmptyObjectOrNull(parsedUrl.query)) { diff --git a/test/internal/node/routing.driver.boltkit.test.js b/test/internal/node/routing.driver.boltkit.test.js index aa80b7064..bd30958a5 100644 --- a/test/internal/node/routing.driver.boltkit.test.js +++ b/test/internal/node/routing.driver.boltkit.test.js @@ -39,36 +39,14 @@ describe('routing driver with stub server', () => { jasmine.DEFAULT_TIMEOUT_INTERVAL = originalTimeout; }); - it('should discover servers', done => { - if (!boltStub.supported) { - done(); - return; - } - // Given - const server = boltStub.start('./test/resources/boltstub/discover_servers_and_read.script', 9001); - - boltStub.run(() => { - const driver = boltStub.newDriver('bolt+routing://127.0.0.1:9001'); - // When - const session = driver.session(); - session.run("MATCH (n) RETURN n.name").then(() => { - - session.close(); - // Then - expect(hasAddressInConnectionPool(driver, '127.0.0.1:9001')).toBeTruthy(); - assertHasRouters(driver, ["127.0.0.1:9001", "127.0.0.1:9002", "127.0.0.1:9003"]); - assertHasReaders(driver, ["127.0.0.1:9002", "127.0.0.1:9003"]); - assertHasWriters(driver, ["127.0.0.1:9001"]); - - driver.close(); - server.exit(code => { - expect(code).toEqual(0); - done(); - }); - }); - }); + it('should discover servers with bolt+routing scheme', done => { + testDiscovery('bolt+routing', done) }); + it('should discover servers with neo4j scheme', done => { + testDiscovery('neo4j', done) + }) + it('should discover IPv6 servers', done => { if (!boltStub.supported) { done(); @@ -2168,6 +2146,36 @@ describe('routing driver with stub server', () => { }); }); + function testDiscovery(scheme, done) { + if (!boltStub.supported) { + done() + return + } + // Given + const server = boltStub.start('./test/resources/boltstub/discover_servers_and_read.script', 9001) + + boltStub.run(() => { + const driver = boltStub.newDriver(`${scheme}://127.0.0.1:9001`) + // When + const session = driver.session() + session.run('MATCH (n) RETURN n.name').then(() => { + + session.close() + // Then + expect(hasAddressInConnectionPool(driver, '127.0.0.1:9001')).toBeTruthy() + assertHasRouters(driver, ['127.0.0.1:9001', '127.0.0.1:9002', '127.0.0.1:9003']) + assertHasReaders(driver, ['127.0.0.1:9002', '127.0.0.1:9003']) + assertHasWriters(driver, ['127.0.0.1:9001']) + + driver.close() + server.exit(code => { + expect(code).toEqual(0) + done() + }) + }) + }) + } + function testAddressPurgeOnDatabaseError(query, accessMode, done) { if (!boltStub.supported) { done(); diff --git a/test/internal/url-util.test.js b/test/internal/url-util.test.js index dc0aeca33..9cd5b440f 100644 --- a/test/internal/url-util.test.js +++ b/test/internal/url-util.test.js @@ -724,7 +724,7 @@ describe('url-util', () => { }); it('should parse URLs with port 80', () => { - ['http', 'https', 'ws', 'wss', 'bolt', 'bolt+routing'].forEach(scheme => { + ['http', 'https', 'ws', 'wss', 'bolt', 'bolt+routing', 'neo4j'].forEach(scheme => { verifyUrl(`${scheme}://localhost:80`, { scheme: scheme, host: 'localhost', diff --git a/test/v1/stress.test.js b/test/v1/stress.test.js index 4fcfa11cf..eaaf34e51 100644 --- a/test/v1/stress.test.js +++ b/test/v1/stress.test.js @@ -299,7 +299,7 @@ describe('stress tests', () => { } function verifyServers(context) { - const routing = DATABASE_URI.indexOf('bolt+routing') === 0; + const routing = DATABASE_URI.indexOf('bolt+routing') === 0 || DATABASE_URI.indexOf('neo4j') === 0 if (routing) { return verifyCausalClusterMembers(context); From d86c307bde1fe0b450c22321540214a8792551fa Mon Sep 17 00:00:00 2001 From: Ali Ince Date: Thu, 16 May 2019 11:25:38 +0100 Subject: [PATCH 2/2] Remove error message assertion --- test/internal/node/direct.driver.boltkit.test.js | 1 - 1 file changed, 1 deletion(-) diff --git a/test/internal/node/direct.driver.boltkit.test.js b/test/internal/node/direct.driver.boltkit.test.js index 1ee02b0ef..30b45a56d 100644 --- a/test/internal/node/direct.driver.boltkit.test.js +++ b/test/internal/node/direct.driver.boltkit.test.js @@ -401,7 +401,6 @@ describe('direct driver with stub server', () => { writeTx.run('CREATE (n {name: \'Bob\'})').then(() => writeTx.commit().then(result => fail('expected an error'), (error) => { expect(error.code).toBe(SERVICE_UNAVAILABLE); - expect(error.message).toContain('Connection was closed by server'); }) ).finally(() => session.close(() => {