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
|
--TEST--
MongoInsertBatch::execute() during failover
--SKIPIF--
<?php $needs = "2.5.5"; ?>
<?php if (!MONGO_STREAMS) { echo "skip This test requires streams support"; } ?>
<?php if ( ! class_exists('MongoWriteBatch')) { exit('skip This test requires MongoWriteBatch classes'); } ?>
<?php require_once "tests/utils/replicaset-failover.inc" ?>
--FILE--
<?php
require_once "tests/utils/server.inc";
function get_primary_maxWriteBatchSize(MongoClient $mc) {
foreach ($mc->getConnections() as $c) {
if ($c['connection']['connection_type'] == 2) {
return $c['connection']['max_write_batch_size'];
}
}
throw new Exception('Cannot get maxWriteBatchSize; no primary found!');
}
$server = new MongoShellServer;
$rs = $server->getReplicasetConfig();
function log_reply() {
global $server;
static $i = 0;
printf("Received reply from batch: %d\n", ++$i);
if ($i === 1) {
echo "Killing master\n";
$server->killMaster();
echo "Master killed\n";
}
}
$ctx = stream_context_create(array("mongodb" => array(
"log_reply" => "log_reply",
)));
$mc = new MongoClient($rs["dsn"], array("replicaSet" => $rs["rsname"]), array("context" => $ctx));
$collection = $mc->selectCollection(dbname(), collname(__FILE__));
$collection->drop();
$batch = new MongoInsertBatch($collection);
$maxWriteBatchSize = get_primary_maxWriteBatchSize($mc);
for ($i = 0; $i < $maxWriteBatchSize + 1; $i++) {
$batch->add(array('x' => $i));
}
try {
$batch->execute(array('w' => 1));
echo "Write succeeded without a primary!\n";
} catch(MongoCursorException $e) {
var_dump($e->getMessage(), $e->getCode());
}
?>
--CLEAN--
<?php require_once "tests/utils/fix-master.inc"; ?>
--EXPECTF--
Received reply from batch: 1
Killing master
Master killed
string(%d) "%s:%d: Remote server has closed the connection"
int(32)
|