-
Notifications
You must be signed in to change notification settings - Fork 41
Fixed Bug:- Multi-Driver Failover when one of multiple hosts down #282
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Draft
p123-stack
wants to merge
6
commits into
main
Choose a base branch
from
bugfix/connection-failure-multi-host
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
2cf09a8
Fixed Bug:- Multi-Driver Failover when one of multiple hosts down
p123-stack 194c020
fixed unit tests
p123-stack 5f4d6ba
added more multi-driver failover and client exception handling unit t…
p123-stack a305e6c
fixed code standards and psalm issue
p123-stack d596e48
Added unit test for Client Session Exception Handling
p123-stack 03bee90
Add unit test and implemented client retry logic for connection pool …
p123-stack File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,122 @@ | ||
| <?php | ||
|
|
||
| declare(strict_types=1); | ||
|
|
||
| /* | ||
| * This file is part of the Neo4j PHP Client and Driver package. | ||
| * | ||
| * (c) Nagels <https://nagels.tech> | ||
| * | ||
| * For the full copyright and license information, please view the LICENSE | ||
| * file that was distributed with this source code. | ||
| */ | ||
|
|
||
| namespace Laudis\Neo4j\Tests\Unit; | ||
|
|
||
| use Laudis\Neo4j\Client; | ||
| use Laudis\Neo4j\Common\DriverSetupManager; | ||
| use Laudis\Neo4j\Databags\SessionConfiguration; | ||
| use Laudis\Neo4j\Databags\TransactionConfiguration; | ||
| use PHPUnit\Framework\TestCase; | ||
| use RuntimeException; | ||
|
|
||
| final class ClientExceptionHandlingTest extends TestCase | ||
| { | ||
| public function testClientRunStatementWithFailingDriver(): void | ||
| { | ||
| $driverSetupManager = $this->createMock(DriverSetupManager::class); | ||
| $sessionConfig = SessionConfiguration::default(); | ||
| $transactionConfig = TransactionConfiguration::default(); | ||
|
|
||
| $driverSetupManager->method('getDriver') | ||
| ->willThrowException(new RuntimeException( | ||
| 'Cannot connect to any server on alias: default with Uris: (\'neo4j://node1:7687\', \'neo4j://node2:7687\')' | ||
| )); | ||
|
|
||
| $client = new Client($driverSetupManager, $sessionConfig, $transactionConfig); | ||
|
|
||
| $this->expectException(RuntimeException::class); | ||
| $this->expectExceptionMessage('Cannot connect to any server on alias: default'); | ||
| $client->run('RETURN 1 as n'); | ||
| } | ||
|
|
||
| public function testClientWriteTransactionWithFailingDriver(): void | ||
| { | ||
| $driverSetupManager = $this->createMock(DriverSetupManager::class); | ||
| $sessionConfig = SessionConfiguration::default(); | ||
| $transactionConfig = TransactionConfiguration::default(); | ||
|
|
||
| $driverSetupManager->method('getDriver') | ||
| ->willThrowException(new RuntimeException( | ||
| 'Cannot connect to any server on alias: default with Uris: (\'neo4j://node1:7687\', \'neo4j://node2:7687\')' | ||
| )); | ||
|
|
||
| $client = new Client($driverSetupManager, $sessionConfig, $transactionConfig); | ||
|
|
||
| $this->expectException(RuntimeException::class); | ||
| $this->expectExceptionMessage('Cannot connect to any server'); | ||
|
|
||
| $client->writeTransaction(function () { | ||
| return 'test'; | ||
| }); | ||
| } | ||
|
|
||
| public function testClientReadTransactionWithFailingDriver(): void | ||
| { | ||
| $driverSetupManager = $this->createMock(DriverSetupManager::class); | ||
| $sessionConfig = SessionConfiguration::default(); | ||
| $transactionConfig = TransactionConfiguration::default(); | ||
|
|
||
| $driverSetupManager->method('getDriver') | ||
| ->willThrowException(new RuntimeException( | ||
| 'Cannot connect to any server on alias: default with Uris: (\'neo4j://node1:7687\', \'neo4j://node2:7687\')' | ||
| )); | ||
|
|
||
| $client = new Client($driverSetupManager, $sessionConfig, $transactionConfig); | ||
|
|
||
| $this->expectException(RuntimeException::class); | ||
| $this->expectExceptionMessage('Cannot connect to any server'); | ||
|
|
||
| $client->readTransaction(function () { | ||
| return 'test'; | ||
| }); | ||
| } | ||
|
|
||
| public function testClientBeginTransactionWithFailingDriver(): void | ||
| { | ||
| $driverSetupManager = $this->createMock(DriverSetupManager::class); | ||
| $sessionConfig = SessionConfiguration::default(); | ||
| $transactionConfig = TransactionConfiguration::default(); | ||
|
|
||
| $driverSetupManager->method('getDriver') | ||
| ->willThrowException(new RuntimeException( | ||
| 'Cannot connect to any server on alias: default with Uris: (\'neo4j://node1:7687\', \'neo4j://node2:7687\')' | ||
| )); | ||
|
|
||
| $client = new Client($driverSetupManager, $sessionConfig, $transactionConfig); | ||
|
|
||
| $this->expectException(RuntimeException::class); | ||
| $this->expectExceptionMessage('Cannot connect to any server'); | ||
|
|
||
| $client->beginTransaction(); | ||
| } | ||
|
|
||
| public function testClientExceptionIncludesFailedAliasInfo(): void | ||
| { | ||
| $driverSetupManager = $this->createMock(DriverSetupManager::class); | ||
| $sessionConfig = SessionConfiguration::default(); | ||
| $transactionConfig = TransactionConfiguration::default(); | ||
|
|
||
| $driverSetupManager->method('getDriver') | ||
| ->willThrowException(new RuntimeException( | ||
| 'Cannot connect to any server on alias: secondary with Uris: (\'neo4j://node4:7687\', \'neo4j://node5:7687\')' | ||
| )); | ||
|
|
||
| $client = new Client($driverSetupManager, $sessionConfig, $transactionConfig); | ||
|
|
||
| $this->expectException(RuntimeException::class); | ||
| $this->expectExceptionMessage('Cannot connect to any server on alias: secondary'); | ||
|
|
||
| $client->run('RETURN 1 as n', [], 'secondary'); | ||
| } | ||
| } |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The idea here is sound, but the execution will have a bug. The driver setups will return the same driver every time. We will need to adjust the DriverSetupManager as well. Maybe we can add a
resetmethod to the class for a specific alias, so it verifies the connections again and finds a new driver with a verified connection? If we go that route, we don't need any complex retry logic; catch the exception, reset the drivers in the driver setup manager, and try again.