Skip to content

Commit 22c91e5

Browse files
robsdedudebigmontz
andauthored
Adding tests for Bolt 5.4 and telemetry (#594)
Co-authored-by: Antonio Barcélos <[email protected]>
1 parent 3df351e commit 22c91e5

File tree

12 files changed

+441
-9
lines changed

12 files changed

+441
-9
lines changed

boltstub/bolt_protocol.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -526,3 +526,20 @@ class Bolt5x3Protocol(Bolt5x2Protocol):
526526
equivalent_versions = set()
527527

528528
server_agent = "Neo4j/5.9.0"
529+
530+
531+
class Bolt5x4Protocol(Bolt5x3Protocol):
532+
protocol_version = (5, 4)
533+
version_aliases = set()
534+
# allow the server to negotiate other bolt versions
535+
equivalent_versions = set()
536+
537+
server_agent = "Neo4j/5.14.0"
538+
539+
messages = {
540+
"C": {
541+
**Bolt5x3Protocol.messages["C"],
542+
b"\x54": "TELEMETRY",
543+
},
544+
"S": Bolt5x3Protocol.messages["S"],
545+
}

nutkit/frontend/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,3 +10,4 @@
1010
from .driver import Driver
1111
from .exceptions import ApplicationCodeError
1212
from .fake_time import FakeTime
13+
from .session import Session

nutkit/frontend/driver.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,8 @@ def __init__(self, backend, uri, auth_token, user_agent=None,
1717
max_connection_pool_size=None,
1818
connection_acquisition_timeout_ms=None,
1919
notifications_min_severity=None,
20-
notifications_disabled_categories=None):
20+
notifications_disabled_categories=None,
21+
telemetry_disabled=None):
2122
self._backend = backend
2223
self._resolver_fn = resolver_fn
2324
self._domain_name_resolver_fn = domain_name_resolver_fn
@@ -48,7 +49,8 @@ def __init__(self, backend, uri, auth_token, user_agent=None,
4849
max_connection_pool_size=max_connection_pool_size,
4950
connection_acquisition_timeout_ms=connection_acquisition_timeout_ms, # noqa: E501
5051
notifications_min_severity=notifications_min_severity,
51-
notifications_disabled_categories=notifications_disabled_categories
52+
notifications_disabled_categories=notifications_disabled_categories, # noqa: E501
53+
telemetry_disabled=telemetry_disabled
5254
)
5355
res = backend.send_and_receive(req)
5456
if not isinstance(res, protocol.Driver):

nutkit/protocol/feature.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,8 @@ class Feature(Enum):
107107
BOLT_5_2 = "Feature:Bolt:5.2"
108108
# The driver supports Bolt protocol version 5.3
109109
BOLT_5_3 = "Feature:Bolt:5.3"
110+
# The driver supports Bolt protocol version 5.4
111+
BOLT_5_4 = "Feature:Bolt:5.4"
110112
# The driver supports patching DateTimes to use UTC for Bolt 4.3 and 4.4
111113
BOLT_PATCH_UTC = "Feature:Bolt:Patch:UTC"
112114
# The driver supports impersonation

