|
| 1 | +--TEST-- |
| 2 | +MongoDB\Driver\Command non-zero batchSize applies to getMore |
| 3 | +--SKIPIF-- |
| 4 | +<?php require __DIR__ . "/../utils/basic-skipif.inc"; ?> |
| 5 | +<?php NEEDS('STANDALONE'); CLEANUP(STANDALONE); ?> |
| 6 | +--FILE-- |
| 7 | +<?php |
| 8 | +require_once __DIR__ . "/../utils/basic.inc"; |
| 9 | + |
| 10 | +class Test implements MongoDB\Driver\Monitoring\CommandSubscriber |
| 11 | +{ |
| 12 | + public function executeCommand() |
| 13 | + { |
| 14 | + MongoDB\Driver\Monitoring\addSubscriber($this); |
| 15 | + |
| 16 | + $manager = new MongoDB\Driver\Manager(STANDALONE); |
| 17 | + |
| 18 | + $bulkWrite = new MongoDB\Driver\BulkWrite; |
| 19 | + |
| 20 | + for ($i = 0; $i < 5; $i++) { |
| 21 | + $bulkWrite->insert(['_id' => $i]); |
| 22 | + } |
| 23 | + |
| 24 | + $writeResult = $manager->executeBulkWrite(NS, $bulkWrite); |
| 25 | + printf("Inserted: %d\n", $writeResult->getInsertedCount()); |
| 26 | + |
| 27 | + $command = new MongoDB\Driver\Command([ |
| 28 | + 'aggregate' => COLLECTION_NAME, |
| 29 | + 'pipeline' => [['$match' => new stdClass]], |
| 30 | + 'cursor' => ['batchSize' => 2] |
| 31 | + ]); |
| 32 | + $cursor = $manager->executeCommand(DATABASE_NAME, $command); |
| 33 | + |
| 34 | + $cursor->toArray(); |
| 35 | + |
| 36 | + MongoDB\Driver\Monitoring\removeSubscriber($this); |
| 37 | + } |
| 38 | + |
| 39 | + public function commandStarted(MongoDB\Driver\Monitoring\CommandStartedEvent $event) |
| 40 | + { |
| 41 | + $command = $event->getCommand(); |
| 42 | + |
| 43 | + if ($event->getCommandName() === 'aggregate') { |
| 44 | + printf("aggregate command specifies batchSize: %d\n", $command->cursor->batchSize); |
| 45 | + } |
| 46 | + |
| 47 | + if ($event->getCommandName() === 'getMore') { |
| 48 | + printf("getMore command specifies batchSize: %d\n", $command->batchSize); |
| 49 | + } |
| 50 | + } |
| 51 | + |
| 52 | + public function commandSucceeded(MongoDB\Driver\Monitoring\CommandSucceededEvent $event) |
| 53 | + { |
| 54 | + $reply = $event->getReply(); |
| 55 | + |
| 56 | + if ($event->getCommandName() === 'aggregate') { |
| 57 | + printf("aggregate response contains %d document(s)\n", count($reply->cursor->firstBatch)); |
| 58 | + } |
| 59 | + |
| 60 | + if ($event->getCommandName() === 'getMore') { |
| 61 | + printf("getMore response contains %d document(s)\n", count($reply->cursor->nextBatch)); |
| 62 | + } |
| 63 | + } |
| 64 | + |
| 65 | + public function commandFailed(MongoDB\Driver\Monitoring\CommandFailedEvent $event) |
| 66 | + { |
| 67 | + } |
| 68 | +} |
| 69 | + |
| 70 | +(new Test)->executeCommand(); |
| 71 | + |
| 72 | +?> |
| 73 | +===DONE=== |
| 74 | +<?php exit(0); ?> |
| 75 | +--EXPECT-- |
| 76 | +Inserted: 5 |
| 77 | +aggregate command specifies batchSize: 2 |
| 78 | +aggregate response contains 2 document(s) |
| 79 | +getMore command specifies batchSize: 2 |
| 80 | +getMore response contains 2 document(s) |
| 81 | +getMore command specifies batchSize: 2 |
| 82 | +getMore response contains 1 document(s) |
| 83 | +===DONE=== |
0 commit comments