Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Test transaction config for execute_query #607

Merged
merged 3 commits into from
Dec 5, 2023
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
8 changes: 5 additions & 3 deletions nutkit/frontend/driver.py
Original file line number Diff line number Diff line change
Expand Up @@ -101,13 +101,15 @@ def send_and_receive(self, req, timeout=None, hooks=None, *,
return self.receive(timeout=timeout, hooks=hooks,
allow_resolution=allow_resolution)

def execute_query(self, cypher, params=None,
routing=None, database=None,
impersonated_user=None, bookmark_manager=...):
def execute_query(self, cypher, *, params=None, routing=None,
robsdedude marked this conversation as resolved.
Show resolved Hide resolved
database=None, impersonated_user=None,
bookmark_manager=..., tx_meta=None, timeout=None):
config = {
"routing": routing,
"database": database,
"impersonatedUser": impersonated_user,
"txMeta": tx_meta,
"timeout": timeout,
}

if bookmark_manager is None:
Expand Down
5 changes: 3 additions & 2 deletions nutkit/protocol/requests.py
Original file line number Diff line number Diff line change
Expand Up @@ -775,14 +775,15 @@ class ExecuteQuery:
:param config.bookmarkManagerId: The id of the bookmark manager
used in the query. None or not define for using the default,
-1 for disabling the BookmarkManager
:param config.txMeta: metadata to attach to the transaction.
:param config.timeout: timeout for the transaction in milliseconds.
"""

def __init__(self, driver_id, cypher, params, config):
self.driverId = driver_id
self.cypher = cypher
self.params = params
if config:
self.config = config
self.config = config


class FakeTimeInstall:
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
!: BOLT 5.0

A: HELLO {"{}": "*"}
*: RESET
C: BEGIN {"tx_metadata": {"foo": "bar"}, "db": "adb"}
S: SUCCESS {}
C: RUN "RETURN 1 AS n" {} {}
S: SUCCESS {"fields": ["n"], "qid": 1}
C: PULL {"n": 1000}
S: RECORD [1]
SUCCESS {"type": "r"}
C: COMMIT
S: SUCCESS {"bookmark": "neo4j:bookmark:v1:tx424242"}
*: RESET
?: GOODBYE
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
!: BOLT 5.0

A: HELLO {"{}": "*"}
*: RESET
C: BEGIN {"tx_timeout": 1234, "db": "adb"}
S: SUCCESS {}
C: RUN "RETURN 1 AS n" {} {}
S: SUCCESS {"fields": ["n"], "qid": 1}
C: PULL {"n": 1000}
S: RECORD [1]
SUCCESS {"type": "r"}
C: COMMIT
S: SUCCESS {"bookmark": "neo4j:bookmark:v1:tx424242"}
*: RESET
?: GOODBYE
80 changes: 63 additions & 17 deletions tests/stub/driver_execute_query/test_driver_execute_query.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,10 @@ def test_execute_query_without_config(self):
self._start_server(self._writer, "tx_return_1_with_params.script")
self._driver = self._new_driver()

eager_result = self._driver.execute_query("RETURN $a AS n",
{"a": types.CypherInt(1)})
eager_result = self._driver.execute_query(
"RETURN $a AS n",
params={"a": types.CypherInt(1)}
)

self._assert_eager_result(
eager_result,
Expand All @@ -65,9 +67,11 @@ def test_configure_routing_to_writers(self):
self._start_server(self._writer, "tx_return_1_with_params.script")
self._driver = self._new_driver()

eager_result = self._driver.execute_query("RETURN $a AS n",
{"a": types.CypherInt(1)},
routing="w")
eager_result = self._driver.execute_query(
"RETURN $a AS n",
params={"a": types.CypherInt(1)},
routing="w"
)

self._assert_eager_result(
eager_result,
Expand All @@ -81,9 +85,11 @@ def test_configure_routing_to_readers(self):
self._start_server(self._reader, "tx_return_1_with_params.script")
self._driver = self._new_driver()

eager_result = self._driver.execute_query("RETURN $a AS n",
{"a": types.CypherInt(1)},
routing="r")
eager_result = self._driver.execute_query(
"RETURN $a AS n",
params={"a": types.CypherInt(1)},
routing="r"
)

self._assert_eager_result(
eager_result,
Expand All @@ -99,9 +105,11 @@ def test_configure_database(self):
)
self._driver = self._new_driver()

eager_result = self._driver.execute_query("RETURN $a AS n",
{"a": types.CypherInt(1)},
database="neo4j")
eager_result = self._driver.execute_query(
"RETURN $a AS n",
params={"a": types.CypherInt(1)},
database="neo4j"
)

self._assert_eager_result(
eager_result,
Expand Down Expand Up @@ -129,6 +137,44 @@ def test_configure_impersonated_user(self):
query_type="r"
)

def test_configure_transaction_metadata(self):
self._start_server(self._router, "router.script")
self._start_server(
self._writer, "tx_return_1_with_tx_meta.script"
)
self._driver = self._new_driver()

eager_result = self._driver.execute_query(
"RETURN 1 AS n",
tx_meta={"foo": types.CypherString("bar")}
)

self._assert_eager_result(
eager_result,
keys=["n"],
records=[types.Record(values=[types.CypherInt(1)])],
query_type="r"
)

def test_configure_transaction_timeout(self):
self._start_server(self._router, "router.script")
self._start_server(
self._writer, "tx_return_1_with_tx_timeout.script"
)
self._driver = self._new_driver()

eager_result = self._driver.execute_query(
"RETURN 1 AS n",
timeout=1234,
)

self._assert_eager_result(
eager_result,
keys=["n"],
records=[types.Record(values=[types.CypherInt(1)])],
query_type="r"
)

def test_causal_consistency_between_query_executions(self):
self._start_server(self._router, "router.script")
self._start_server(
Expand All @@ -139,7 +185,7 @@ def test_causal_consistency_between_query_executions(self):
# CREATING NODE
eager_result = self._driver.execute_query(
"CREATE (p:Person {name:$name}) RETURN p.name AS name",
{"name": types.CypherString("the person")}
params={"name": types.CypherString("the person")}
)

self._assert_eager_result(
Expand All @@ -152,7 +198,7 @@ def test_causal_consistency_between_query_executions(self):
# READING SAME NODE
eager_result2 = self._driver.execute_query(
"MATCH (p:Person {name:$name}) RETURN p.name AS name",
{"name": types.CypherString("the person")}
params={"name": types.CypherString("the person")}
)

self._assert_eager_result(
Expand All @@ -172,7 +218,7 @@ def test_disable_bookmark_manager(self):
# CREATING NODE
eager_result = self._driver.execute_query(
"CREATE (p:Person {name:$name}) RETURN p.name AS name",
{"name": types.CypherString("the person")},
params={"name": types.CypherString("the person")},
bookmark_manager=None
)

Expand All @@ -186,7 +232,7 @@ def test_disable_bookmark_manager(self):
# READING SAME NODE
eager_result2 = self._driver.execute_query(
"MATCH (p:Person {name:$name}) RETURN p.name AS name",
{"name": types.CypherString("the person")},
params={"name": types.CypherString("the person")},
bookmark_manager=None
)

Expand All @@ -213,7 +259,7 @@ def test_configure_custom_bookmark_manager(self):
# CREATING NODE
eager_result = self._driver.execute_query(
"CREATE (p:Person {name:$name}) RETURN p.name AS name",
{"name": types.CypherString("a person")},
params={"name": types.CypherString("a person")},
bookmark_manager=bookmark_manager
)

Expand All @@ -227,7 +273,7 @@ def test_configure_custom_bookmark_manager(self):
# READING SAME NODE
eager_result2 = self._driver.execute_query(
"MATCH (p:Person {name:$name}) RETURN p.name AS name",
{"name": types.CypherString("a person")},
params={"name": types.CypherString("a person")},
bookmark_manager=bookmark_manager
)

Expand Down