Skip to content

Commit

Permalink
Revert "Added server state check for bolt."
Browse files Browse the repository at this point in the history
This reverts commit 8335f8b.
  • Loading branch information
exaby73 committed Jul 15, 2024
1 parent be650a5 commit c3e836b
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 18 deletions.
12 changes: 12 additions & 0 deletions src/Bolt/BoltConnection.php
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,10 @@ public function begin(?string $database, ?float $timeout, BookmarkHolder $holder
*/
public function discard(?int $qid): void
{
if (!in_array($this->protocol()->serverState, [ServerState::STREAMING, ServerState::TX_STREAMING], true)) {
throw new Neo4jException([Neo4jError::fromMessageAndCode('Neo.ClientError.Request.Invalid', 'Message \'DISCARD\' cannot be handled by a session which isn\'t in the STREAMING|TX_STREAMING state.')]);
}

$extra = $this->buildResultExtra(null, $qid);
$response = $this->protocol()
->discard($extra)
Expand All @@ -217,6 +221,10 @@ public function discard(?int $qid): void
*/
public function run(string $text, array $parameters, ?string $database, ?float $timeout, BookmarkHolder $holder, ?AccessMode $mode): array
{
if (!in_array($this->protocol()->serverState, [ServerState::READY, ServerState::TX_READY, ServerState::TX_STREAMING], true)) {
throw new Neo4jException([Neo4jError::fromMessageAndCode('Neo.ClientError.Request.Invalid', 'Message \'RUN\' cannot be handled by a session which isn\'t in the READY|TX_READY|TX_STREAMING state.')]);
}

$extra = $this->buildRunExtra($database, $timeout, $holder, $mode);
$response = $this->protocol()
->run($text, $parameters, $extra)
Expand Down Expand Up @@ -274,6 +282,10 @@ public function protocol(): V4_4|V5|V5_3|V5_4
*/
public function pull(?int $qid, ?int $fetchSize): array
{
if (!in_array($this->protocol()->serverState, [ServerState::STREAMING, ServerState::TX_STREAMING], true)) {
throw new Neo4jException([Neo4jError::fromMessageAndCode('Neo.ClientError.Request.Invalid', 'Message \'PULL\' cannot be handled by a session which isn\'t in the STREAMING|TX_STREAMING state.')]);
}

$extra = $this->buildResultExtra($fetchSize, $qid);

$tbr = [];
Expand Down
55 changes: 37 additions & 18 deletions tests/Integration/TransactionIntegrationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -212,19 +212,28 @@ public function testCommitValidFilledWithInvalidStatement(): void
self::assertFalse($tsx->isCommitted());
}

public function testCommitInvalid(): void
{
$this->markTestSkipped('Skipped due to ConnectionTimeoutException');
// TODO commit on READY state cause stuck neo4j connection on older version and disconnect at newer
// public function testCommitInvalid(): void
// {
// $tsx = $this->getSession()->beginTransaction();
// $tsx->commit();
//
// self::assertTrue($tsx->isFinished());
// self::assertFalse($tsx->isRolledBack());
// self::assertTrue($tsx->isCommitted());
//
// $this->expectException(Neo4jException::class);
// $tsx->commit();
}
// $exception = false;
// try {
// $tsx->commit();
// } catch (Throwable) {
// $exception = true;
// }
// self::assertTrue($exception);
//
// self::assertTrue($tsx->isFinished());
// self::assertTrue($tsx->isRolledBack());
// self::assertFalse($tsx->isCommitted());
// }

public function testRollbackValid(): void
{
Expand All @@ -237,18 +246,28 @@ public function testRollbackValid(): void
// self::assertFalse($tsx->isCommitted());
}

public function testRollbackInvalid(): void
{
$tsx = $this->getSession()->beginTransaction();
$tsx->rollback();

self::assertTrue($tsx->isFinished());
self::assertTrue($tsx->isRolledBack());
self::assertFalse($tsx->isCommitted());

$this->expectException(Neo4jException::class);
$tsx->rollback();
}
// TODO rollback on READY state cause stuck neo4j connection on older version and disconnect at newer
// public function testRollbackInvalid(): void
// {
// $tsx = $this->getSession()->beginTransaction();
// $tsx->rollback();
//
// self::assertTrue($tsx->isFinished());
// self::assertTrue($tsx->isRolledBack());
// self::assertFalse($tsx->isCommitted());
//
// $exception = false;
// try {
// $tsx->rollback();
// } catch (Throwable) {
// $exception = true;
// }
// self::assertTrue($exception);
//
// self::assertTrue($tsx->isFinished());
// self::assertTrue($tsx->isRolledBack());
// self::assertFalse($tsx->isCommitted());
// }

// /**
// * TODO - rework this test
Expand Down

0 comments on commit c3e836b

Please sign in to comment.