|
| 1 | +--TEST-- |
| 2 | +Retryable reads: executeReadCommand is retried once |
| 3 | +--SKIPIF-- |
| 4 | +<?php require __DIR__ . "/../utils/basic-skipif.inc"; ?> |
| 5 | +<?php skip_if_not_libmongoc_crypto(); ?> |
| 6 | +<?php skip_if_no_failcommand_failpoint(); ?> |
| 7 | +<?php skip_if_not_clean(); ?> |
| 8 | +--FILE-- |
| 9 | +<?php |
| 10 | +require_once __DIR__ . "/../utils/basic.inc"; |
| 11 | + |
| 12 | +class Observer implements MongoDB\Driver\Monitoring\CommandSubscriber |
| 13 | +{ |
| 14 | + public function commandStarted(MongoDB\Driver\Monitoring\CommandStartedEvent $event) |
| 15 | + { |
| 16 | + printf("Command started: %s\n", $event->getCommandName()); |
| 17 | + } |
| 18 | + |
| 19 | + public function commandSucceeded(MongoDB\Driver\Monitoring\CommandSucceededEvent $event) |
| 20 | + { |
| 21 | + } |
| 22 | + |
| 23 | + public function commandFailed(MongoDB\Driver\Monitoring\CommandFailedEvent $event) |
| 24 | + { |
| 25 | + } |
| 26 | +} |
| 27 | + |
| 28 | +$manager = new MongoDB\Driver\Manager(URI, ['retryReads' => true]); |
| 29 | + |
| 30 | +$bulk = new MongoDB\Driver\BulkWrite; |
| 31 | +$bulk->insert(['x' => 1]); |
| 32 | +$bulk->insert(['x' => 2]); |
| 33 | + |
| 34 | +$manager->executeBulkWrite(NS, $bulk); |
| 35 | + |
| 36 | +configureFailPoint($manager, 'failCommand', ['times' => 1], ['failCommands' => ['aggregate'], 'closeConnection' => true]); |
| 37 | + |
| 38 | +$observer = new Observer; |
| 39 | +MongoDB\Driver\Monitoring\addSubscriber($observer); |
| 40 | + |
| 41 | +$command = new MongoDB\Driver\Command([ |
| 42 | + 'aggregate' => COLLECTION_NAME, |
| 43 | + 'pipeline' => [ |
| 44 | + ['$group' => ['_id' => 1, 'n' => ['$sum' => 1]]], |
| 45 | + ], |
| 46 | + 'cursor' => (object) [], |
| 47 | +]); |
| 48 | +$cursor = $manager->executeReadCommand(DATABASE_NAME, $command); |
| 49 | +var_dump(iterator_to_array($cursor)); |
| 50 | + |
| 51 | +MongoDB\Driver\Monitoring\removeSubscriber($observer); |
| 52 | + |
| 53 | +?> |
| 54 | +===DONE=== |
| 55 | +<?php exit(0); ?> |
| 56 | +--EXPECTF-- |
| 57 | +Command started: aggregate |
| 58 | +Command started: aggregate |
| 59 | +array(1) { |
| 60 | + [0]=> |
| 61 | + object(stdClass)#%d (2) { |
| 62 | + ["_id"]=> |
| 63 | + int(1) |
| 64 | + ["n"]=> |
| 65 | + int(2) |
| 66 | + } |
| 67 | +} |
| 68 | +===DONE=== |
0 commit comments