Skip to content

Commit eb0cc9d

Browse files
committed
Implement the service unavailable test.
1 parent 7a013d5 commit eb0cc9d

File tree

2 files changed

+19
-26
lines changed

2 files changed

+19
-26
lines changed

test/examples/service_unavailable_example.py

Lines changed: 10 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -19,33 +19,20 @@
1919
# limitations under the License.
2020

2121
# tag::service-unavailable-import[]
22-
from neo4j.v1 import GraphDatabase
22+
from neo4j.v1 import GraphDatabase, ServiceUnavailable
23+
from base_application import BaseApplication
2324
# end::service-unavailable-import[]
2425

25-
class ServiceUnavailableExample:
26+
class ServiceUnavailableExample(BaseApplication):
2627
def __init__(self, uri, user, password):
27-
self._driver = GraphDatabase.driver( uri, auth=(user, password), Config.build().withMaxTransactionRetryTime( 3, SECONDS ).withLogging( DEV_NULL_LOGGING ).toConfig() )
28-
29-
def close(self):
30-
self._driver.close();
28+
super().__init__(uri, user, password)
3129

3230
# tag::service-unavailable[]
3331
def addItem(self):
34-
try ( Session session = driver.session() )
35-
{
36-
return session.writeTransaction( new TransactionWork<Boolean>()
37-
{
38-
@Override
39-
public Boolean execute( Transaction tx )
40-
{
41-
tx.run( "CREATE (a:Item)" );
42-
return true;
43-
}
44-
} );
45-
}
46-
catch ( ServiceUnavailableException ex )
47-
{
48-
return false;
49-
}
50-
}
32+
try:
33+
with self._driver.session() as session:
34+
session.write_transaction(lambda tx: tx.run("CREATE (a:Item)"))
35+
return True
36+
except ServiceUnavailable as e:
37+
return False
5138
# end::service-unavailable[]

test/examples/test_examples.py

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -106,9 +106,15 @@ def test_result_retain_example(self):
106106

107107
self.assertEqual(employee_count, 2)
108108

109-
# def test_service_unavailable_example(self):
110-
# from service_unavailable_example import ServiceUnavailableExample
111-
# pass
109+
def test_service_unavailable_example(self):
110+
from service_unavailable_example import ServiceUnavailableExample
111+
112+
example = ServiceUnavailableExample(self.bolt_uri, self.user, self.password)
113+
ExamplesTest._stop_server()
114+
115+
self.assertFalse(example.addItem())
116+
117+
ExamplesTest._start_server()
112118

113119
def test_session_example(self):
114120
from session_example import SessionExample

0 commit comments

Comments
 (0)