nutkit/protocol/requests.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,8 @@ def __init__(
7474
liveness_check_timeout_ms=None, max_connection_pool_size=None,
7575
connection_acquisition_timeout_ms=None,
7676
notifications_min_severity=None,
77-
notifications_disabled_categories=None
77+
notifications_disabled_categories=None,
78+
telemetry_disabled=None
7879
):
7980
# Neo4j URI to connect to
8081
self.uri = uri
@@ -96,6 +97,8 @@ def __init__(
9697
self.notificationsMinSeverity = notifications_min_severity
9798
if notifications_disabled_categories is not None:
9899
self.notificationsDisabledCategories = notifications_disabled_categories # noqa: E501
100+
if telemetry_disabled is not None:
101+
self.telemetryDisabled = telemetry_disabled
99102
# (bool) whether to enable or disable encryption
100103
# field missing in message: use driver default (should be False)
101104
if encrypted is not None:

tests/stub/driver_parameters/telemetry/__init__.py

Whitespace-only changes.
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
!: BOLT 5.4
2+
3+
C: HELLO {"{}": "*"}
4+
IF: #SERVER_TELEMETRY_ENABLED#
5+
S: SUCCESS {"server": "Neo4j/5.14.0", "connection_id": "bolt-1", "hints": {"telemetry.enabled": true}}
6+
ELSE:
7+
S: SUCCESS {"server": "Neo4j/5.14.0", "connection_id": "bolt-1"}
8+
A: LOGON {"{}": "*"}
9+
*: RESET
10+
11+
{{
12+
{{
13+
{{
14+
# transaction function
15+
C: TELEMETRY {"Z": "0"}
16+
----
17+
# unmanaged transaction
18+
C: TELEMETRY {"Z": "1"}
19+
----
20+
# driver level
21+
C: TELEMETRY {"Z": "3"}
22+
}}
23+
C: BEGIN {"{}": "*"}
24+
S: SUCCESS {}
25+
S: SUCCESS {}
26+
----
27+
C: BEGIN {"{}": "*"}
28+
S: SUCCESS {}
29+
}}
30+
C: RUN "RETURN 1 AS n" {"{}": "*"} {"{}": "*"}
31+
S: SUCCESS {"fields": ["n"]}
32+
C: PULL {"{}": "*"}
33+
S: RECORD [1]
34+
S: SUCCESS {"type": "r"}
35+
C: COMMIT
36+
S: SUCCESS {}
37+
----
38+
# auto commit
39+
{{
40+
C: TELEMETRY {"Z": "2"}
41+
C: RUN "RETURN 1 AS n" {"{}": "*"} {"{}": "*"}
42+
S: SUCCESS {}
43+
S: SUCCESS {"fields": ["n"]}
44+
----
45+
C: RUN "RETURN 1 AS n" {"{}": "*"} {"{}": "*"}
46+
S: SUCCESS {"fields": ["n"]}
47+
}}
48+
C: PULL {"{}": "*"}
49+
S: RECORD [1]
50+
S: SUCCESS {"type": "r"}
51+
}}
52+
53+
*: RESET
54+
?: GOODBYE
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
!: BOLT 5.4
2+
!: ALLOW RESTART
3+
!: PY connection_count = 0
4+
5+
PY: connection_count += 1
6+
C: HELLO {"{}": "*"}
7+
S: SUCCESS {"server": "Neo4j/5.14.0", "connection_id": "bolt-1", "hints": {"telemetry.enabled": true}}
8+
A: LOGON {"{}": "*"}
9+
*: RESET
10+
11+
IF: connection_count == 1
12+
{{
13+
C: TELEMETRY {"Z": "*"}
14+
S: <EXIT>
15+
# oopsies... dead connection... time for a retry
16+
}}
17+
ELIF: connection_count == 2
18+
{{
19+
# The driver is expected to send the TELEMETRY message again.
20+
# This time, it'll be successful.
21+
C: TELEMETRY {"Z": "*"}
22+
C: BEGIN {"{}": "*"}
23+
S: SUCCESS {}
24+
S: FAILURE {"code": "Neo.TransientError.General.PleaseRetry", "message": "something went wrong™"}
25+
26+
{?
27+
C: RUN {"U": "*"} {"{}": "*"} {"{}": "*"}
28+
S: IGNORED
29+
?}
30+
{?
31+
C: PULL {"{}": "*"}
32+
S: IGNORED
33+
?}
34+
35+
+: RESET
36+
37+
# The previous TELEMETRY message was successful, so the driver should not send it again.
38+
C: BEGIN {"{}": "*"}
39+
S: SUCCESS {}
40+
C: RUN "RETURN 1 AS n" {"{}": "*"} {"{}": "*"}
41+
S: SUCCESS {"fields": ["n"]}
42+
C: PULL {"{}": "*"}
43+
S: RECORD [1]
44+
S: SUCCESS {"type": "r"}
45+
C: COMMIT
46+
S: SUCCESS {}
47+
}}
48+
49+
*: RESET
50+
?: GOODBYE
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
!: BOLT 5.4
2+
!: AUTO RESET
3+
!: ALLOW RESTART
4+
5+
C: HELLO {"{}": "*"}
6+
IF: #SERVER_TELEMETRY_ENABLED#
7+
S: SUCCESS {"server": "Neo4j/5.14.0", "connection_id": "bolt-2", "hints": {"telemetry.enabled": true}}
8+
ELSE:
9+
S: SUCCESS {"server": "Neo4j/5.14.0", "connection_id": "bolt-2"}
10+
A: LOGON {"{}": "*"}
11+
*: RESET
12+
{+
13+
C: ROUTE "*" "*" "*"
14+
S: SUCCESS { "rt": { "ttl": 1000, "servers": [{"addresses": ["#HOST#:9010"], "role":"ROUTE"}, {"addresses": ["#HOST#:9000"], "role":"READ"}, {"addresses": ["#HOST#:9000"], "role":"WRITE"}]}}
15+
*: RESET
16+
+}
17+
?: GOODBYE

0 commit comments

Comments
 (0)