-
-
Notifications
You must be signed in to change notification settings - Fork 11
/
Copy pathPerformanceTest.php
63 lines (53 loc) · 2.03 KB
/
PerformanceTest.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
<?php
namespace Bolt\tests;
use Bolt\Bolt;
use Bolt\connection\Socket;
use Bolt\enum\Signature;
use Bolt\protocol\Response;
use Bolt\tests\packstream\v1\generators\RandomDataGenerator;
/**
* Class PerformanceTest
* @author Ghlen Nagels
* @link /~https://github.com/neo4j-php/Bolt
* @package Bolt\tests
*/
class PerformanceTest extends TestLayer
{
public function test50KRecords(): void
{
$amount = 50000;
$conn = new Socket($GLOBALS['NEO_HOST'] ?? 'localhost', $GLOBALS['NEO_PORT'] ?? 7687, 60);
$protocol = (new Bolt($conn))->setProtocolVersions($this->getCompatibleBoltVersion())->build();
$this->sayHello($protocol, $GLOBALS['NEO_USER'], $GLOBALS['NEO_PASS']);
//prevent multiple runs at once
while (true) {
$protocol->run('MATCH (n:Test50k) RETURN count(n)')->getResponse();
/** @var Response $response */
$response = $protocol->pull()->getResponse();
if ($response->signature !== Signature::RECORD)
$this->markTestSkipped();
$protocol->getResponse();
if ($response->content[0] > 0) {
sleep(60);
} else {
iterator_to_array($protocol->run('CREATE (n:Test50k)')->pull()->getResponses(), false);
break;
}
}
$generator = new RandomDataGenerator($amount);
/** @var Response $response */
$response = $protocol
->run('UNWIND $x as x RETURN x', ['x' => $generator])
->getResponse();
if ($response->signature !== Signature::SUCCESS)
$this->markTestIncomplete('[' . $response->content['code'] . '] ' . $response->content['message']);
$count = 0;
/** @var Response $response */
foreach ($protocol->pull()->getResponses() as $response) {
if ($response->signature === Signature::RECORD)
$count++;
}
$protocol->run('MATCH (n:Test50k) DELETE n')->getResponses();
$this->assertEquals($amount, $count);
}
}