|
| 1 | +--TEST-- |
| 2 | +MongoDB\Driver\Server::executeCommand() does not send read preference to standalone |
| 3 | +--SKIPIF-- |
| 4 | +<?php require __DIR__ . "/../utils/basic-skipif.inc"; ?> |
| 5 | +<?php skip_if_not_live(); ?> |
| 6 | +<?php skip_if_not_standalone(); ?> |
| 7 | +<?php skip_if_not_clean(); ?> |
| 8 | +<?php skip_if_server_version('<', '3.6'); ?> |
| 9 | +--FILE-- |
| 10 | +<?php |
| 11 | +require_once __DIR__ . "/../utils/basic.inc"; |
| 12 | +require_once __DIR__ . "/../utils/observer.php"; |
| 13 | + |
| 14 | +$manager = new MongoDB\Driver\Manager(URI); |
| 15 | +$server = $manager->selectServer(new MongoDB\Driver\ReadPreference(MongoDB\Driver\ReadPreference::RP_PRIMARY)); |
| 16 | + |
| 17 | +(new CommandObserver)->observe( |
| 18 | + function() use ($server) { |
| 19 | + $command = new MongoDB\Driver\Command([ |
| 20 | + 'ping' => true, |
| 21 | + ]); |
| 22 | + |
| 23 | + try { |
| 24 | + $server->executeCommand( |
| 25 | + DATABASE_NAME, |
| 26 | + $command, |
| 27 | + [ |
| 28 | + 'readPreference' => new \MongoDB\Driver\ReadPreference(\MongoDB\Driver\ReadPreference::RP_SECONDARY), |
| 29 | + 'readConcern' => new \MongoDB\Driver\ReadConcern(\MongoDB\Driver\ReadConcern::LOCAL), |
| 30 | + 'writeConcern' => new \MongoDB\Driver\WriteConcern(\MongoDB\Driver\WriteConcern::MAJORITY), |
| 31 | + ] |
| 32 | + ); |
| 33 | + } catch ( Exception $e ) { |
| 34 | + // Ignore exception that ping doesn't support writeConcern |
| 35 | + } |
| 36 | + }, |
| 37 | + function(stdClass $command) { |
| 38 | + echo isset($command->{'$readPreference'}) ? 'Read preference set' : 'No read preference set', "\n"; |
| 39 | + echo "Read Concern: ", $command->readConcern->level, "\n"; |
| 40 | + echo "Write Concern: ", $command->writeConcern->w, "\n"; |
| 41 | + } |
| 42 | +); |
| 43 | + |
| 44 | +?> |
| 45 | +===DONE=== |
| 46 | +<?php exit(0); ?> |
| 47 | +--EXPECTF-- |
| 48 | +No read preference set |
| 49 | +Read Concern: local |
| 50 | +Write Concern: majority |
| 51 | +===DONE=== |
0 commit comments