Skip to content

Commit 9e51578

Browse files
Peter Wilhelmsson2hdddg
authored andcommitted
Cherry pick performance/stress tests from 1.7
These tests were lost somewhere in 1.7 branching/remerging from 1.7 to 4.0.
1 parent 3c11e2b commit 9e51578

File tree

5 files changed

+209
-0
lines changed

5 files changed

+209
-0
lines changed

tests/env.py

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
#!/usr/bin/env python
2+
# -*- encoding: utf-8 -*-
3+
4+
# Copyright (c) 2002-2019 "Neo4j,"
5+
# Neo4j Sweden AB [http://neo4j.com]
6+
#
7+
# This file is part of Neo4j.
8+
#
9+
# Licensed under the Apache License, Version 2.0 (the "License");
10+
# you may not use this file except in compliance with the License.
11+
# You may obtain a copy of the License at
12+
#
13+
# http://www.apache.org/licenses/LICENSE-2.0
14+
#
15+
# Unless required by applicable law or agreed to in writing, software
16+
# distributed under the License is distributed on an "AS IS" BASIS,
17+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18+
# See the License for the specific language governing permissions and
19+
# limitations under the License.
20+
21+
22+
from os import getenv
23+
24+
25+
# Full path of a server package to be used for integration testing
26+
NEO4J_SERVER_PACKAGE = getenv("NEO4J_SERVER_PACKAGE")
27+
28+
# An existing remote server at this URI
29+
NEO4J_SERVER_URI = getenv("NEO4J_URI")
30+
31+
# Name of a user for the currently running server
32+
NEO4J_USER = getenv("NEO4J_USER")
33+
34+
# Password for the currently running server
35+
NEO4J_PASSWORD = getenv("NEO4J_PASSWORD")
36+
37+
NEOCTRL_ARGS = getenv("NEOCTRL_ARGS", "3.4.1")

tests/performance/test_results.py

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
#!/usr/bin/env python
2+
# -*- encoding: utf-8 -*-
3+
4+
# Copyright (c) 2002-2019 "Neo4j,"
5+
# Neo4j Sweden AB [http://neo4j.com]
6+
#
7+
# This file is part of Neo4j.
8+
#
9+
# Licensed under the Apache License, Version 2.0 (the "License");
10+
# you may not use this file except in compliance with the License.
11+
# You may obtain a copy of the License at
12+
#
13+
# http://www.apache.org/licenses/LICENSE-2.0
14+
#
15+
# Unless required by applicable law or agreed to in writing, software
16+
# distributed under the License is distributed on an "AS IS" BASIS,
17+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18+
# See the License for the specific language governing permissions and
19+
# limitations under the License.
20+
21+
22+
from itertools import product
23+
24+
from pytest import mark
25+
26+
from neo4j import GraphDatabase
27+
from .tools import RemoteGraphDatabaseServer
28+
29+
30+
class ReadWorkload(object):
31+
32+
server = None
33+
driver = None
34+
35+
@classmethod
36+
def setup_class(cls):
37+
cls.server = server = RemoteGraphDatabaseServer()
38+
server.start()
39+
cls.driver = GraphDatabase.driver(server.server_uri, auth=server.auth_token, encrypted=server.encrypted)
40+
41+
@classmethod
42+
def teardown_class(cls):
43+
cls.driver.close()
44+
cls.server.stop()
45+
46+
def work(self, *units_of_work):
47+
def runner():
48+
with self.driver.session() as session:
49+
for unit_of_work in units_of_work:
50+
session.read_transaction(unit_of_work)
51+
return runner
52+
53+
54+
class TestReadWorkload(ReadWorkload):
55+
56+
@staticmethod
57+
def uow(record_count, record_width, value):
58+
59+
def _(tx):
60+
s = "UNWIND range(1, $record_count) AS _ RETURN {}".format(
61+
", ".join("$x AS x{}".format(i) for i in range(record_width)))
62+
p = {"record_count": record_count, "x": value}
63+
for record in tx.run(s, p):
64+
assert all(x == value for x in record.values())
65+
66+
return _
67+
68+
@mark.parametrize("record_count,record_width,value", product(
69+
[1, 1000], # record count
70+
[1, 10], # record width
71+
[1, u'hello, world'], # value
72+
))
73+
def test_1x1(self, benchmark, record_count, record_width, value):
74+
benchmark(self.work(self.uow(record_count, record_width, value)))

