Skip to content

Commit bc73a1c

Browse files
committed
PHPC-169: Test read and write concern inheritance
1 parent 7274d49 commit bc73a1c

12 files changed

+490
-0
lines changed
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
--TEST--
2+
MongoDB\Driver\Manager::executeBulkWrite() write concern inheritance
3+
--SKIPIF--
4+
<?php require __DIR__ . "/../utils/basic-skipif.inc"; ?>
5+
<?php skip_if_not_replica_set(); ?>
6+
<?php skip_if_not_enough_data_nodes(2); /* w:2 */ ?>
7+
<?php skip_if_not_clean(); ?>
8+
--FILE--
9+
<?php
10+
require_once __DIR__ . "/../utils/basic.inc";
11+
require_once __DIR__ . "/../utils/observer.php";
12+
13+
$manager = new MongoDB\Driver\Manager(URI, ['w' => 2, 'wtimeoutms' => 1000]);
14+
15+
(new CommandObserver)->observe(
16+
function() use ($manager) {
17+
$bulk = new MongoDB\Driver\BulkWrite;
18+
$bulk->insert(['x' => 1]);
19+
$manager->executeBulkWrite(NS, $bulk);
20+
21+
$bulk = new MongoDB\Driver\BulkWrite;
22+
$bulk->insert(['x' => 1]);
23+
$manager->executeBulkWrite(NS, $bulk, ['writeConcern' => new MongoDB\Driver\WriteConcern(1)]);
24+
},
25+
function(stdClass $command) {
26+
echo json_encode($command->writeConcern), "\n";
27+
}
28+
);
29+
30+
?>
31+
===DONE===
32+
<?php exit(0); ?>
33+
--EXPECT--
34+
{"w":2,"wtimeout":1000}
35+
{"w":1}
36+
===DONE===
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
--TEST--
2+
MongoDB\Driver\Manager::executeCommand() does not inherit read or write concern
3+
--SKIPIF--
4+
<?php require __DIR__ . "/../utils/basic-skipif.inc"; ?>
5+
<?php skip_if_not_replica_set(); ?>
6+
<?php skip_if_not_enough_data_nodes(2); /* w:2 */ ?>
7+
<?php skip_if_server_version('<', '3.6'); /* readConcernLevel:available */ ?>
8+
<?php skip_if_not_clean(); ?>
9+
--FILE--
10+
<?php
11+
require_once __DIR__ . "/../utils/basic.inc";
12+
require_once __DIR__ . "/../utils/observer.php";
13+
14+
$manager = new MongoDB\Driver\Manager(URI, ['readConcernLevel' => 'local', 'w' => 2, 'wtimeoutms' => 1000]);
15+
16+
$command = new MongoDB\Driver\Command([
17+
'aggregate' => COLLECTION_NAME,
18+
'pipeline' => [
19+
['$group' => ['_id' => 1]],
20+
['$out' => COLLECTION_NAME . '.out'],
21+
],
22+
'cursor' => (object) [],
23+
]);
24+
25+
(new CommandObserver)->observe(
26+
function() use ($manager, $command) {
27+
$manager->executeCommand(DATABASE_NAME, $command);
28+
$manager->executeCommand(DATABASE_NAME, $command, [
29+
'readConcern' => new MongoDB\Driver\ReadConcern(MongoDB\Driver\ReadConcern::AVAILABLE),
30+
'writeConcern' => new MongoDB\Driver\WriteConcern(1),
31+
]);
32+
},
33+
function(stdClass $command) {
34+
echo json_encode($command->readConcern ?? null), "\n";
35+
echo json_encode($command->writeConcern ?? null), "\n";
36+
}
37+
);
38+
39+
?>
40+
===DONE===
41+
<?php exit(0); ?>
42+
--EXPECT--
43+
null
44+
null
45+
{"level":"available"}
46+
{"w":1}
47+
===DONE===
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
--TEST--
2+
MongoDB\Driver\Manager::executeQuery() read concern inheritance
3+
--SKIPIF--
4+
<?php require __DIR__ . "/../utils/basic-skipif.inc"; ?>
5+
<?php skip_if_not_replica_set(); ?>
6+
<?php skip_if_server_version('<', '3.6'); /* readConcernLevel:available */ ?>
7+
<?php skip_if_not_clean(); ?>
8+
--FILE--
9+
<?php
10+
require_once __DIR__ . "/../utils/basic.inc";
11+
require_once __DIR__ . "/../utils/observer.php";
12+
13+
$manager = new MongoDB\Driver\Manager(URI, ['readConcernLevel' => 'local']);
14+
15+
(new CommandObserver)->observe(
16+
function() use ($manager) {
17+
$manager->executeQuery(NS, new MongoDB\Driver\Query([]));
18+
$manager->executeQuery(NS, new MongoDB\Driver\Query([], [
19+
'readConcern' => new MongoDB\Driver\ReadConcern(MongoDB\Driver\ReadConcern::AVAILABLE),
20+
]));
21+
},
22+
function(stdClass $command) {
23+
echo json_encode($command->readConcern), "\n";
24+
}
25+
);
26+
27+
?>
28+
===DONE===
29+
<?php exit(0); ?>
30+
--EXPECT--
31+
{"level":"local"}
32+
{"level":"available"}
33+
===DONE===
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
--TEST--
2+
MongoDB\Driver\Manager::executeReadCommand() read concern inheritance
3+
--SKIPIF--
4+
<?php require __DIR__ . "/../utils/basic-skipif.inc"; ?>
5+
<?php skip_if_not_replica_set(); ?>
6+
<?php skip_if_server_version('<', '3.6'); /* readConcernLevel:available */ ?>
7+
<?php skip_if_not_clean(); ?>
8+
--FILE--
9+
<?php
10+
require_once __DIR__ . "/../utils/basic.inc";
11+
require_once __DIR__ . "/../utils/observer.php";
12+
13+
$manager = new MongoDB\Driver\Manager(URI, ['readConcernLevel' => 'local']);
14+
15+
$command = new MongoDB\Driver\Command([
16+
'aggregate' => COLLECTION_NAME,
17+
'pipeline' => [['$group' => ['_id' => 1]]],
18+
'cursor' => (object) [],
19+
]);
20+
21+
(new CommandObserver)->observe(
22+
function() use ($manager, $command) {
23+
$manager->executeReadCommand(DATABASE_NAME, $command);
24+
$manager->executeReadCommand(DATABASE_NAME, $command, [
25+
'readConcern' => new MongoDB\Driver\ReadConcern(MongoDB\Driver\ReadConcern::AVAILABLE),
26+
]);
27+
},
28+
function(stdClass $command) {
29+
echo json_encode($command->readConcern), "\n";
30+
}
31+
);
32+
33+
?>
34+
===DONE===
35+
<?php exit(0); ?>
36+
--EXPECT--
37+
{"level":"local"}
38+
{"level":"available"}
39+
===DONE===
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
--TEST--
2+
MongoDB\Driver\Manager::executeReadWriteCommand() read and write concern inheritance
3+
--SKIPIF--
4+
<?php require __DIR__ . "/../utils/basic-skipif.inc"; ?>
5+
<?php skip_if_not_replica_set(); ?>
6+
<?php skip_if_not_enough_data_nodes(2); /* w:2 */ ?>
7+
<?php skip_if_server_version('<', '3.6'); /* readConcernLevel:available */ ?>
8+
<?php skip_if_not_clean(); ?>
9+
--FILE--
10+
<?php
11+
require_once __DIR__ . "/../utils/basic.inc";
12+
require_once __DIR__ . "/../utils/observer.php";
13+
14+
$manager = new MongoDB\Driver\Manager(URI, ['readConcernLevel' => 'local', 'w' => 2, 'wtimeoutms' => 1000]);
15+
16+
$command = new MongoDB\Driver\Command([
17+
'aggregate' => COLLECTION_NAME,
18+
'pipeline' => [
19+
['$group' => ['_id' => 1]],
20+
['$out' => COLLECTION_NAME . '.out'],
21+
],
22+
'cursor' => (object) [],
23+
]);
24+
25+
(new CommandObserver)->observe(
26+
function() use ($manager, $command) {
27+
$manager->executeReadWriteCommand(DATABASE_NAME, $command);
28+
$manager->executeReadWriteCommand(DATABASE_NAME, $command, [
29+
'readConcern' => new MongoDB\Driver\ReadConcern(MongoDB\Driver\ReadConcern::AVAILABLE),
30+
'writeConcern' => new MongoDB\Driver\WriteConcern(1),
31+
]);
32+
},
33+
function(stdClass $command) {
34+
echo json_encode($command->readConcern), "\n";
35+
echo json_encode($command->writeConcern), "\n";
36+
}
37+
);
38+
39+
?>
40+
===DONE===
41+
<?php exit(0); ?>
42+
--EXPECT--
43+
{"level":"local"}
44+
{"w":2,"wtimeout":1000}
45+
{"level":"available"}
46+
{"w":1}
47+
===DONE===
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
--TEST--
2+
MongoDB\Driver\Manager::executeWriteCommand() write concern inheritance
3+
--SKIPIF--
4+
<?php require __DIR__ . "/../utils/basic-skipif.inc"; ?>
5+
<?php skip_if_not_replica_set(); ?>
6+
<?php skip_if_not_enough_data_nodes(2); /* w:2 */ ?>
7+
<?php skip_if_server_version('<', '3.2'); /* findAndModify writeConcern */ ?>
8+
<?php skip_if_not_clean(); ?>
9+
--FILE--
10+
<?php
11+
require_once __DIR__ . "/../utils/basic.inc";
12+
require_once __DIR__ . "/../utils/observer.php";
13+
14+
$manager = new MongoDB\Driver\Manager(URI, ['w' => 2, 'wtimeoutms' => 1000]);
15+
16+
$command = new MongoDB\Driver\Command([
17+
'findAndModify' => COLLECTION_NAME,
18+
'query' => ['x' => 1],
19+
'upsert' => true,
20+
'new' => true,
21+
'update' => ['$inc' => ['x' => 1]],
22+
]);
23+
24+
(new CommandObserver)->observe(
25+
function() use ($manager, $command) {
26+
$manager->executeWriteCommand(DATABASE_NAME, $command);
27+
$manager->executeWriteCommand(DATABASE_NAME, $command, ['writeConcern' => new MongoDB\Driver\WriteConcern(1)]);
28+
},
29+
function(stdClass $command) {
30+
echo json_encode($command->writeConcern), "\n";
31+
}
32+
);
33+
34+
?>
35+
===DONE===
36+
<?php exit(0); ?>
37+
--EXPECT--
38+
{"w":2,"wtimeout":1000}
39+
{"w":1}
40+
===DONE===
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
--TEST--
2+
MongoDB\Driver\Server::executeBulkWrite() write concern inheritance
3+
--SKIPIF--
4+
<?php require __DIR__ . "/../utils/basic-skipif.inc"; ?>
5+
<?php skip_if_not_replica_set(); ?>
6+
<?php skip_if_not_enough_data_nodes(2); /* w:2 */ ?>
7+
<?php skip_if_not_clean(); ?>
8+
--FILE--
9+
<?php
10+
require_once __DIR__ . "/../utils/basic.inc";
11+
require_once __DIR__ . "/../utils/observer.php";
12+
13+
$manager = new MongoDB\Driver\Manager(URI, ['w' => 2, 'wtimeoutms' => 1000]);
14+
$server = $manager->selectServer(new MongoDB\Driver\ReadPreference('primary'));
15+
16+
(new CommandObserver)->observe(
17+
function() use ($server) {
18+
$bulk = new MongoDB\Driver\BulkWrite;
19+
$bulk->insert(['x' => 1]);
20+
$server->executeBulkWrite(NS, $bulk);
21+
22+
$bulk = new MongoDB\Driver\BulkWrite;
23+
$bulk->insert(['x' => 1]);
24+
$server->executeBulkWrite(NS, $bulk, ['writeConcern' => new MongoDB\Driver\WriteConcern(1)]);
25+
},
26+
function(stdClass $command) {
27+
echo json_encode($command->writeConcern), "\n";
28+
}
29+
);
30+
31+
?>
32+
===DONE===
33+
<?php exit(0); ?>
34+
--EXPECT--
35+
{"w":2,"wtimeout":1000}
36+
{"w":1}
37+
===DONE===
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
--TEST--
2+
MongoDB\Driver\Server::executeCommand() does not inherit read or write concern
3+
--SKIPIF--
4+
<?php require __DIR__ . "/../utils/basic-skipif.inc"; ?>
5+
<?php skip_if_not_replica_set(); ?>
6+
<?php skip_if_not_enough_data_nodes(2); /* w:2 */ ?>
7+
<?php skip_if_server_version('<', '3.6'); /* readConcernLevel:available */ ?>
8+
<?php skip_if_not_clean(); ?>
9+
--FILE--
10+
<?php
11+
require_once __DIR__ . "/../utils/basic.inc";
12+
require_once __DIR__ . "/../utils/observer.php";
13+
14+
$manager = new MongoDB\Driver\Manager(URI, ['readConcernLevel' => 'local', 'w' => 2, 'wtimeoutms' => 1000]);
15+
$server = $manager->selectServer(new MongoDB\Driver\ReadPreference('primary'));
16+
17+
$command = new MongoDB\Driver\Command([
18+
'aggregate' => COLLECTION_NAME,
19+
'pipeline' => [
20+
['$group' => ['_id' => 1]],
21+
['$out' => COLLECTION_NAME . '.out'],
22+
],
23+
'cursor' => (object) [],
24+
]);
25+
26+
(new CommandObserver)->observe(
27+
function() use ($server, $command) {
28+
$server->executeCommand(DATABASE_NAME, $command);
29+
$server->executeCommand(DATABASE_NAME, $command, [
30+
'readConcern' => new MongoDB\Driver\ReadConcern(MongoDB\Driver\ReadConcern::AVAILABLE),
31+
'writeConcern' => new MongoDB\Driver\WriteConcern(1),
32+
]);
33+
},
34+
function(stdClass $command) {
35+
echo json_encode($command->readConcern ?? null), "\n";
36+
echo json_encode($command->writeConcern ?? null), "\n";
37+
}
38+
);
39+
40+
?>
41+
===DONE===
42+
<?php exit(0); ?>
43+
--EXPECT--
44+
null
45+
null
46+
{"level":"available"}
47+
{"w":1}
48+
===DONE===
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
--TEST--
2+
MongoDB\Driver\Server::executeQuery() read concern inheritance
3+
--SKIPIF--
4+
<?php require __DIR__ . "/../utils/basic-skipif.inc"; ?>
5+
<?php skip_if_not_replica_set(); ?>
6+
<?php skip_if_server_version('<', '3.6'); /* readConcernLevel:available */ ?>
7+
<?php skip_if_not_clean(); ?>
8+
--FILE--
9+
<?php
10+
require_once __DIR__ . "/../utils/basic.inc";
11+
require_once __DIR__ . "/../utils/observer.php";
12+
13+
$manager = new MongoDB\Driver\Manager(URI, ['readConcernLevel' => 'local']);
14+
$server = $manager->selectServer(new MongoDB\Driver\ReadPreference('primary'));
15+
16+
(new CommandObserver)->observe(
17+
function() use ($server) {
18+
$server->executeQuery(NS, new MongoDB\Driver\Query([]));
19+
$server->executeQuery(NS, new MongoDB\Driver\Query([], [
20+
'readConcern' => new MongoDB\Driver\ReadConcern(MongoDB\Driver\ReadConcern::AVAILABLE),
21+
]));
22+
},
23+
function(stdClass $command) {
24+
echo json_encode($command->readConcern), "\n";
25+
}
26+
);
27+
28+
?>
29+
===DONE===
30+
<?php exit(0); ?>
31+
--EXPECT--
32+
{"level":"local"}
33+
{"level":"available"}
34+
===DONE===

0 commit comments

Comments
 (0)