|
| 1 | +/** |
| 2 | + * Copyright (c) 2002-2020 "Neo4j," |
| 3 | + * Neo4j Sweden AB [http://neo4j.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 | +import MultiDatabaseRountingProcuderRunner from '../../../src/internal/routing-table-getter/routing-procedure-runner-multi-database' |
| 21 | +import ServerAddress from '../../../src/internal/server-address' |
| 22 | +import TxConfig from '../../../src/internal/tx-config' |
| 23 | +import Result from '../../../src/result' |
| 24 | +import FakeConnection from '../fake-connection' |
| 25 | +import FakeSession from '../fake-session' |
| 26 | + |
| 27 | +describe('#unit MultiDatabaseRountingProcuderRunner', () => { |
| 28 | + it('should run query over protocol with the correct params', () => { |
| 29 | + const initialAddress = ServerAddress.fromUrl('bolt://127.0.0.1') |
| 30 | + const bookmark = 'bookmark' |
| 31 | + const mode = 'READ' |
| 32 | + const database = 'adb' |
| 33 | + const sessionDatabase = 'session.database' |
| 34 | + const onComplete = () => 'nothing' |
| 35 | + const connection = new FakeConnection().withProtocolVersion(3) |
| 36 | + const context = { someContext: '1234' } |
| 37 | + const session = new FakeSession(null, connection) |
| 38 | + .withBookmark(bookmark) |
| 39 | + .withMode(mode) |
| 40 | + .withDatabase(sessionDatabase) |
| 41 | + .withOnComplete(onComplete) |
| 42 | + |
| 43 | + run({ connection, context, session, database, initialAddress }) |
| 44 | + |
| 45 | + expect(connection.seenQueries).toEqual([ |
| 46 | + 'CALL dbms.routing.getRoutingTable($context, $database)' |
| 47 | + ]) |
| 48 | + expect(connection.seenParameters).toEqual([ |
| 49 | + { context: { ...context, address: initialAddress }, database } |
| 50 | + ]) |
| 51 | + expect(connection.seenProtocolOptions).toEqual([ |
| 52 | + { |
| 53 | + bookmark, |
| 54 | + txConfig: TxConfig.empty(), |
| 55 | + mode, |
| 56 | + database: sessionDatabase, |
| 57 | + afterComplete: onComplete |
| 58 | + } |
| 59 | + ]) |
| 60 | + }) |
| 61 | + |
| 62 | + it('should return a result', () => { |
| 63 | + const connection = new FakeConnection().withProtocolVersion(3) |
| 64 | + const context = { someContext: '1234' } |
| 65 | + const session = new FakeSession(null, connection) |
| 66 | + |
| 67 | + const result = run({ connection, context, session }) |
| 68 | + |
| 69 | + expect(result).toEqual(jasmine.any(Result)) |
| 70 | + expect(result._streamObserverPromise).toEqual(jasmine.any(Promise)) |
| 71 | + }) |
| 72 | +}) |
| 73 | + |
| 74 | +function run ({ |
| 75 | + connection, |
| 76 | + database = 'adb', |
| 77 | + context, |
| 78 | + session, |
| 79 | + initialAddress |
| 80 | +}) { |
| 81 | + const runner = new MultiDatabaseRountingProcuderRunner(initialAddress) |
| 82 | + return runner.run(connection, database, context, session) |
| 83 | +} |
0 commit comments