From 43cb31ec0961b91777b4e2243fb32df63469ad89 Mon Sep 17 00:00:00 2001 From: martin bendsoe Date: Wed, 20 May 2020 13:31:21 +0200 Subject: [PATCH 1/4] added address in routing context --- neo4j/io/__init__.py | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/neo4j/io/__init__.py b/neo4j/io/__init__.py index f69ec3ec5..acd3258ae 100644 --- a/neo4j/io/__init__.py +++ b/neo4j/io/__init__.py @@ -531,11 +531,24 @@ def opener(addr, timeout): return pool def __init__(self, opener, pool_config, workspace_config, routing_context, addresses): + """ + + :param opener: + :param pool_config: + :param workspace_config: + :param routing_context: Dictionary with routing information + :param addresses: + """ super(Neo4jPool, self).__init__(opener, pool_config, workspace_config) # Each database have a routing table, the default database is a special case. log.debug("[#0000] C: routing addresses %r", addresses) + self.init_address = addresses[0] self.routing_tables = {workspace_config.database: RoutingTable(database=workspace_config.database, routers=addresses)} self.routing_context = routing_context + if "address" in routing_context: + raise ConfigurationError("The key 'address' is reserved for internal routing context.") + self.routing_context["address"] = str(self.init_address) + log.debug("routing_context", self.routing_context) # self.missing_writer = False self.refresh_lock = Lock() @@ -580,6 +593,8 @@ def fetch_routing_info(self, *, address, timeout, database): :param address: router address :param timeout: seconds :param database: the data base name to get routing table for + :param init_address: the address by which the client initially contacted the server as a hint for inclusion in the returned routing table. + :return: list of routing records or None if no connection could be established :raise ServiceUnavailable: if the server does not support routing or From 9a1f18fbbf6382d5d2f49ff261ba1292b26571c5 Mon Sep 17 00:00:00 2001 From: martin bendsoe Date: Wed, 20 May 2020 14:52:16 +0200 Subject: [PATCH 2/4] fixed stubtests --- neo4j/io/__init__.py | 2 +- tests/stub/conftest.py | 14 ++-- tests/stub/scripts/v3/broken_router.script | 3 +- ...er_routing_get_routing_table_system.script | 2 +- .../stub/scripts/v3/get_routing_table.script | 3 +- .../v3/get_routing_table_with_context.script | 3 +- tests/stub/scripts/v3/non_router.script | 3 +- tests/stub/scripts/v3/router.script | 2 +- .../stub/scripts/v3/router_no_readers.script | 3 +- .../stub/scripts/v3/router_no_routers.script | 3 +- .../stub/scripts/v3/router_no_writers.script | 3 +- .../v3/router_with_multiple_servers.script | 3 +- .../v3/router_with_multiple_writers.script | 3 +- tests/stub/scripts/v3/rude_router.script | 3 +- tests/stub/scripts/v3/silent_router.script | 3 +- ...ng_get_routing_table_system_default.script | 2 +- ...ting_get_routing_table_system_neo4j.script | 2 +- tests/stub/scripts/v4x0/router.script | 2 +- ...uter_get_routing_table_with_context.script | 2 +- ..._read_port_9004_one_write_port_9006.script | 2 +- ..._port_with_role_read_and_role_write.script | 2 +- .../v4x0/router_with_no_role_read.script | 2 +- .../v4x0/router_with_no_role_write.script | 2 +- .../routing_table_failure_not_a_router.script | 2 +- .../v4x0/routing_table_silent_router.script | 2 +- tests/stub/test_accesslevel.py | 30 +++---- tests/stub/test_multi_database.py | 2 +- tests/stub/test_routingdriver.py | 82 +++++++------------ 28 files changed, 82 insertions(+), 105 deletions(-) diff --git a/neo4j/io/__init__.py b/neo4j/io/__init__.py index acd3258ae..8117393bc 100644 --- a/neo4j/io/__init__.py +++ b/neo4j/io/__init__.py @@ -548,7 +548,7 @@ def __init__(self, opener, pool_config, workspace_config, routing_context, addre if "address" in routing_context: raise ConfigurationError("The key 'address' is reserved for internal routing context.") self.routing_context["address"] = str(self.init_address) - log.debug("routing_context", self.routing_context) + log.debug("routing_context {}".format(self.routing_context)) # self.missing_writer = False self.refresh_lock = Lock() diff --git a/tests/stub/conftest.py b/tests/stub/conftest.py index 4b7bcc61b..7e564af96 100644 --- a/tests/stub/conftest.py +++ b/tests/stub/conftest.py @@ -28,11 +28,11 @@ from boltkit.server.stub import BoltStubService from pytest import fixture -# import logging -# from neo4j.debug import watch -# watch("neo4j") -# -# log = logging.getLogger("neo4j") +import logging +from neo4j.debug import watch +watch("neo4j") + +log = logging.getLogger("neo4j") class StubServer(): @@ -157,8 +157,8 @@ def driver_info(): """ Base class for test cases that integrate with a server. """ return { - "uri": "bolt://localhost:7687", - "bolt_routing_uri": "neo4j://localhost:7687", + "uri_bolt": "bolt://localhost:9001", + "uri_neo4j": "neo4j://localhost:9001", "user": "test", "password": "test", "auth_token": ("test", "test") diff --git a/tests/stub/scripts/v3/broken_router.script b/tests/stub/scripts/v3/broken_router.script index c3ce15ba4..7f3e72123 100644 --- a/tests/stub/scripts/v3/broken_router.script +++ b/tests/stub/scripts/v3/broken_router.script @@ -2,8 +2,9 @@ !: AUTO HELLO !: AUTO GOODBYE !: AUTO RESET +!: PORT 9001 -C: RUN "CALL dbms.cluster.routing.getRoutingTable($context)" {"context": {}} {} +C: RUN "CALL dbms.cluster.routing.getRoutingTable($context)" {"context": {"address": "localhost:9001"}} {} PULL_ALL S: FAILURE {"code": "Neo.DatabaseError.General.UnknownError", "message": "An unknown error occurred."} IGNORED diff --git a/tests/stub/scripts/v3/dbms_cluster_routing_get_routing_table_system.script b/tests/stub/scripts/v3/dbms_cluster_routing_get_routing_table_system.script index 8e4061aef..7aea9af85 100644 --- a/tests/stub/scripts/v3/dbms_cluster_routing_get_routing_table_system.script +++ b/tests/stub/scripts/v3/dbms_cluster_routing_get_routing_table_system.script @@ -4,7 +4,7 @@ C: HELLO {"user_agent": "test", "scheme": "basic", "principal": "test", "credentials": "test"} S: SUCCESS {"server": "Neo4j/3.5.0", "connection_id": "12345678-1234-1234-1234-123456789000"} -C: RUN "CALL dbms.cluster.routing.getRoutingTable($context)" {"context": {}} {"mode": "r"} +C: RUN "CALL dbms.cluster.routing.getRoutingTable($context)" {"context": {"address": "localhost:9001"}} {"mode": "r"} PULL_ALL S: SUCCESS {"fields": ["ttl", "servers"]} RECORD [1234, [{"role":"WRITE", "addresses":["127.0.0.1:9001"]}, {"role":"READ", "addresses":["127.0.0.1:9002", "127.0.0.1:9003"]}, {"role":"ROUTE", "addresses":["127.0.0.1:9001", "127.0.0.1:9002", "127.0.0.1:9003"]}]] diff --git a/tests/stub/scripts/v3/get_routing_table.script b/tests/stub/scripts/v3/get_routing_table.script index 4a8f04c0a..b3ec1fa0f 100644 --- a/tests/stub/scripts/v3/get_routing_table.script +++ b/tests/stub/scripts/v3/get_routing_table.script @@ -2,8 +2,9 @@ !: AUTO HELLO !: AUTO GOODBYE !: AUTO RESET +!: PORT 9001 -C: RUN "CALL dbms.cluster.routing.getRoutingTable($context)" {"context": {}} {"mode": "r"} +C: RUN "CALL dbms.cluster.routing.getRoutingTable($context)" {"context": {"address": "localhost:9001"}} {"mode": "r"} PULL_ALL S: SUCCESS {"fields": ["ttl", "servers"]} RECORD [9223372036854775807, [{"addresses": ["127.0.0.1:9001"],"role": "WRITE"}, {"addresses": ["127.0.0.1:9002"], "role": "READ"},{"addresses": ["127.0.0.1:9001", "127.0.0.1:9002"], "role": "ROUTE"}]] diff --git a/tests/stub/scripts/v3/get_routing_table_with_context.script b/tests/stub/scripts/v3/get_routing_table_with_context.script index a79a24c76..65e67bc68 100644 --- a/tests/stub/scripts/v3/get_routing_table_with_context.script +++ b/tests/stub/scripts/v3/get_routing_table_with_context.script @@ -2,8 +2,9 @@ !: AUTO HELLO !: AUTO GOODBYE !: AUTO RESET +!: PORT 9001 -C: RUN "CALL dbms.cluster.routing.getRoutingTable($context)" {"context": {"name": "molly", "age": "1"}} {"mode": "r"} +C: RUN "CALL dbms.cluster.routing.getRoutingTable($context)" {"context": {"name": "molly", "age": "1", "address": "localhost:9001"}} {"mode": "r"} PULL_ALL S: SUCCESS {"fields": ["ttl", "servers"]} RECORD [9223372036854775807, [{"addresses": ["127.0.0.1:9001"],"role": "WRITE"}, {"addresses": ["127.0.0.1:9002"], "role": "READ"},{"addresses": ["127.0.0.1:9001", "127.0.0.1:9002"], "role": "ROUTE"}]] diff --git a/tests/stub/scripts/v3/non_router.script b/tests/stub/scripts/v3/non_router.script index b6b58e2b2..f14da112f 100644 --- a/tests/stub/scripts/v3/non_router.script +++ b/tests/stub/scripts/v3/non_router.script @@ -1,8 +1,9 @@ !: BOLT 3 !: AUTO HELLO !: AUTO GOODBYE +!: PORT 9001 -C: RUN "CALL dbms.cluster.routing.getRoutingTable($context)" {"context": {}} {"mode":"r"} +C: RUN "CALL dbms.cluster.routing.getRoutingTable($context)" {"context": {"address": "localhost:9001"}} {"mode":"r"} PULL_ALL S: FAILURE {"code": "Neo.ClientError.Procedure.ProcedureNotFound", "message": "Not a router"} IGNORED diff --git a/tests/stub/scripts/v3/router.script b/tests/stub/scripts/v3/router.script index a0901bc4c..d5da9b0cb 100644 --- a/tests/stub/scripts/v3/router.script +++ b/tests/stub/scripts/v3/router.script @@ -4,7 +4,7 @@ !: AUTO RESET !: PORT 9001 -C: RUN "CALL dbms.cluster.routing.getRoutingTable($context)" {"context": {}} {"mode": "r"} +C: RUN "CALL dbms.cluster.routing.getRoutingTable($context)" {"context": {"address": "localhost:9001"}} {"mode": "r"} PULL_ALL S: SUCCESS {"fields": ["ttl", "servers"]} RECORD [300, [{"role":"ROUTE","addresses":["127.0.0.1:9001","127.0.0.1:9002","127.0.0.1:9003"]},{"role":"READ","addresses":["127.0.0.1:9004","127.0.0.1:9005"]},{"role":"WRITE","addresses":["127.0.0.1:9006"]}]] diff --git a/tests/stub/scripts/v3/router_no_readers.script b/tests/stub/scripts/v3/router_no_readers.script index 44794cca8..8bcf624ff 100644 --- a/tests/stub/scripts/v3/router_no_readers.script +++ b/tests/stub/scripts/v3/router_no_readers.script @@ -2,8 +2,9 @@ !: AUTO HELLO !: AUTO GOODBYE !: AUTO RESET +!: PORT 9001 -C: RUN "CALL dbms.cluster.routing.getRoutingTable($context)" {"context": {}} {"mode": "r"} +C: RUN "CALL dbms.cluster.routing.getRoutingTable($context)" {"context": {"address": "localhost:9001"}} {"mode": "r"} PULL_ALL S: SUCCESS {"fields": ["ttl", "servers"]} RECORD [300, [{"role":"ROUTE","addresses":["127.0.0.1:9001","127.0.0.1:9002","127.0.0.1:9003"]},{"role":"READ","addresses":[]},{"role":"WRITE","addresses":["127.0.0.1:9006"]}]] diff --git a/tests/stub/scripts/v3/router_no_routers.script b/tests/stub/scripts/v3/router_no_routers.script index 9bcb05c90..c8b37d6f2 100644 --- a/tests/stub/scripts/v3/router_no_routers.script +++ b/tests/stub/scripts/v3/router_no_routers.script @@ -2,8 +2,9 @@ !: AUTO HELLO !: AUTO GOODBYE !: AUTO RESET +!: PORT 9001 -C: RUN "CALL dbms.cluster.routing.getRoutingTable($context)" {"context": {}} {"mode": "r"} +C: RUN "CALL dbms.cluster.routing.getRoutingTable($context)" {"context": {"address": "localhost:9001"}} {"mode": "r"} PULL_ALL S: SUCCESS {"fields": ["ttl", "servers"]} RECORD [300, [{"role":"ROUTE","addresses":[]},{"role":"READ","addresses":["127.0.0.1:9004","127.0.0.1:9005"]},{"role":"WRITE","addresses":["127.0.0.1:9006"]}]] diff --git a/tests/stub/scripts/v3/router_no_writers.script b/tests/stub/scripts/v3/router_no_writers.script index 1b6fb694b..11b94d639 100644 --- a/tests/stub/scripts/v3/router_no_writers.script +++ b/tests/stub/scripts/v3/router_no_writers.script @@ -2,8 +2,9 @@ !: AUTO HELLO !: AUTO GOODBYE !: AUTO RESET +!: PORT 9001 -C: RUN "CALL dbms.cluster.routing.getRoutingTable($context)" {"context": {}} {"mode": "r"} +C: RUN "CALL dbms.cluster.routing.getRoutingTable($context)" {"context": {"address": "localhost:9001"}} {"mode": "r"} PULL_ALL S: SUCCESS {"fields": ["ttl", "servers"]} RECORD [300, [{"role":"ROUTE","addresses":["127.0.0.1:9001","127.0.0.1:9002","127.0.0.1:9003"]},{"role":"READ","addresses":["127.0.0.1:9004","127.0.0.1:9005"]},{"role":"WRITE","addresses":[]}]] diff --git a/tests/stub/scripts/v3/router_with_multiple_servers.script b/tests/stub/scripts/v3/router_with_multiple_servers.script index e338aa13c..34ac0f0f7 100644 --- a/tests/stub/scripts/v3/router_with_multiple_servers.script +++ b/tests/stub/scripts/v3/router_with_multiple_servers.script @@ -2,8 +2,9 @@ !: AUTO HELLO !: AUTO GOODBYE !: AUTO RESET +!: PORT 9001 -C: RUN "CALL dbms.cluster.routing.getRoutingTable($context)" {"context": {}} {"mode": "r"} +C: RUN "CALL dbms.cluster.routing.getRoutingTable($context)" {"context": {"address": "localhost:9001"}} {"mode": "r"} PULL_ALL S: SUCCESS {"fields": ["ttl", "servers"]} RECORD [300, [{"role":"ROUTE","addresses":["127.0.0.1:9001","127.0.0.1:9002"]},{"role":"READ","addresses":["127.0.0.1:9001","127.0.0.1:9003"]},{"role":"WRITE","addresses":["127.0.0.1:9004"]}]] diff --git a/tests/stub/scripts/v3/router_with_multiple_writers.script b/tests/stub/scripts/v3/router_with_multiple_writers.script index eda5069bb..c8e053727 100644 --- a/tests/stub/scripts/v3/router_with_multiple_writers.script +++ b/tests/stub/scripts/v3/router_with_multiple_writers.script @@ -2,8 +2,9 @@ !: AUTO HELLO !: AUTO GOODBYE !: AUTO RESET +!: PORT 9001 -C: RUN "CALL dbms.cluster.routing.getRoutingTable($context)" {"context": {}} {"mode": "r"} +C: RUN "CALL dbms.cluster.routing.getRoutingTable($context)" {"context": {"address": "localhost:9001"}} {"mode": "r"} PULL_ALL S: SUCCESS {"fields": ["ttl", "servers"]} RECORD [300, [{"role":"ROUTE","addresses":["127.0.0.1:9001","127.0.0.1:9002","127.0.0.1:9003"]},{"role":"READ","addresses":["127.0.0.1:9004","127.0.0.1:9005"]},{"role":"WRITE","addresses":["127.0.0.1:9006","127.0.0.1:9007"]}]] diff --git a/tests/stub/scripts/v3/rude_router.script b/tests/stub/scripts/v3/rude_router.script index 9c135e1c4..9fa163b86 100644 --- a/tests/stub/scripts/v3/rude_router.script +++ b/tests/stub/scripts/v3/rude_router.script @@ -2,8 +2,9 @@ !: AUTO HELLO !: AUTO GOODBYE !: AUTO RESET +!: PORT 9001 -C: RUN "CALL dbms.cluster.routing.getRoutingTable($context)" {"context": {}} {"mode": "r"} +C: RUN "CALL dbms.cluster.routing.getRoutingTable($context)" {"context": {"address": "localhost:9001"}} {"mode": "r"} PULL_ALL S: diff --git a/tests/stub/scripts/v3/silent_router.script b/tests/stub/scripts/v3/silent_router.script index 6fde3a0c8..a844c7d7f 100644 --- a/tests/stub/scripts/v3/silent_router.script +++ b/tests/stub/scripts/v3/silent_router.script @@ -2,8 +2,9 @@ !: AUTO HELLO !: AUTO GOODBYE !: AUTO RESET +!: PORT 9001 -C: RUN "CALL dbms.cluster.routing.getRoutingTable($context)" {"context": {}} {"mode": "r"} +C: RUN "CALL dbms.cluster.routing.getRoutingTable($context)" {"context": {"address": "localhost:9001"}} {"mode": "r"} PULL_ALL S: SUCCESS {"fields": ["ttl", "servers"]} SUCCESS {} diff --git a/tests/stub/scripts/v4x0/dbms_routing_get_routing_table_system_default.script b/tests/stub/scripts/v4x0/dbms_routing_get_routing_table_system_default.script index 0e22da905..05f9a9ab2 100644 --- a/tests/stub/scripts/v4x0/dbms_routing_get_routing_table_system_default.script +++ b/tests/stub/scripts/v4x0/dbms_routing_get_routing_table_system_default.script @@ -4,7 +4,7 @@ C: HELLO {"user_agent": "test", "scheme": "basic", "principal": "test", "credentials": "test"} S: SUCCESS {"server": "Neo4j/4.0.0", "connection_id": "12345678-1234-1234-1234-123456789000"} -C: RUN "CALL dbms.routing.getRoutingTable($context)" {"context": {}} {"mode": "r", "db": "system"} +C: RUN "CALL dbms.routing.getRoutingTable($context)" {"context": {"address": "localhost:9001"}} {"mode": "r", "db": "system"} PULL {"n": -1} S: SUCCESS {"fields": ["ttl", "servers"]} RECORD [1234, [{"role":"WRITE", "addresses":["127.0.0.1:9001"]}, {"role":"READ", "addresses":["127.0.0.1:9002", "127.0.0.1:9003"]}, {"role":"ROUTE", "addresses":["127.0.0.1:9001", "127.0.0.1:9002", "127.0.0.1:9003"]}]] diff --git a/tests/stub/scripts/v4x0/dbms_routing_get_routing_table_system_neo4j.script b/tests/stub/scripts/v4x0/dbms_routing_get_routing_table_system_neo4j.script index ba1369842..aed4b3c44 100644 --- a/tests/stub/scripts/v4x0/dbms_routing_get_routing_table_system_neo4j.script +++ b/tests/stub/scripts/v4x0/dbms_routing_get_routing_table_system_neo4j.script @@ -4,7 +4,7 @@ C: HELLO {"user_agent": "test", "scheme": "basic", "principal": "test", "credentials": "test"} S: SUCCESS {"server": "Neo4j/4.0.0", "connection_id": "12345678-1234-1234-1234-123456789000"} -C: RUN "CALL dbms.routing.getRoutingTable($context, $database)" {"context": {}, "database": "neo4j"} {"mode": "r", "db": "system"} +C: RUN "CALL dbms.routing.getRoutingTable($context, $database)" {"context": {"address": "localhost:9001"}, "database": "neo4j"} {"mode": "r", "db": "system"} PULL {"n": -1} S: SUCCESS {"fields": ["ttl", "servers"]} RECORD [1234, [{"role":"WRITE", "addresses":["127.0.0.1:9001"]}, {"role":"READ", "addresses":["127.0.0.1:9002", "127.0.0.1:9003"]}, {"role":"ROUTE", "addresses":["127.0.0.1:9001", "127.0.0.1:9002", "127.0.0.1:9003"]}]] diff --git a/tests/stub/scripts/v4x0/router.script b/tests/stub/scripts/v4x0/router.script index af0e8c197..46dfcb64b 100644 --- a/tests/stub/scripts/v4x0/router.script +++ b/tests/stub/scripts/v4x0/router.script @@ -4,7 +4,7 @@ !: AUTO RESET !: PORT 9001 -C: RUN "CALL dbms.routing.getRoutingTable($context)" {"context": {}} {"mode": "r", "db": "system"} +C: RUN "CALL dbms.routing.getRoutingTable($context)" {"context": {"address": "localhost:9001"}} {"mode": "r", "db": "system"} PULL {"n": -1} S: SUCCESS {"fields": ["ttl", "servers"]} RECORD [300, [{"role":"ROUTE","addresses":["127.0.0.1:9001","127.0.0.1:9002","127.0.0.1:9003"]},{"role":"READ","addresses":["127.0.0.1:9004","127.0.0.1:9005"]},{"role":"WRITE","addresses":["127.0.0.1:9006"]}]] diff --git a/tests/stub/scripts/v4x0/router_get_routing_table_with_context.script b/tests/stub/scripts/v4x0/router_get_routing_table_with_context.script index 15cbf13de..34c3d4cd1 100644 --- a/tests/stub/scripts/v4x0/router_get_routing_table_with_context.script +++ b/tests/stub/scripts/v4x0/router_get_routing_table_with_context.script @@ -4,7 +4,7 @@ !: AUTO RESET !: PORT 9001 -C: RUN "CALL dbms.routing.getRoutingTable($context)" {"context": {"name": "molly", "age": "1"}} {"mode": "r", "db": "system"} +C: RUN "CALL dbms.routing.getRoutingTable($context)" {"context": {"name": "molly", "age": "1", "address": "localhost:9001"}} {"mode": "r", "db": "system"} PULL {"n": -1} S: SUCCESS {"fields": ["ttl", "servers"]} RECORD [302, [{"role":"ROUTE", "addresses":["127.0.0.1:9001", "127.0.0.1:9002"]}, {"role":"READ", "addresses":["127.0.0.1:9002"]}, {"role":"WRITE", "addresses":["127.0.0.1:9001"]}]] diff --git a/tests/stub/scripts/v4x0/router_port_9001_one_read_port_9004_one_write_port_9006.script b/tests/stub/scripts/v4x0/router_port_9001_one_read_port_9004_one_write_port_9006.script index 0a4987ec0..cafc5742b 100644 --- a/tests/stub/scripts/v4x0/router_port_9001_one_read_port_9004_one_write_port_9006.script +++ b/tests/stub/scripts/v4x0/router_port_9001_one_read_port_9004_one_write_port_9006.script @@ -6,7 +6,7 @@ C: HELLO {"user_agent": "test", "scheme": "basic", "principal": "test", "credentials": "test"} S: SUCCESS {"server": "Neo4j/4.0.0", "connection_id": "123e4567-e89b-12d3-a456-426655440000"} -C: RUN "CALL dbms.routing.getRoutingTable($context)" {"context":{}} {"mode": "r", "db": "system"} +C: RUN "CALL dbms.routing.getRoutingTable($context)" {"context": {"address": "localhost:9001"}} {"mode": "r", "db": "system"} PULL {"n": -1} S: SUCCESS {"fields": ["ttl", "servers"]} RECORD [300, [{"role":"ROUTE", "addresses":["127.0.0.1:9001", "127.0.0.1:9002"]}, {"role":"READ", "addresses":["127.0.0.1:9004"]}, {"role":"WRITE", "addresses":["127.0.0.1:9006"]}]] diff --git a/tests/stub/scripts/v4x0/router_role_route_share_port_with_role_read_and_role_write.script b/tests/stub/scripts/v4x0/router_role_route_share_port_with_role_read_and_role_write.script index 11ba3e8cc..160afbee1 100644 --- a/tests/stub/scripts/v4x0/router_role_route_share_port_with_role_read_and_role_write.script +++ b/tests/stub/scripts/v4x0/router_role_route_share_port_with_role_read_and_role_write.script @@ -4,7 +4,7 @@ !: AUTO RESET !: PORT 9001 -C: RUN "CALL dbms.routing.getRoutingTable($context)" {"context": {}} {"mode": "r", "db": "system"} +C: RUN "CALL dbms.routing.getRoutingTable($context)" {"context": {"address": "localhost:9001"}} {"mode": "r", "db": "system"} PULL {"n": -1} S: SUCCESS {"fields": ["ttl", "servers"]} RECORD [302, [{"role":"ROUTE", "addresses":["127.0.0.1:9001", "127.0.0.1:9002"]}, {"role":"READ", "addresses":["127.0.0.1:9002"]}, {"role":"WRITE", "addresses":["127.0.0.1:9001"]}]] diff --git a/tests/stub/scripts/v4x0/router_with_no_role_read.script b/tests/stub/scripts/v4x0/router_with_no_role_read.script index 94e72d691..8039adddf 100644 --- a/tests/stub/scripts/v4x0/router_with_no_role_read.script +++ b/tests/stub/scripts/v4x0/router_with_no_role_read.script @@ -4,7 +4,7 @@ !: AUTO RESET !: PORT 9001 -C: RUN "CALL dbms.routing.getRoutingTable($context)" {"context": {}} {"mode": "r", "db": "system"} +C: RUN "CALL dbms.routing.getRoutingTable($context)" {"context": {"address": "localhost:9001"}} {"mode": "r", "db": "system"} PULL {"n": -1} S: SUCCESS {"fields": ["ttl", "servers"]} RECORD [304, [{"role":"ROUTE", "addresses":["127.0.0.1:9001", "127.0.0.1:9002", "127.0.0.1:9003"]}, {"role":"READ", "addresses":[]}, {"role":"WRITE", "addresses":["127.0.0.1:9006"]}]] diff --git a/tests/stub/scripts/v4x0/router_with_no_role_write.script b/tests/stub/scripts/v4x0/router_with_no_role_write.script index 2bf5db83c..e1f8cbc9a 100644 --- a/tests/stub/scripts/v4x0/router_with_no_role_write.script +++ b/tests/stub/scripts/v4x0/router_with_no_role_write.script @@ -4,7 +4,7 @@ !: AUTO RESET !: PORT 9001 -C: RUN "CALL dbms.routing.getRoutingTable($context)" {"context": {}} {"mode": "r", "db": "system"} +C: RUN "CALL dbms.routing.getRoutingTable($context)" {"context": {"address": "localhost:9001"}} {"mode": "r", "db": "system"} PULL {"n": -1} S: SUCCESS {"fields": ["ttl", "servers"]} RECORD [303, [{"role":"ROUTE", "addresses":["127.0.0.1:9001", "127.0.0.1:9002", "127.0.0.1:9003"]}, {"role":"READ", "addresses":["127.0.0.1:9004", "127.0.0.1:9005"]}, {"role":"WRITE", "addresses":[]}]] diff --git a/tests/stub/scripts/v4x0/routing_table_failure_not_a_router.script b/tests/stub/scripts/v4x0/routing_table_failure_not_a_router.script index eaf28300e..520eca40c 100644 --- a/tests/stub/scripts/v4x0/routing_table_failure_not_a_router.script +++ b/tests/stub/scripts/v4x0/routing_table_failure_not_a_router.script @@ -2,7 +2,7 @@ !: AUTO HELLO !: AUTO GOODBYE -C: RUN "CALL dbms.routing.getRoutingTable($context)" {"context": {}} {"mode": "r", "db": "system"} +C: RUN "CALL dbms.routing.getRoutingTable($context)" {"context": {"address": "localhost:9001"}} {"mode": "r", "db": "system"} PULL {"n": -1} S: FAILURE {"code": "Neo.ClientError.Procedure.ProcedureNotFound", "message": "Not a router"} IGNORED diff --git a/tests/stub/scripts/v4x0/routing_table_silent_router.script b/tests/stub/scripts/v4x0/routing_table_silent_router.script index 439a086da..ba0697646 100644 --- a/tests/stub/scripts/v4x0/routing_table_silent_router.script +++ b/tests/stub/scripts/v4x0/routing_table_silent_router.script @@ -3,7 +3,7 @@ !: AUTO GOODBYE !: AUTO RESET -C: RUN "CALL dbms.routing.getRoutingTable($context)" {"context": {}} {"mode": "r", "db": "system"} +C: RUN "CALL dbms.routing.getRoutingTable($context)" {"context": {"address": "localhost:9001"}} {"mode": "r", "db": "system"} PULL {"n": -1} S: SUCCESS {"fields": ["ttl", "servers"]} SUCCESS {} diff --git a/tests/stub/test_accesslevel.py b/tests/stub/test_accesslevel.py index 845f2bb85..b10164ea7 100644 --- a/tests/stub/test_accesslevel.py +++ b/tests/stub/test_accesslevel.py @@ -42,8 +42,7 @@ def test_read_transaction(driver_info, test_scripts): # python -m pytest tests/stub/test_accesslevel.py -s -v -k test_read_transaction with StubCluster(*test_scripts): - uri = "neo4j://localhost:9001" - with GraphDatabase.driver(uri, auth=driver_info["auth_token"]) as driver: + with GraphDatabase.driver(driver_info["uri_neo4j"], auth=driver_info["auth_token"]) as driver: with driver.session(fetch_size=-1) as session: def unit_of_work(tx): @@ -66,8 +65,7 @@ def unit_of_work(tx): def test_write_transaction(driver_info, test_scripts): # python -m pytest tests/stub/test_accesslevel.py -s -v -k test_write_transaction with StubCluster(*test_scripts): - uri = "neo4j://localhost:9001" - with GraphDatabase.driver(uri, auth=driver_info["auth_token"]) as driver: + with GraphDatabase.driver(driver_info["uri_neo4j"], auth=driver_info["auth_token"]) as driver: with driver.session(fetch_size=-1) as session: def unit_of_work(tx): @@ -91,8 +89,7 @@ def unit_of_work(tx): def test_read_transaction_with_error(driver_info, test_scripts): # python -m pytest tests/stub/test_accesslevel.py -s -v -k test_read_transaction_with_error with StubCluster(*test_scripts): - uri = "neo4j://localhost:9001" - with GraphDatabase.driver(uri, auth=driver_info["auth_token"]) as driver: + with GraphDatabase.driver(driver_info["uri_neo4j"], auth=driver_info["auth_token"]) as driver: with driver.session(fetch_size=-1) as session: def unit_of_work(tx): @@ -113,8 +110,7 @@ def unit_of_work(tx): def test_write_transaction_with_error(driver_info, test_scripts): # python -m pytest tests/stub/test_accesslevel.py -s -v -k test_write_transaction_with_error with StubCluster(*test_scripts): - uri = "neo4j://localhost:9001" - with GraphDatabase.driver(uri, auth=driver_info["auth_token"]) as driver: + with GraphDatabase.driver(driver_info["uri_neo4j"], auth=driver_info["auth_token"]) as driver: with driver.session(fetch_size=-1) as session: def unit_of_work(tx): @@ -134,8 +130,7 @@ def unit_of_work(tx): def test_two_subsequent_read_transactions(driver_info, test_scripts): # python -m pytest tests/stub/test_accesslevel.py -s -v -k test_two_subsequent_read_transactions with StubCluster(*test_scripts): - uri = "neo4j://localhost:9001" - with GraphDatabase.driver(uri, auth=driver_info["auth_token"]) as driver: + with GraphDatabase.driver(driver_info["uri_neo4j"], auth=driver_info["auth_token"]) as driver: with driver.session(fetch_size=-1) as session: def unit_of_work(tx): @@ -160,8 +155,7 @@ def unit_of_work(tx): def test_two_subsequent_write_transactions(driver_info, test_scripts): # python -m pytest tests/stub/test_accesslevel.py -s -v -k test_two_subsequent_write_transactions with StubCluster(*test_scripts): - uri = "neo4j://localhost:9001" - with GraphDatabase.driver(uri, auth=driver_info["auth_token"]) as driver: + with GraphDatabase.driver(driver_info["uri_neo4j"], auth=driver_info["auth_token"]) as driver: with driver.session(fetch_size=-1) as session: def unit_of_work(tx): @@ -187,8 +181,7 @@ def unit_of_work(tx): def test_read_tx_then_write_tx(driver_info, test_scripts): # python -m pytest tests/stub/test_accesslevel.py -s -v -k test_read_tx_then_write_tx with StubCluster(*test_scripts): - uri = "neo4j://localhost:9001" - with GraphDatabase.driver(uri, auth=driver_info["auth_token"]) as driver: + with GraphDatabase.driver(driver_info["uri_neo4j"], auth=driver_info["auth_token"]) as driver: with driver.session(fetch_size=-1) as session: def unit_of_work_1(tx): @@ -221,8 +214,7 @@ def unit_of_work_2(tx): def test_write_tx_then_read_tx(driver_info, test_scripts): # python -m pytest tests/stub/test_accesslevel.py -s -v -k test_write_tx_then_read_tx with StubCluster(*test_scripts): - uri = "neo4j://localhost:9001" - with GraphDatabase.driver(uri, auth=driver_info["auth_token"]) as driver: + with GraphDatabase.driver(driver_info["uri_neo4j"], auth=driver_info["auth_token"]) as driver: with driver.session(fetch_size=-1) as session: def unit_of_work_1(tx): @@ -254,8 +246,7 @@ def unit_of_work_2(tx): def test_no_retry_read_on_user_canceled_tx(driver_info, test_scripts): # python -m pytest tests/stub/test_accesslevel.py -s -v -k test_no_retry_read_on_user_canceled_tx with StubCluster(*test_scripts): - uri = "neo4j://127.0.0.1:9001" - with GraphDatabase.driver(uri, auth=driver_info["auth_token"]) as driver: + with GraphDatabase.driver(driver_info["uri_neo4j"], auth=driver_info["auth_token"]) as driver: with driver.session(fetch_size=-1) as session: def unit_of_work(tx): tx.run("RETURN 1") @@ -275,8 +266,7 @@ def unit_of_work(tx): def test_no_retry_write_on_user_canceled_tx(driver_info, test_scripts): # python -m pytest tests/stub/test_accesslevel.py -s -v -k test_no_retry_write_on_user_canceled_tx with StubCluster(*test_scripts): - uri = "neo4j://127.0.0.1:9001" - with GraphDatabase.driver(uri, auth=driver_info["auth_token"]) as driver: + with GraphDatabase.driver(driver_info["uri_neo4j"], auth=driver_info["auth_token"]) as driver: with driver.session(fetch_size=-1) as session: def unit_of_work(tx): tx.run("RETURN 1") diff --git a/tests/stub/test_multi_database.py b/tests/stub/test_multi_database.py index 776798515..efa4570d4 100644 --- a/tests/stub/test_multi_database.py +++ b/tests/stub/test_multi_database.py @@ -48,7 +48,7 @@ def test_dbms_cluster_routing_get_routing_table(driver_info, test_script, test_d } with StubCluster(test_script): - uri = "neo4j://127.0.0.1:9001" + uri = "neo4j://localhost:9001" driver = GraphDatabase.driver(uri, auth=driver_info["auth_token"], **test_config) assert isinstance(driver, Neo4jDriver) driver.close() diff --git a/tests/stub/test_routingdriver.py b/tests/stub/test_routingdriver.py index 2e77b2314..370286b92 100644 --- a/tests/stub/test_routingdriver.py +++ b/tests/stub/test_routingdriver.py @@ -58,8 +58,7 @@ def test_neo4j_uri_scheme_constructs_neo4j_driver(driver_info, test_script): # python -m pytest tests/stub/test_routingdriver.py -s -v -k test_neo4j_uri_scheme_constructs_neo4j_driver with StubCluster(test_script): - uri = "neo4j://127.0.0.1:9001" - with GraphDatabase.driver(uri, auth=driver_info["auth_token"]) as driver: + with GraphDatabase.driver(driver_info["uri_neo4j"], auth=driver_info["auth_token"]) as driver: assert isinstance(driver, Neo4jDriver) @@ -74,7 +73,7 @@ def test_neo4j_uri_scheme_constructs_neo4j_driver(driver_info, test_script): def test_neo4j_uri_scheme_self_signed_certificate_constructs_neo4j_driver(driver_info, test_script): # python -m pytest tests/stub/test_routingdriver.py -s -v -k test_neo4j_uri_scheme_self_signed_certificate_constructs_neo4j_driver with StubCluster(test_script): - uri = "neo4j+ssc://127.0.0.1:9001" + uri = "neo4j+ssc://localhost:9001" test_config = { "user_agent": "test", @@ -105,7 +104,7 @@ def test_neo4j_uri_scheme_self_signed_certificate_constructs_neo4j_driver(driver def test_neo4j_uri_scheme_secure_constructs_neo4j_driver(driver_info, test_script): # python -m pytest tests/stub/test_routingdriver.py -s -v -k test_neo4j_uri_scheme_secure_constructs_neo4j_driver with StubCluster(test_script): - uri = "neo4j+s://127.0.0.1:9001" + uri = "neo4j+s://localhost:9001" test_config = { "user_agent": "test", @@ -128,8 +127,8 @@ def test_neo4j_uri_scheme_secure_constructs_neo4j_driver(driver_info, test_scrip @pytest.mark.parametrize( "test_uri", [ - "neo4j+ssc://127.0.0.1:9001", - "neo4j+s://127.0.0.1:9001", + "neo4j+ssc://localhost:9001", + "neo4j+s://localhost:9001", ] ) @pytest.mark.parametrize( @@ -160,9 +159,8 @@ def test_neo4j_uri_scheme_secure_constructs_neo4j_driver_config_error(driver_inf ) def test_neo4j_driver_verify_connectivity(driver_info, test_script): # python -m pytest tests/stub/test_routingdriver.py -s -v -k test_neo4j_driver_verify_connectivity - uri = "neo4j://127.0.0.1:9001" with StubCluster(test_script): - driver = GraphDatabase.driver(uri, auth=driver_info["auth_token"], user_agent="test") + driver = GraphDatabase.driver(driver_info["uri_neo4j"], auth=driver_info["auth_token"], user_agent="test") assert isinstance(driver, Neo4jDriver) with StubCluster(test_script): @@ -180,9 +178,8 @@ def test_neo4j_driver_verify_connectivity(driver_info, test_script): ) def test_neo4j_driver_verify_connectivity_server_down(driver_info, test_script): # python -m pytest tests/stub/test_routingdriver.py -s -v -k test_neo4j_driver_verify_connectivity_server_down - uri = "neo4j://127.0.0.1:9001" with StubCluster(test_script): - driver = GraphDatabase.driver(uri, auth=driver_info["auth_token"], user_agent="test") + driver = GraphDatabase.driver(driver_info["uri_neo4j"], auth=driver_info["auth_token"], user_agent="test") assert isinstance(driver, Neo4jDriver) with pytest.raises(ServiceUnavailable): @@ -201,9 +198,8 @@ def test_neo4j_driver_verify_connectivity_server_down(driver_info, test_script): def test_cannot_discover_servers_on_non_router(driver_info, test_script): # python -m pytest tests/stub/test_routingdriver.py -s -v -k test_cannot_discover_servers_on_non_router with StubCluster(test_script): - uri = "neo4j://127.0.0.1:9001" with pytest.raises(ServiceUnavailable): - with GraphDatabase.driver(uri, auth=driver_info["auth_token"]): + with GraphDatabase.driver(driver_info["uri_neo4j"], auth=driver_info["auth_token"]): pass @@ -217,9 +213,8 @@ def test_cannot_discover_servers_on_non_router(driver_info, test_script): def test_cannot_discover_servers_on_silent_router(driver_info, test_script): # python -m pytest tests/stub/test_routingdriver.py -s -v -k test_cannot_discover_servers_on_silent_router with StubCluster(test_script): - uri = "neo4j://127.0.0.1:9001" with pytest.raises(BoltRoutingError): - with GraphDatabase.driver(uri, auth=driver_info["auth_token"]): + with GraphDatabase.driver(driver_info["uri_neo4j"], auth=driver_info["auth_token"]): pass @@ -233,8 +228,7 @@ def test_cannot_discover_servers_on_silent_router(driver_info, test_script): def test_should_discover_servers_on_driver_construction(driver_info, test_script): # python -m pytest tests/stub/test_routingdriver.py -s -v -k test_should_discover_servers_on_driver_construction with StubCluster(test_script): - uri = "neo4j://127.0.0.1:9001" - with GraphDatabase.driver(uri, auth=driver_info["auth_token"]) as driver: + with GraphDatabase.driver(driver_info["uri_neo4j"], auth=driver_info["auth_token"]) as driver: table = driver._pool.routing_tables[DEFAULT_DATABASE] assert table.routers == {('127.0.0.1', 9001), ('127.0.0.1', 9002), ('127.0.0.1', 9003)} @@ -252,8 +246,7 @@ def test_should_discover_servers_on_driver_construction(driver_info, test_script def test_should_be_able_to_read(driver_info, test_scripts): # python -m pytest tests/stub/test_routingdriver.py -s -v -k test_should_be_able_to_read with StubCluster(*test_scripts): - uri = "neo4j://127.0.0.1:9001" - with GraphDatabase.driver(uri, auth=driver_info["auth_token"]) as driver: + with GraphDatabase.driver(driver_info["uri_neo4j"], auth=driver_info["auth_token"]) as driver: with driver.session(default_access_mode=READ_ACCESS, fetch_size=-1) as session: result = session.run("RETURN $x", {"x": 1}) for record in result: @@ -271,8 +264,7 @@ def test_should_be_able_to_read(driver_info, test_scripts): def test_should_be_able_to_write(driver_info, test_scripts): # python -m pytest tests/stub/test_routingdriver.py -s -v -k test_should_be_able_to_write with StubCluster(*test_scripts): - uri = "neo4j://127.0.0.1:9001" - with GraphDatabase.driver(uri, auth=driver_info["auth_token"]) as driver: + with GraphDatabase.driver(driver_info["uri_neo4j"], auth=driver_info["auth_token"]) as driver: with driver.session(default_access_mode=WRITE_ACCESS, fetch_size=-1) as session: result = session.run("CREATE (a $x)", {"x": {"name": "Alice"}}) assert not list(result) @@ -289,8 +281,7 @@ def test_should_be_able_to_write(driver_info, test_scripts): def test_should_be_able_to_write_as_default(driver_info, test_scripts): # python -m pytest tests/stub/test_routingdriver.py -s -v -k test_should_be_able_to_write_as_default with StubCluster(*test_scripts): - uri = "neo4j://127.0.0.1:9001" - with GraphDatabase.driver(uri, auth=driver_info["auth_token"]) as driver: + with GraphDatabase.driver(driver_info["uri_neo4j"], auth=driver_info["auth_token"]) as driver: with driver.session(fetch_size=-1) as session: result = session.run("CREATE (a $x)", {"x": {"name": "Alice"}}) assert not list(result) @@ -307,8 +298,7 @@ def test_should_be_able_to_write_as_default(driver_info, test_scripts): def test_routing_disconnect_on_run(driver_info, test_scripts): # python -m pytest tests/stub/test_routingdriver.py -s -v -k test_routing_disconnect_on_run with StubCluster(*test_scripts): - uri = "neo4j://127.0.0.1:9001" - with GraphDatabase.driver(uri, auth=driver_info["auth_token"]) as driver: + with GraphDatabase.driver(driver_info["uri_neo4j"], auth=driver_info["auth_token"]) as driver: with pytest.raises(SessionExpired): with driver.session(default_access_mode=READ_ACCESS, fetch_size=-1) as session: session.run("RETURN $x", {"x": 1}).consume() @@ -324,8 +314,7 @@ def test_routing_disconnect_on_run(driver_info, test_scripts): def test_routing_disconnect_on_pull_all(driver_info, test_scripts): # python -m pytest tests/stub/test_routingdriver.py -s -v -k test_routing_disconnect_on_pull_all with StubCluster(*test_scripts): - uri = "neo4j://127.0.0.1:9001" - with GraphDatabase.driver(uri, auth=driver_info["auth_token"]) as driver: + with GraphDatabase.driver(driver_info["uri_neo4j"], auth=driver_info["auth_token"]) as driver: with pytest.raises(SessionExpired): with driver.session(default_access_mode=READ_ACCESS, fetch_size=-1) as session: session.run("RETURN $x", {"x": 1}).consume() @@ -341,8 +330,7 @@ def test_routing_disconnect_on_pull_all(driver_info, test_scripts): def test_should_disconnect_after_fetching_autocommit_result(driver_info, test_scripts): # python -m pytest tests/stub/test_routingdriver.py -s -v -k test_should_disconnect_after_fetching_autocommit_result with StubCluster(*test_scripts): - uri = "neo4j://127.0.0.1:9001" - with GraphDatabase.driver(uri, auth=driver_info["auth_token"]) as driver: + with GraphDatabase.driver(driver_info["uri_neo4j"], auth=driver_info["auth_token"]) as driver: with driver.session(default_access_mode=READ_ACCESS, fetch_size=-1) as session: result = session.run("RETURN $x", {"x": 1}) assert session._connection is not None @@ -360,8 +348,7 @@ def test_should_disconnect_after_fetching_autocommit_result(driver_info, test_sc def test_should_disconnect_after_explicit_commit(driver_info, test_scripts, test_run_args): # python -m pytest tests/stub/test_routingdriver.py -s -v -k test_should_disconnect_after_explicit_commit with StubCluster(*test_scripts): - uri = "neo4j://127.0.0.1:9001" - with GraphDatabase.driver(uri, auth=driver_info["auth_token"]) as driver: + with GraphDatabase.driver(driver_info["uri_neo4j"], auth=driver_info["auth_token"]) as driver: with driver.session(default_access_mode=READ_ACCESS, fetch_size=-1) as session: with session.begin_transaction() as tx: result = tx.run(*test_run_args) @@ -385,8 +372,7 @@ def test_should_disconnect_after_explicit_commit(driver_info, test_scripts, test def test_default_access_mode_defined_at_session_level(driver_info, test_scripts, test_run_args): # python -m pytest tests/stub/test_routingdriver.py -s -v -k test_default_access_mode_defined_at_session_level with StubCluster(*test_scripts): - uri = "neo4j://127.0.0.1:9001" - with GraphDatabase.driver(uri, auth=driver_info["auth_token"]) as driver: + with GraphDatabase.driver(driver_info["uri_neo4j"], auth=driver_info["auth_token"]) as driver: with driver.session(default_access_mode=READ_ACCESS, fetch_size=-1) as session: with session.begin_transaction() as tx: result = tx.run(*test_run_args) @@ -410,8 +396,7 @@ def test_default_access_mode_defined_at_session_level(driver_info, test_scripts, def test_should_reconnect_for_new_query(driver_info, test_scripts, test_run_args): # python -m pytest tests/stub/test_routingdriver.py -s -v -k test_should_reconnect_for_new_query with StubCluster(*test_scripts): - uri = "neo4j://127.0.0.1:9001" - with GraphDatabase.driver(uri, auth=driver_info["auth_token"]) as driver: + with GraphDatabase.driver(driver_info["uri_neo4j"], auth=driver_info["auth_token"]) as driver: with driver.session(default_access_mode=READ_ACCESS, fetch_size=-1) as session: result_1 = session.run(*test_run_args) assert session._connection is not None @@ -433,8 +418,7 @@ def test_should_reconnect_for_new_query(driver_info, test_scripts, test_run_args def test_should_retain_connection_if_fetching_multiple_results(driver_info, test_scripts, test_run_args): # python -m pytest tests/stub/test_routingdriver.py -s -v -k test_should_retain_connection_if_fetching_multiple_results with StubCluster(*test_scripts): - uri = "neo4j://127.0.0.1:9001" - with GraphDatabase.driver(uri, auth=driver_info["auth_token"]) as driver: + with GraphDatabase.driver(driver_info["uri_neo4j"], auth=driver_info["auth_token"]) as driver: with driver.session(default_access_mode=READ_ACCESS, fetch_size=-1) as session: result_1 = session.run(*test_run_args) result_2 = session.run(*test_run_args) @@ -455,8 +439,7 @@ def test_should_retain_connection_if_fetching_multiple_results(driver_info, test def test_two_sessions_can_share_a_connection(driver_info, test_scripts, test_run_args): # python -m pytest tests/stub/test_routingdriver.py -s -v -k test_two_sessions_can_share_a_connection with StubCluster(*test_scripts): - uri = "neo4j://127.0.0.1:9001" - with GraphDatabase.driver(uri, auth=driver_info["auth_token"]) as driver: + with GraphDatabase.driver(driver_info["uri_neo4j"], auth=driver_info["auth_token"]) as driver: session_1 = driver.session(default_access_mode=READ_ACCESS, fetch_size=-1) session_2 = driver.session(default_access_mode=READ_ACCESS, fetch_size=-1) @@ -490,8 +473,7 @@ def test_two_sessions_can_share_a_connection(driver_info, test_scripts, test_run def test_should_call_get_routing_table_procedure(driver_info, test_scripts, test_run_args): # python -m pytest tests/stub/test_routingdriver.py -s -v -k test_should_call_get_routing_table_procedure with StubCluster(*test_scripts): - uri = "neo4j://127.0.0.1:9001" - with GraphDatabase.driver(uri, auth=driver_info["auth_token"]) as driver: + with GraphDatabase.driver(driver_info["uri_neo4j"], auth=driver_info["auth_token"]) as driver: with driver.session(default_access_mode=READ_ACCESS, fetch_size=-1) as session: result = session.run(*test_run_args) for record in result: @@ -509,7 +491,7 @@ def test_should_call_get_routing_table_procedure(driver_info, test_scripts, test def test_should_call_get_routing_table_with_context(driver_info, test_scripts, test_run_args): # python -m pytest tests/stub/test_routingdriver.py -s -v -k test_should_call_get_routing_table_with_context with StubCluster(*test_scripts): - uri = "neo4j://127.0.0.1:9001/?name=molly&age=1" + uri = "neo4j://localhost:9001/?name=molly&age=1" with GraphDatabase.driver(uri, auth=driver_info["auth_token"]) as driver: with driver.session(default_access_mode=READ_ACCESS, fetch_size=-1) as session: result = session.run(*test_run_args) @@ -528,8 +510,7 @@ def test_should_call_get_routing_table_with_context(driver_info, test_scripts, t def test_should_serve_read_when_missing_writer(driver_info, test_scripts, test_run_args): # python -m pytest tests/stub/test_routingdriver.py -s -v -k test_should_serve_read_when_missing_writer with StubCluster(*test_scripts): - uri = "neo4j://127.0.0.1:9001" - with GraphDatabase.driver(uri, auth=driver_info["auth_token"]) as driver: + with GraphDatabase.driver(driver_info["uri_neo4j"], auth=driver_info["auth_token"]) as driver: with driver.session(default_access_mode=READ_ACCESS, fetch_size=-1) as session: result = session.run(*test_run_args) for record in result: @@ -547,9 +528,8 @@ def test_should_serve_read_when_missing_writer(driver_info, test_scripts, test_r def test_should_error_when_missing_reader(driver_info, test_script): # python -m pytest tests/stub/test_routingdriver.py -s -v -k test_should_error_when_missing_reader with StubCluster(test_script): - uri = "neo4j://127.0.0.1:9001" with pytest.raises(BoltRoutingError): - GraphDatabase.driver(uri, auth=driver_info["auth_token"]) + GraphDatabase.driver(driver_info["uri_neo4j"], auth=driver_info["auth_token"]) @pytest.mark.parametrize( @@ -562,8 +542,7 @@ def test_should_error_when_missing_reader(driver_info, test_script): def test_forgets_address_on_not_a_leader_error(driver_info, test_scripts, test_run_args): # python -m pytest tests/stub/test_routingdriver.py -s -v -k test_forgets_address_on_not_a_leader_error with StubCluster(*test_scripts): - uri = "neo4j://127.0.0.1:9001" - with GraphDatabase.driver(uri, auth=driver_info["auth_token"]) as driver: + with GraphDatabase.driver(driver_info["uri_neo4j"], auth=driver_info["auth_token"]) as driver: with driver.session(default_access_mode=WRITE_ACCESS, fetch_size=-1) as session: with pytest.raises(ClientError): _ = session.run(*test_run_args) @@ -589,8 +568,7 @@ def test_forgets_address_on_not_a_leader_error(driver_info, test_scripts, test_r def test_forgets_address_on_forbidden_on_read_only_database_error(driver_info, test_scripts, test_run_args): # python -m pytest tests/stub/test_routingdriver.py -s -v -k test_forgets_address_on_forbidden_on_read_only_database_error with StubCluster(*test_scripts): - uri = "neo4j://127.0.0.1:9001" - with GraphDatabase.driver(uri, auth=driver_info["auth_token"]) as driver: + with GraphDatabase.driver(driver_info["uri_neo4j"], auth=driver_info["auth_token"]) as driver: with driver.session(default_access_mode=WRITE_ACCESS, fetch_size=-1) as session: with pytest.raises(ClientError): _ = session.run(*test_run_args) @@ -616,8 +594,7 @@ def test_forgets_address_on_forbidden_on_read_only_database_error(driver_info, t def test_forgets_address_on_service_unavailable_error(driver_info, test_scripts, test_run_args): # python -m pytest tests/stub/test_routingdriver.py -s -v -k test_forgets_address_on_service_unavailable_error with StubCluster(*test_scripts): - uri = "neo4j://127.0.0.1:9001" - with GraphDatabase.driver(uri, auth=driver_info["auth_token"]) as driver: + with GraphDatabase.driver(driver_info["uri_neo4j"], auth=driver_info["auth_token"]) as driver: with driver.session(default_access_mode=READ_ACCESS, fetch_size=-1) as session: pool = driver._pool @@ -651,8 +628,7 @@ def test_forgets_address_on_service_unavailable_error(driver_info, test_scripts, def test_forgets_address_on_database_unavailable_error(driver_info, test_scripts, test_run_args): # python -m pytest tests/stub/test_routingdriver.py -s -v -k test_forgets_address_on_database_unavailable_error with StubCluster(*test_scripts): - uri = "neo4j://127.0.0.1:9001" - with GraphDatabase.driver(uri, auth=driver_info["auth_token"]) as driver: + with GraphDatabase.driver(driver_info["uri_neo4j"], auth=driver_info["auth_token"]) as driver: with driver.session(default_access_mode=READ_ACCESS, fetch_size=-1) as session: pool = driver._pool From 4a2469aac57702b1906e1998c0a09fccfc441994 Mon Sep 17 00:00:00 2001 From: martin bendsoe Date: Mon, 25 May 2020 10:51:14 +0200 Subject: [PATCH 3/4] fixed integration tests for the changes --- neo4j/io/__init__.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/neo4j/io/__init__.py b/neo4j/io/__init__.py index 8117393bc..425e6abc6 100644 --- a/neo4j/io/__init__.py +++ b/neo4j/io/__init__.py @@ -545,11 +545,11 @@ def __init__(self, opener, pool_config, workspace_config, routing_context, addre self.init_address = addresses[0] self.routing_tables = {workspace_config.database: RoutingTable(database=workspace_config.database, routers=addresses)} self.routing_context = routing_context - if "address" in routing_context: - raise ConfigurationError("The key 'address' is reserved for internal routing context.") + if self.routing_context is None: + self.routing_context = {} + elif "address" in self.routing_context: + raise ConfigurationError("The key 'address' is reserved for routing context.") self.routing_context["address"] = str(self.init_address) - log.debug("routing_context {}".format(self.routing_context)) - # self.missing_writer = False self.refresh_lock = Lock() def __repr__(self): From 4584c51732a2650514d1e560d60add28baf56e64 Mon Sep 17 00:00:00 2001 From: martin bendsoe Date: Mon, 25 May 2020 11:00:01 +0200 Subject: [PATCH 4/4] fixup --- tests/stub/conftest.py | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/tests/stub/conftest.py b/tests/stub/conftest.py index 7e564af96..44a891db3 100644 --- a/tests/stub/conftest.py +++ b/tests/stub/conftest.py @@ -28,14 +28,14 @@ from boltkit.server.stub import BoltStubService from pytest import fixture -import logging -from neo4j.debug import watch -watch("neo4j") - -log = logging.getLogger("neo4j") +# import logging +# from neo4j.debug import watch +# watch("neo4j") +# +# log = logging.getLogger("neo4j") -class StubServer(): +class StubServer: def __init__(self, port, script): self.port = port @@ -62,7 +62,7 @@ def kill(self): self._process.kill() -class StubCluster(object): +class StubCluster: def __init__(self, servers): self.servers = {port: StubServer(port, script) for port, script in dict(servers).items()} @@ -99,7 +99,7 @@ def run(self): check_call(["python", "-m", "boltkit.legacy.stub", "-v", str(self.port), self.script]) -class LegacyStubCluster(object): +class LegacyStubCluster: def __init__(self, servers): self.servers = {port: LegacyStubServer(port, script) for port, script in dict(servers).items()}