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 67 68 69 70 71 72 73 74
|
--TEST--
MongoClient::insert() 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();
$mc = new MongoClient($rs["dsn"], array("replicaSet" => $rs["rsname"]));
$coll = $mc->selectCollection("failover", "test1");
for($i = 0; $i < 10; $i++) {
/* Just to make sure master is working fine */
try {
$coll->insert(array("doc" => $i));
} catch(Exception $e) {
echo "This was not supposed to happen!!!\n";
var_dump(get_class($e), $e->getMessage(), $e->getCode());
}
}
$i++;
echo "Killing master\n";
$server->killMaster();
echo "Master killed\n";
try {
$coll->insert(array("doc" => $i));
echo "That query should have failed\n";
} catch(MongoCursorException $e) {
var_dump($e->getMessage(), $e->getCode());
}
for(; $i < 20; $i++) {
try {
$coll->insert(array("doc" => $i));
echo "That query probably should have failed\n";
} catch(MongoCursorException $e) {
var_dump($e->getMessage(), $e->getCode());
}
}
for($i=0;$i<60; $i++) {
try {
$coll->insert(array("doc" => $i));
echo "Found master again\n";
break;
} catch(MongoCursorException $e) {
}
}
?>
--CLEAN--
<?php require_once "tests/utils/fix-master.inc"; ?>
--EXPECTF--
Killing master
Master killed
string(%d) "%s:%d: %s"
int(32)
string(51) "Couldn't get connection: No candidate servers found"
int(16)
string(51) "Couldn't get connection: No candidate servers found"
int(16)
string(51) "Couldn't get connection: No candidate servers found"
int(16)
string(51) "Couldn't get connection: No candidate servers found"
int(16)
string(51) "Couldn't get connection: No candidate servers found"
int(16)
string(51) "Couldn't get connection: No candidate servers found"
int(16)
string(51) "Couldn't get connection: No candidate servers found"
int(16)
string(51) "Couldn't get connection: No candidate servers found"
int(16)
string(51) "Couldn't get connection: No candidate servers found"
int(16)
|