Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 16 additions & 1 deletion neo4j/io/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -531,12 +531,25 @@ 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: <NEO4J POOL> 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
# self.missing_writer = False
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)
self.refresh_lock = Lock()

def __repr__(self):
Expand Down Expand Up @@ -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
Expand Down
10 changes: 5 additions & 5 deletions tests/stub/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
# log = logging.getLogger("neo4j")


class StubServer():
class StubServer:

def __init__(self, port, script):
self.port = port
Expand All @@ -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()}
Expand Down Expand Up @@ -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()}
Expand Down Expand Up @@ -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")
Expand Down
3 changes: 2 additions & 1 deletion tests/stub/scripts/v3/broken_router.script
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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"]}]]
Expand Down
3 changes: 2 additions & 1 deletion tests/stub/scripts/v3/get_routing_table.script
Original file line number Diff line number Diff line change
Expand Up @@ -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"}]]
Expand Down
3 changes: 2 additions & 1 deletion tests/stub/scripts/v3/get_routing_table_with_context.script
Original file line number Diff line number Diff line change
Expand Up @@ -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"}]]
Expand Down
3 changes: 2 additions & 1 deletion tests/stub/scripts/v3/non_router.script
Original file line number Diff line number Diff line change
@@ -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
Expand Down
2 changes: 1 addition & 1 deletion tests/stub/scripts/v3/router.script
Original file line number Diff line number Diff line change
Expand Up @@ -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"]}]]
Expand Down
3 changes: 2 additions & 1 deletion tests/stub/scripts/v3/router_no_readers.script
Original file line number Diff line number Diff line change
Expand Up @@ -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"]}]]
Expand Down
3 changes: 2 additions & 1 deletion tests/stub/scripts/v3/router_no_routers.script
Original file line number Diff line number Diff line change
Expand Up @@ -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"]}]]
Expand Down
3 changes: 2 additions & 1 deletion tests/stub/scripts/v3/router_no_writers.script
Original file line number Diff line number Diff line change
Expand Up @@ -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":[]}]]
Expand Down
3 changes: 2 additions & 1 deletion tests/stub/scripts/v3/router_with_multiple_servers.script
Original file line number Diff line number Diff line change
Expand Up @@ -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"]}]]
Expand Down
3 changes: 2 additions & 1 deletion tests/stub/scripts/v3/router_with_multiple_writers.script
Original file line number Diff line number Diff line change
Expand Up @@ -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"]}]]
Expand Down
3 changes: 2 additions & 1 deletion tests/stub/scripts/v3/rude_router.script
Original file line number Diff line number Diff line change
Expand Up @@ -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: <EXIT>

3 changes: 2 additions & 1 deletion tests/stub/scripts/v3/silent_router.script
Original file line number Diff line number Diff line change
Expand Up @@ -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 {}
Original file line number Diff line number Diff line change
Expand Up @@ -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"]}]]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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"]}]]
Expand Down
2 changes: 1 addition & 1 deletion tests/stub/scripts/v4x0/router.script
Original file line number Diff line number Diff line change
Expand Up @@ -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"]}]]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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"]}]]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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"]}]]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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"]}]]
Expand Down
2 changes: 1 addition & 1 deletion tests/stub/scripts/v4x0/router_with_no_role_read.script
Original file line number Diff line number Diff line change
Expand Up @@ -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"]}]]
Expand Down
2 changes: 1 addition & 1 deletion tests/stub/scripts/v4x0/router_with_no_role_write.script
Original file line number Diff line number Diff line change
Expand Up @@ -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":[]}]]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion tests/stub/scripts/v4x0/routing_table_silent_router.script
Original file line number Diff line number Diff line change
Expand Up @@ -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 {}
Loading