|
| 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))) |
0 commit comments