1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66
|
--TEST--
Test for PHP-736: MongoClient construction with non-matching RP tag sets
--SKIPIF--
<?php require_once 'tests/utils/replicaset.inc' ?>
--FILE--
<?php
require_once 'tests/utils/server.inc';
$rs = MongoShellServer::getReplicasetInfo();
$mc = new MongoClient($rs['dsn'], array(
'replicaSet' => $rs['rsname'],
'readPreference' => MongoClient::RP_SECONDARY_PREFERRED,
'readPreferenceTags' => array('foo:bar', ''),
));
echo "MongoClient constructed with empty tag set fallback\n";
$c = $mc->selectCollection(dbname(), 'fixtures');
var_dump($c->findOne());
$mc = new MongoClient($rs['dsn'], array(
'replicaSet' => $rs['rsname'],
'readPreference' => MongoClient::RP_SECONDARY_PREFERRED,
'readPreferenceTags' => array('foo:bar'),
));
echo "MongoClient constructed without empty tag set fallback\n";
$c = $mc->selectCollection(dbname(), 'fixtures');
try {
echo "Finding one (should fail, we don't have that tag)\n";
var_dump($c->findOne());
} catch (MongoConnectionException $e) {
printf("error message: %s\n", $e->getMessage());
}
echo "Secondary read, killing that tag\n";
$c->setReadPreference(MongoClient::RP_SECONDARY_PREFERRED, array());
var_dump($c->findOne());
?>
--EXPECTF--
MongoClient constructed with empty tag set fallback
array(2) {
["_id"]=>
object(MongoId)#6 (1) {
["$id"]=>
string(24) "%s"
}
["example"]=>
string(8) "document"
}
MongoClient constructed without empty tag set fallback
Finding one (should fail, we don't have that tag)
error message: No candidate servers found
Secondary read, killing that tag
array(2) {
["_id"]=>
object(MongoId)#7 (1) {
["$id"]=>
string(24) "%s"
}
["example"]=>
string(8) "document"
}
|