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
|
--TEST--
MongoClient::__construct() during failover (1)
--SKIPIF--
<?php require_once "tests/utils/replicaset-failover.inc" ?>
--FILE--
<?php
require_once "tests/utils/server.inc";
$server = new MongoShellServer;
$rs = $server->getReplicasetConfig();
/* Just to have some data to read */
$mc = new MongoClient($rs["dsn"], array("replicaSet" => $rs["rsname"]));
$coll = $mc->selectCollection("ctorfailover", "test1");
$data = array("x" => "The world is not enough");
$coll->insert($data);
$id = $data["_id"];
$coll->insert(array("something" => "else"), array("w" => 4));
$coll = $mc = null;
echo "About to kill master\n";
$server->killMaster();
echo "Master killed\n";
for($i = 0; $i<10; $i++) {
try {
$mc = new MongoClient($rs["dsn"], array("replicaSet" => $rs["rsname"], "readPreference" => MongoClient::RP_SECONDARY));
$coll = $mc->selectCollection("ctorfailover", "test1");
$data = $coll->findOne(array("_id" => $id));
var_dump($data["x"]);
} catch(Exception $e) {
var_dump(get_class($e), $e->getMessage(), $e->getCode());
}
}
try {
$mc = new MongoClient($rs["dsn"], array("replicaSet" => $rs["rsname"]));
$coll = $mc->selectCollection("ctorfailover", "test1");
$data = $coll->findOne(array("_id" => $id));
echo "Primary is up for some reason, that shouldn't have happened!\n";
} catch(Exception $e) {
var_dump(get_class($e), $e->getMessage(), $e->getCode());
}
?>
--CLEAN--
<?php require_once "tests/utils/fix-master.inc"; ?>
--EXPECTF--
About to kill master
Master killed
string(23) "The world is not enough"
string(23) "The world is not enough"
string(23) "The world is not enough"
string(23) "The world is not enough"
string(23) "The world is not enough"
string(23) "The world is not enough"
string(23) "The world is not enough"
string(23) "The world is not enough"
string(23) "The world is not enough"
string(23) "The world is not enough"
string(20) "MongoCursorException"
string(%d) "%s:%d: Remote server has closed the connection"
int(32)
|