|
19 | 19 | # limitations under the License. |
20 | 20 |
|
21 | 21 |
|
| 22 | +from time import sleep |
22 | 23 | from unittest import SkipTest |
23 | 24 | from uuid import uuid4 |
24 | 25 |
|
25 | 26 | from neo4j import \ |
26 | 27 | READ_ACCESS, WRITE_ACCESS, \ |
27 | 28 | CypherError, SessionError, TransactionError, unit_of_work |
28 | 29 | from neo4j.types.graph import Node, Relationship, Path |
29 | | -from neo4j.exceptions import CypherSyntaxError |
| 30 | +from neo4j.exceptions import CypherSyntaxError, TransientError |
30 | 31 |
|
31 | 32 | from test.integration.tools import DirectIntegrationTestCase |
32 | 33 |
|
@@ -62,6 +63,24 @@ def test_can_run_simple_statement_with_params(self): |
62 | 63 | session.close() |
63 | 64 | assert count == 1 |
64 | 65 |
|
| 66 | + def test_autocommit_transactions_use_bookmarks(self): |
| 67 | + if self.protocol_version() < 3: |
| 68 | + raise SkipTest("Test requires Bolt v3") |
| 69 | + bookmarks = [] |
| 70 | + # Generate an initial bookmark |
| 71 | + with self.driver.session() as session: |
| 72 | + session.run("CREATE ()").consume() |
| 73 | + bookmark = session.last_bookmark() |
| 74 | + self.assertIsNotNone(bookmark) |
| 75 | + bookmarks.append(bookmark) |
| 76 | + # Propagate into another session |
| 77 | + with self.driver.session(bookmarks=bookmarks) as session: |
| 78 | + self.assertEqual(list(session.next_bookmarks()), bookmarks) |
| 79 | + session.run("CREATE ()").consume() |
| 80 | + bookmark = session.last_bookmark() |
| 81 | + self.assertIsNotNone(bookmark) |
| 82 | + self.assertNotIn(bookmark, bookmarks) |
| 83 | + |
65 | 84 | def test_fails_on_bad_syntax(self): |
66 | 85 | session = self.driver.session() |
67 | 86 | with self.assertRaises(CypherError): |
@@ -369,6 +388,27 @@ def test_last_run_statement_should_be_cleared_on_failure(self): |
369 | 388 | assert connection_2._last_run_statement is None |
370 | 389 | tx.close() |
371 | 390 |
|
| 391 | + def test_transaction_metadata(self): |
| 392 | + if self.protocol_version() < 3: |
| 393 | + raise SkipTest("Test requires Bolt v3") |
| 394 | + with self.driver.session() as session: |
| 395 | + metadata_in = {"foo": "bar"} |
| 396 | + with session.begin_transaction(metadata=metadata_in) as tx: |
| 397 | + metadata_out = tx.run("CALL dbms.getTXMetaData").single().value() |
| 398 | + self.assertEqual(metadata_in, metadata_out) |
| 399 | + |
| 400 | + def test_transaction_timeout(self): |
| 401 | + if self.protocol_version() < 3: |
| 402 | + raise SkipTest("Test requires Bolt v3") |
| 403 | + with self.driver.session() as s1: |
| 404 | + s1.run("CREATE (a:Node)").consume() |
| 405 | + with self.driver.session() as s2: |
| 406 | + tx1 = s1.begin_transaction() |
| 407 | + tx1.run("MATCH (a:Node) SET a.property = 1").consume() |
| 408 | + tx2 = s2.begin_transaction(timeout=0.25) |
| 409 | + with self.assertRaises(TransientError): |
| 410 | + tx2.run("MATCH (a:Node) SET a.property = 2").consume() |
| 411 | + |
372 | 412 |
|
373 | 413 | class BookmarkingTestCase(DirectIntegrationTestCase): |
374 | 414 |
|
|
0 commit comments