|
| 1 | +--TEST-- |
| 2 | +MongoDB\Driver\Server: Manager->getServer() returning correct server |
| 3 | +--SKIPIF-- |
| 4 | +<?php require "tests/utils/basic-skipif.inc"; CLEANUP(REPLICASET); ?> |
| 5 | +--FILE-- |
| 6 | +<?php |
| 7 | +require_once "tests/utils/basic.inc"; |
| 8 | + |
| 9 | +$manager = new MongoDB\Driver\Manager(REPLICASET); |
| 10 | + |
| 11 | + |
| 12 | +$doc = array("example" => "document"); |
| 13 | +$bulk = new \MongoDB\Driver\BulkWrite(); |
| 14 | +$bulk->insert($doc); |
| 15 | +$wresult = $manager->executeBulkWrite(NS, $bulk); |
| 16 | + |
| 17 | +$bulk = new \MongoDB\Driver\BulkWrite(); |
| 18 | +$bulk->insert($doc); |
| 19 | + |
| 20 | +/* writes go to the primary */ |
| 21 | +$server = $wresult->getServer(); |
| 22 | +/* This is the same server */ |
| 23 | +$server2 = $server->executeBulkWrite(NS, $bulk)->getServer(); |
| 24 | + |
| 25 | +/* Both are the primary, e.g. the same server */ |
| 26 | +var_dump($server == $server2); |
| 27 | + |
| 28 | + |
| 29 | +$rp = new MongoDB\Driver\ReadPreference(MongoDB\Driver\ReadPreference::RP_SECONDARY); |
| 30 | +/* Fetch a secondary */ |
| 31 | +$server3 = $manager->executeQuery(NS, new MongoDB\Driver\Query(array()), $rp)->getServer(); |
| 32 | + |
| 33 | +var_dump($server == $server3); |
| 34 | +var_dump($server->getPort(), $server3->getPort()); |
| 35 | + |
| 36 | + |
| 37 | +$bulk = new \MongoDB\Driver\BulkWrite(); |
| 38 | +$bulk->insert($doc); |
| 39 | + |
| 40 | +$result = $server3->executeBulkWrite("local.examples", $bulk); |
| 41 | +var_dump($result, $result->getServer()->getHost(), $result->getServer()->getPort()); |
| 42 | +$result = $server3->executeQuery("local.examples", new MongoDB\Driver\Query(array())); |
| 43 | +foreach($result as $document) { |
| 44 | + var_dump($document); |
| 45 | +} |
| 46 | +$cmd = new MongoDB\Driver\Command(array("drop" => "examples")); |
| 47 | +$server3->executeCommand("local", $cmd); |
| 48 | + |
| 49 | +throws(function() use ($server3, $bulk) { |
| 50 | + $result = $server3->executeBulkWrite(NS, $bulk); |
| 51 | +}, "MongoDB\\Driver\\RuntimeException"); |
| 52 | + |
| 53 | +?> |
| 54 | +===DONE=== |
| 55 | +<?php exit(0); ?> |
| 56 | +--EXPECTF-- |
| 57 | +bool(true) |
| 58 | +bool(false) |
| 59 | +int(3000) |
| 60 | +int(3001) |
| 61 | +object(MongoDB\Driver\WriteResult)#%d (%d) { |
| 62 | + ["nInserted"]=> |
| 63 | + int(1) |
| 64 | + ["nMatched"]=> |
| 65 | + int(0) |
| 66 | + ["nModified"]=> |
| 67 | + int(0) |
| 68 | + ["nRemoved"]=> |
| 69 | + int(0) |
| 70 | + ["nUpserted"]=> |
| 71 | + int(0) |
| 72 | + ["upsertedIds"]=> |
| 73 | + array(0) { |
| 74 | + } |
| 75 | + ["writeErrors"]=> |
| 76 | + array(0) { |
| 77 | + } |
| 78 | + ["writeConcernError"]=> |
| 79 | + array(0) { |
| 80 | + } |
| 81 | + ["writeConcern"]=> |
| 82 | + array(4) { |
| 83 | + ["wmajority"]=> |
| 84 | + bool(false) |
| 85 | + ["wtimeout"]=> |
| 86 | + int(0) |
| 87 | + ["fsync"]=> |
| 88 | + bool(false) |
| 89 | + ["journal"]=> |
| 90 | + bool(false) |
| 91 | + } |
| 92 | +} |
| 93 | +string(14) "192.168.112.10" |
| 94 | +int(3001) |
| 95 | +array(2) { |
| 96 | + ["_id"]=> |
| 97 | + object(BSON\ObjectID)#%d (1) { |
| 98 | + ["oid"]=> |
| 99 | + string(24) "%s" |
| 100 | + } |
| 101 | + ["example"]=> |
| 102 | + string(8) "document" |
| 103 | +} |
| 104 | +OK: Got MongoDB\Driver\RuntimeException |
| 105 | +===DONE=== |
0 commit comments