|
17 | 17 | use InvalidArgumentException;
|
18 | 18 | use Laudis\Neo4j\Authentication\Authenticate;
|
19 | 19 | use Laudis\Neo4j\Basic\Driver;
|
| 20 | +use Laudis\Neo4j\Bolt\BoltDriver; |
| 21 | +use Laudis\Neo4j\Bolt\ConnectionPool; |
20 | 22 | use Laudis\Neo4j\ClientBuilder;
|
21 | 23 | use Laudis\Neo4j\Common\Uri;
|
22 | 24 | use Laudis\Neo4j\Contracts\FormatterInterface;
|
|
27 | 29 | use Laudis\Neo4j\Formatter\OGMFormatter;
|
28 | 30 | use Laudis\Neo4j\Types\CypherList;
|
29 | 31 | use Laudis\Neo4j\Types\CypherMap;
|
| 32 | +use ReflectionClass; |
30 | 33 | use function str_starts_with;
|
31 | 34 |
|
32 | 35 | /**
|
33 |
| - * @psalm-import-type OGMTypes from \Laudis\Neo4j\Formatter\OGMFormatter |
| 36 | + * @psalm-import-type OGMTypes from OGMFormatter |
34 | 37 | *
|
35 | 38 | * @extends EnvironmentAwareIntegrationTest<CypherList<CypherMap<OGMTypes>>>
|
36 | 39 | */
|
@@ -355,4 +358,45 @@ public function fetchSize(string $connection, int $fetchSize): void
|
355 | 358 |
|
356 | 359 | $this->assertCount($nodesAmount, $uniqueUserIds);
|
357 | 360 | }
|
| 361 | + |
| 362 | + public function testRedundantAcquire(): void |
| 363 | + { |
| 364 | + $connections = self::buildConnections(); |
| 365 | + |
| 366 | + $builder = ClientBuilder::create(); |
| 367 | + foreach ($connections as $i => $connection) { |
| 368 | + $uri = Uri::create($connection); |
| 369 | + $alias = $uri->getScheme().'_'.$i; |
| 370 | + $builder = $builder->withDriver($alias, $connection); |
| 371 | + } |
| 372 | + |
| 373 | + $client = $builder->withFormatter(ClientIntegrationTest::formatter()) |
| 374 | + ->withDefaultSessionConfiguration(SessionConfiguration::default()->withDatabase('neo4j')) |
| 375 | + ->build(); |
| 376 | + |
| 377 | + foreach ($connections as $i => $connection) { |
| 378 | + $uri = Uri::create($connection); |
| 379 | + $alias = $uri->getScheme().'_'.$i; |
| 380 | + $client->run('MATCH (x) RETURN x', [], $alias); |
| 381 | + |
| 382 | + $driver = $client->getDriver($alias); |
| 383 | + |
| 384 | + // We make sure there is no redundant acquire by testing the amount of open connections. |
| 385 | + // These may never exceed 1 in this simple case. |
| 386 | + if ($driver instanceof BoltDriver) { |
| 387 | + $reflection = new ReflectionClass($driver); |
| 388 | + |
| 389 | + $poolProp = $reflection->getProperty('pool'); |
| 390 | + /** @var ConnectionPool $pool */ |
| 391 | + $pool = $poolProp->getValue($driver); |
| 392 | + |
| 393 | + $reflection = new ReflectionClass($pool); |
| 394 | + $connectionProp = $reflection->getProperty('activeConnections'); |
| 395 | + /** @var array $activeConnections */ |
| 396 | + $activeConnections = $connectionProp->getValue($pool); |
| 397 | + |
| 398 | + $this->assertCount(1, $activeConnections); |
| 399 | + } |
| 400 | + } |
| 401 | + } |
358 | 402 | }
|
0 commit comments