Skip to content

Commit c3e836b

Browse files
committed
Revert "Added server state check for bolt."
This reverts commit 8335f8b.
1 parent be650a5 commit c3e836b

File tree

2 files changed

+49
-18
lines changed

2 files changed

+49
-18
lines changed

src/Bolt/BoltConnection.php

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -201,6 +201,10 @@ public function begin(?string $database, ?float $timeout, BookmarkHolder $holder
201201
*/
202202
public function discard(?int $qid): void
203203
{
204+
if (!in_array($this->protocol()->serverState, [ServerState::STREAMING, ServerState::TX_STREAMING], true)) {
205+
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.')]);
206+
}
207+
204208
$extra = $this->buildResultExtra(null, $qid);
205209
$response = $this->protocol()
206210
->discard($extra)
@@ -217,6 +221,10 @@ public function discard(?int $qid): void
217221
*/
218222
public function run(string $text, array $parameters, ?string $database, ?float $timeout, BookmarkHolder $holder, ?AccessMode $mode): array
219223
{
224+
if (!in_array($this->protocol()->serverState, [ServerState::READY, ServerState::TX_READY, ServerState::TX_STREAMING], true)) {
225+
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.')]);
226+
}
227+
220228
$extra = $this->buildRunExtra($database, $timeout, $holder, $mode);
221229
$response = $this->protocol()
222230
->run($text, $parameters, $extra)
@@ -274,6 +282,10 @@ public function protocol(): V4_4|V5|V5_3|V5_4
274282
*/
275283
public function pull(?int $qid, ?int $fetchSize): array
276284
{
285+
if (!in_array($this->protocol()->serverState, [ServerState::STREAMING, ServerState::TX_STREAMING], true)) {
286+
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.')]);
287+
}
288+
277289
$extra = $this->buildResultExtra($fetchSize, $qid);
278290

279291
$tbr = [];

tests/Integration/TransactionIntegrationTest.php

Lines changed: 37 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -212,19 +212,28 @@ public function testCommitValidFilledWithInvalidStatement(): void
212212
self::assertFalse($tsx->isCommitted());
213213
}
214214

215-
public function testCommitInvalid(): void
216-
{
217-
$this->markTestSkipped('Skipped due to ConnectionTimeoutException');
215+
// TODO commit on READY state cause stuck neo4j connection on older version and disconnect at newer
216+
// public function testCommitInvalid(): void
217+
// {
218218
// $tsx = $this->getSession()->beginTransaction();
219219
// $tsx->commit();
220220
//
221221
// self::assertTrue($tsx->isFinished());
222222
// self::assertFalse($tsx->isRolledBack());
223223
// self::assertTrue($tsx->isCommitted());
224224
//
225-
// $this->expectException(Neo4jException::class);
226-
// $tsx->commit();
227-
}
225+
// $exception = false;
226+
// try {
227+
// $tsx->commit();
228+
// } catch (Throwable) {
229+
// $exception = true;
230+
// }
231+
// self::assertTrue($exception);
232+
//
233+
// self::assertTrue($tsx->isFinished());
234+
// self::assertTrue($tsx->isRolledBack());
235+
// self::assertFalse($tsx->isCommitted());
236+
// }
228237

229238
public function testRollbackValid(): void
230239
{
@@ -237,18 +246,28 @@ public function testRollbackValid(): void
237246
// self::assertFalse($tsx->isCommitted());
238247
}
239248

240-
public function testRollbackInvalid(): void
241-
{
242-
$tsx = $this->getSession()->beginTransaction();
243-
$tsx->rollback();
244-
245-
self::assertTrue($tsx->isFinished());
246-
self::assertTrue($tsx->isRolledBack());
247-
self::assertFalse($tsx->isCommitted());
248-
249-
$this->expectException(Neo4jException::class);
250-
$tsx->rollback();
251-
}
249+
// TODO rollback on READY state cause stuck neo4j connection on older version and disconnect at newer
250+
// public function testRollbackInvalid(): void
251+
// {
252+
// $tsx = $this->getSession()->beginTransaction();
253+
// $tsx->rollback();
254+
//
255+
// self::assertTrue($tsx->isFinished());
256+
// self::assertTrue($tsx->isRolledBack());
257+
// self::assertFalse($tsx->isCommitted());
258+
//
259+
// $exception = false;
260+
// try {
261+
// $tsx->rollback();
262+
// } catch (Throwable) {
263+
// $exception = true;
264+
// }
265+
// self::assertTrue($exception);
266+
//
267+
// self::assertTrue($tsx->isFinished());
268+
// self::assertTrue($tsx->isRolledBack());
269+
// self::assertFalse($tsx->isCommitted());
270+
// }
252271

253272
// /**
254273
// * TODO - rework this test

0 commit comments

Comments
 (0)