tests/performance/tools.py

Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
#!/usr/bin/env python
2+
# -*- encoding: utf-8 -*-
3+
4+
# Copyright (c) 2002-2019 "Neo4j,"
5+
# Neo4j Sweden AB [http://neo4j.com]
6+
#
7+
# This file is part of Neo4j.
8+
#
9+
# Licensed under the Apache License, Version 2.0 (the "License");
10+
# you may not use this file except in compliance with the License.
11+
# You may obtain a copy of the License at
12+
#
13+
# http://www.apache.org/licenses/LICENSE-2.0
14+
#
15+
# Unless required by applicable law or agreed to in writing, software
16+
# distributed under the License is distributed on an "AS IS" BASIS,
17+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18+
# See the License for the specific language governing permissions and
19+
# limitations under the License.
20+
21+
22+
from test.integration.tools import IntegrationTestCase
23+
24+
from os import makedirs, remove
25+
from os.path import basename, dirname, join as path_join, realpath, isfile, expanduser
26+
import platform
27+
from unittest import TestCase, SkipTest
28+
from shutil import copyfile
29+
from sys import exit, stderr
30+
31+
try:
32+
from urllib.request import urlretrieve
33+
except ImportError:
34+
from urllib import urlretrieve
35+
36+
from boltkit.controller import WindowsController, UnixController
37+
38+
from neo4j import GraphDatabase
39+
from neo4j.exceptions import AuthError
40+
41+
from test.env import NEO4J_USER, NEO4J_PASSWORD, NEO4J_SERVER_URI
42+
43+
44+
def is_listening(address):
45+
from socket import create_connection
46+
try:
47+
s = create_connection(address)
48+
except IOError:
49+
return False
50+
else:
51+
s.close()
52+
return True
53+
54+
55+
class RemoteGraphDatabaseServer(object):
56+
server_uri = NEO4J_SERVER_URI or "bolt://localhost:7687"
57+
auth_token = (NEO4J_USER or "neo4j", NEO4J_PASSWORD)
58+
encrypted = NEO4J_SERVER_URI is not None
59+
60+
def __enter__(self):
61+
self.start()
62+
return self
63+
64+
def __exit__(self, exc_type, exc_value, traceback):
65+
self.stop()
66+
67+
@classmethod
68+
def start(cls):
69+
with GraphDatabase.driver(cls.server_uri, auth=cls.auth_token, encrypted=cls.encrypted) as driver:
70+
try:
71+
with driver.session():
72+
print("Using existing remote server {}\n".format(cls.server_uri))
73+
return
74+
except AuthError as error:
75+
raise RuntimeError("Failed to authenticate (%s)" % error)
76+
raise SkipTest("No remote Neo4j server available for %s" % cls.__name__)
77+
78+
@classmethod
79+
def stop(cls):
80+
pass

tox-performance.ini

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
[tox]
2+
envlist =
3+
py34
4+
py35
5+
py36
6+
7+
[testenv]
8+
passenv =
9+
NEO4J_USER
10+
NEO4J_PASSWORD
11+
NEO4J_URI
12+
commands =
13+
python setup.py develop
14+
pip install --upgrade -r {toxinidir}/test/requirements.txt
15+
coverage erase
16+
coverage run -m pytest -v {posargs} test/performance
17+
coverage report

tox.ini

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ passenv =
1616
TEAMCITY_USER
1717
TEAMCITY_PASSWORD
1818
JAVA_HOME
19+
NEO4J_URI
1920
AWS_ACCESS_KEY_ID
2021
AWS_SECRET_ACCESS_KEY
2122
deps =

0 commit comments

Comments
 (0)