mirror of
https://github.com/macintoshplus/mongo-php-driver.git
synced 2026-04-29 11:33:12 +02:00
Merge pull request #316
This commit is contained in:
+7
-4
@@ -644,8 +644,9 @@ int phongo_execute_query(mongoc_client_t *client, const char *namespace, const p
|
||||
return false;
|
||||
}
|
||||
|
||||
if (server_id > 0) {
|
||||
cursor->server_id = server_id;
|
||||
if (server_id > 0 && !mongoc_cursor_set_hint(cursor, server_id)) {
|
||||
phongo_throw_exception(PHONGO_ERROR_MONGOC_FAILED TSRMLS_CC, "%s", "Could not set cursor server_id");
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!phongo_advance_cursor_and_check_for_error(cursor TSRMLS_CC)) {
|
||||
@@ -668,8 +669,10 @@ int phongo_execute_command(mongoc_client_t *client, const char *db, const bson_t
|
||||
|
||||
|
||||
cursor = mongoc_client_command(client, db, MONGOC_QUERY_NONE, 0, 1, 0, command, NULL, read_preference);
|
||||
if (server_id > 0) {
|
||||
cursor->server_id = server_id;
|
||||
|
||||
if (server_id > 0 && !mongoc_cursor_set_hint(cursor, server_id)) {
|
||||
phongo_throw_exception(PHONGO_ERROR_MONGOC_FAILED TSRMLS_CC, "%s", "Could not set cursor server_id");
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!phongo_advance_cursor_and_check_for_error(cursor TSRMLS_CC)) {
|
||||
|
||||
@@ -59,7 +59,7 @@ object(MongoDB\Driver\Cursor)#%d (%d) {
|
||||
}
|
||||
}
|
||||
["flags"]=>
|
||||
int(0)
|
||||
int(4)
|
||||
["skip"]=>
|
||||
int(0)
|
||||
["limit"]=>
|
||||
|
||||
@@ -0,0 +1,33 @@
|
||||
--TEST--
|
||||
MongoDB\Driver\Server::executeCommand() with conflicting read preference for secondary
|
||||
--SKIPIF--
|
||||
<?php require __DIR__ . "/../utils/basic-skipif.inc"; NEEDS("REPLICASET"); ?>
|
||||
--FILE--
|
||||
<?php
|
||||
require_once __DIR__ . "/../utils/basic.inc";
|
||||
|
||||
$manager = new MongoDB\Driver\Manager(REPLICASET);
|
||||
|
||||
$secondaryRp = new MongoDB\Driver\ReadPreference(MongoDB\Driver\ReadPreference::RP_SECONDARY);
|
||||
$secondary = $manager->selectServer($secondaryRp);
|
||||
|
||||
/* Note: this is testing that the read preference (even a conflicting one) has
|
||||
* no effect when directly querying a server, since the slaveOk flag is always
|
||||
* set for hinted commands. */
|
||||
$primaryRp = new MongoDB\Driver\ReadPreference(MongoDB\Driver\ReadPreference::RP_PRIMARY);
|
||||
$cursor = $secondary->executeCommand(DATABASE_NAME, new MongoDB\Driver\Command(array('ping' => 1)), $primaryRp);
|
||||
|
||||
var_dump($cursor->toArray());
|
||||
|
||||
?>
|
||||
===DONE===
|
||||
<?php exit(0); ?>
|
||||
--EXPECTF--
|
||||
array(1) {
|
||||
[0]=>
|
||||
object(stdClass)#%d (%d) {
|
||||
["ok"]=>
|
||||
float(1)
|
||||
}
|
||||
}
|
||||
===DONE===
|
||||
@@ -1,25 +0,0 @@
|
||||
--TEST--
|
||||
MongoDB\Driver\Server::executeCommand() with conflicting read preference for secondary
|
||||
--SKIPIF--
|
||||
<?php require __DIR__ . "/../utils/basic-skipif.inc"; NEEDS("REPLICASET"); ?>
|
||||
--FILE--
|
||||
<?php
|
||||
require_once __DIR__ . "/../utils/basic.inc";
|
||||
|
||||
$manager = new MongoDB\Driver\Manager(REPLICASET);
|
||||
|
||||
$rp = new MongoDB\Driver\ReadPreference(MongoDB\Driver\ReadPreference::RP_SECONDARY);
|
||||
$secondary = $manager->selectServer($rp);
|
||||
|
||||
echo throws(function() use ($secondary) {
|
||||
$rp = new MongoDB\Driver\ReadPreference(MongoDB\Driver\ReadPreference::RP_PRIMARY);
|
||||
$secondary->executeCommand(NS, new MongoDB\Driver\Command(array('ping' => 1)), $rp);
|
||||
}, "MongoDB\Driver\Exception\RuntimeException"), "\n";
|
||||
|
||||
?>
|
||||
===DONE===
|
||||
<?php exit(0); ?>
|
||||
--EXPECT--
|
||||
OK: Got MongoDB\Driver\Exception\RuntimeException
|
||||
not master and slaveOk=false
|
||||
===DONE===
|
||||
@@ -0,0 +1,41 @@
|
||||
--TEST--
|
||||
MongoDB\Driver\Server::executeQuery() with conflicting read preference for secondary
|
||||
--SKIPIF--
|
||||
<?php require __DIR__ . "/../utils/basic-skipif.inc"; NEEDS("REPLICASET"); CLEANUP(REPLICASET); ?>
|
||||
--FILE--
|
||||
<?php
|
||||
require_once __DIR__ . "/../utils/basic.inc";
|
||||
|
||||
$manager = new MongoDB\Driver\Manager(REPLICASET);
|
||||
|
||||
$primaryRp = new MongoDB\Driver\ReadPreference(MongoDB\Driver\ReadPreference::RP_PRIMARY);
|
||||
$primary = $manager->selectServer($primaryRp);
|
||||
|
||||
$bulk = new \MongoDB\Driver\BulkWrite;
|
||||
$bulk->insert(['_id' => 1, 'x' => 1]);
|
||||
$primary->executeBulkWrite(NS, $bulk, new MongoDB\Driver\WriteConcern(MongoDB\Driver\WriteConcern::MAJORITY));
|
||||
|
||||
$secondaryRp = new MongoDB\Driver\ReadPreference(MongoDB\Driver\ReadPreference::RP_SECONDARY);
|
||||
$secondary = $manager->selectServer($secondaryRp);
|
||||
|
||||
/* Note: this is testing that the read preference (even a conflicting one) has
|
||||
* no effect when directly querying a server, since the slaveOk flag is always
|
||||
* set for hinted queries. */
|
||||
$cursor = $secondary->executeQuery(NS, new MongoDB\Driver\Query(['x' => 1]), $primaryRp);
|
||||
|
||||
var_dump($cursor->toArray());
|
||||
|
||||
?>
|
||||
===DONE===
|
||||
<?php exit(0); ?>(
|
||||
--EXPECTF--
|
||||
array(1) {
|
||||
[0]=>
|
||||
object(stdClass)#%d (%d) {
|
||||
["_id"]=>
|
||||
int(1)
|
||||
["x"]=>
|
||||
int(1)
|
||||
}
|
||||
}
|
||||
===DONE===
|
||||
@@ -1,25 +0,0 @@
|
||||
--TEST--
|
||||
MongoDB\Driver\Server::executeQuery() with conflicting read preference for secondary
|
||||
--SKIPIF--
|
||||
<?php require __DIR__ . "/../utils/basic-skipif.inc"; NEEDS("REPLICASET"); ?>
|
||||
--FILE--
|
||||
<?php
|
||||
require_once __DIR__ . "/../utils/basic.inc";
|
||||
|
||||
$manager = new MongoDB\Driver\Manager(REPLICASET);
|
||||
|
||||
$rp = new MongoDB\Driver\ReadPreference(MongoDB\Driver\ReadPreference::RP_SECONDARY);
|
||||
$secondary = $manager->selectServer($rp);
|
||||
|
||||
echo throws(function() use ($secondary) {
|
||||
$rp = new MongoDB\Driver\ReadPreference(MongoDB\Driver\ReadPreference::RP_PRIMARY);
|
||||
$secondary->executeQuery(NS, new MongoDB\Driver\Query(array("x" => 1)), $rp);
|
||||
}, "MongoDB\Driver\Exception\RuntimeException"), "\n";
|
||||
|
||||
?>
|
||||
===DONE===
|
||||
<?php exit(0); ?>
|
||||
--EXPECT--
|
||||
OK: Got MongoDB\Driver\Exception\RuntimeException
|
||||
not master and slaveOk=false
|
||||
===DONE===
|
||||
Reference in New Issue
Block a user