|
7 | 7 | use MongoDB\Driver\ReadPreference;
|
8 | 8 | use MongoDB\Driver\Server;
|
9 | 9 | use MongoDB\Driver\Exception\ConnectionTimeoutException;
|
| 10 | +use MongoDB\Exception\ResumeTokenException; |
10 | 11 | use MongoDB\Operation\DatabaseCommand;
|
11 | 12 | use MongoDB\Operation\InsertOne;
|
12 | 13 | use MongoDB\Operation\Watch;
|
@@ -552,6 +553,41 @@ public function testNextAdvancesKey()
|
552 | 553 | $this->assertSame(1, $changeStream->key());
|
553 | 554 | }
|
554 | 555 |
|
| 556 | + public function testResumeTokenNotFoundAdvancesKey() |
| 557 | + { |
| 558 | + $pipeline = [['$project' => ['_id' => 0 ]]]; |
| 559 | + |
| 560 | + $operation = new Watch($this->manager, $this->getDatabaseName(), $this->getCollectionName(), $pipeline, $this->defaultOptions); |
| 561 | + $changeStream = $operation->execute($this->getPrimaryServer()); |
| 562 | + |
| 563 | + /* Note: we intentionally do not start iteration with rewind() to ensure |
| 564 | + * that we test extraction functionality within next(). */ |
| 565 | + $this->insertDocument(['x' => 1]); |
| 566 | + $this->insertDocument(['x' => 2]); |
| 567 | + $this->insertDocument(['x' => 3]); |
| 568 | + |
| 569 | + try { |
| 570 | + $changeStream->rewind(); |
| 571 | + $this->fail('ResumeTokenException was not thrown'); |
| 572 | + } catch (ResumeTokenException $e) {} |
| 573 | + |
| 574 | + $this->assertSame(0, $changeStream->key()); |
| 575 | + |
| 576 | + try { |
| 577 | + $changeStream->next(); |
| 578 | + $this->fail('ResumeTokenException was not thrown'); |
| 579 | + } catch (ResumeTokenException $e) {} |
| 580 | + |
| 581 | + $this->assertSame(1, $changeStream->key()); |
| 582 | + |
| 583 | + try { |
| 584 | + $changeStream->next(); |
| 585 | + $this->fail('ResumeTokenException was not thrown'); |
| 586 | + } catch (ResumeTokenException $e) {} |
| 587 | + |
| 588 | + $this->assertSame(2, $changeStream->key()); |
| 589 | + } |
| 590 | + |
555 | 591 | private function insertDocument($document)
|
556 | 592 | {
|
557 | 593 | $insertOne = new InsertOne($this->getDatabaseName(), $this->getCollectionName(), $document);
|
|
0 commit comments