Skip to content

Commit 93185b7

Browse files
committed
Merged pull request #902
2 parents 5383ca0 + 9ade9ab commit 93185b7

4 files changed

+178
-6
lines changed

tests/session/transaction-integration_error-001.phpt

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
--TEST--
2-
MongoDB\Driver\Session: Setting per-op readConcern or writeConcern in transaction
2+
MongoDB\Driver\Session: Setting per-op readConcern or writeConcern in transaction (executeCommand)
33
--SKIPIF--
44
<?php require __DIR__ . "/../utils/basic-skipif.inc"; ?>
55
<?php skip_if_not_libmongoc_crypto(); ?>
@@ -37,8 +37,8 @@ echo throws(function() use ($manager, $session) {
3737
DATABASE_NAME,
3838
$cmd,
3939
[
40-
'session' => $session,
41-
'readConcern' => new \MongoDB\Driver\ReadConcern( \MongoDB\Driver\ReadConcern::LOCAL )
40+
'session' => $session,
41+
'readConcern' => new \MongoDB\Driver\ReadConcern( \MongoDB\Driver\ReadConcern::LOCAL )
4242
]
4343
);
4444
}, "MongoDB\Driver\Exception\InvalidArgumentException"), "\n";
@@ -52,9 +52,8 @@ echo throws(function() use ($manager, $session) {
5252
DATABASE_NAME,
5353
$cmd,
5454
[
55-
'session' => $session,
56-
'writeConcern' => new \MongoDB\Driver\WriteConcern(
57-
\MongoDB\Driver\WriteConcern::MAJORITY )
55+
'session' => $session,
56+
'writeConcern' => new \MongoDB\Driver\WriteConcern( \MongoDB\Driver\WriteConcern::MAJORITY )
5857
]
5958
);
6059
}, "MongoDB\Driver\Exception\InvalidArgumentException"), "\n";
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
--TEST--
2+
MongoDB\Driver\Session: Setting per-op readConcern in transaction (executeReadCommand)
3+
--SKIPIF--
4+
<?php require __DIR__ . "/../utils/basic-skipif.inc"; ?>
5+
<?php skip_if_not_libmongoc_crypto(); ?>
6+
<?php skip_if_not_replica_set(); ?>
7+
<?php skip_if_server_version('<', '4.0'); ?>
8+
<?php skip_if_not_clean(); ?>
9+
--FILE--
10+
<?php
11+
require_once __DIR__ . "/../utils/basic.inc";
12+
13+
$manager = new MongoDB\Driver\Manager(URI);
14+
15+
/* Create collections as that can't be (automatically) done in a transaction */
16+
$manager->executeCommand(
17+
DATABASE_NAME,
18+
new \MongoDB\Driver\Command([ 'create' => COLLECTION_NAME ]),
19+
[ 'writeConcern' => new \MongoDB\Driver\WriteConcern( \MongoDB\Driver\WriteConcern::MAJORITY ) ]
20+
);
21+
22+
23+
/* Do the transaction */
24+
$session = $manager->startSession();
25+
26+
$session->startTransaction( [
27+
'readConcern' => new \MongoDB\Driver\ReadConcern( "snapshot" ),
28+
'writeConcern' => new \MongoDB\Driver\WriteConcern( \MongoDB\Driver\WriteConcern::MAJORITY )
29+
] );
30+
31+
echo throws(function() use ($manager, $session) {
32+
$cmd = new \MongoDB\Driver\Command( [
33+
'count' => COLLECTION_NAME,
34+
'query' => [ 'q' => [ 'employee' => 3 ] ]
35+
] );
36+
$manager->executeReadCommand(
37+
DATABASE_NAME,
38+
$cmd,
39+
[
40+
'session' => $session,
41+
'readConcern' => new \MongoDB\Driver\ReadConcern( \MongoDB\Driver\ReadConcern::LOCAL )
42+
]
43+
);
44+
}, "MongoDB\Driver\Exception\InvalidArgumentException"), "\n";
45+
46+
?>
47+
===DONE===
48+
<?php exit(0); ?>
49+
--EXPECT--
50+
OK: Got MongoDB\Driver\Exception\InvalidArgumentException
51+
Cannot set read concern after starting transaction
52+
===DONE===
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
--TEST--
2+
MongoDB\Driver\Session: Setting per-op writeConcern in transaction (executeWriteCommand)
3+
--SKIPIF--
4+
<?php require __DIR__ . "/../utils/basic-skipif.inc"; ?>
5+
<?php skip_if_not_libmongoc_crypto(); ?>
6+
<?php skip_if_not_replica_set(); ?>
7+
<?php skip_if_server_version('<', '4.0'); ?>
8+
<?php skip_if_not_clean(); ?>
9+
--FILE--
10+
<?php
11+
require_once __DIR__ . "/../utils/basic.inc";
12+
13+
$manager = new MongoDB\Driver\Manager(URI);
14+
15+
/* Create collections as that can't be (automatically) done in a transaction */
16+
$manager->executeCommand(
17+
DATABASE_NAME,
18+
new \MongoDB\Driver\Command([ 'create' => COLLECTION_NAME ]),
19+
[ 'writeConcern' => new \MongoDB\Driver\WriteConcern( \MongoDB\Driver\WriteConcern::MAJORITY ) ]
20+
);
21+
22+
23+
/* Do the transaction */
24+
$session = $manager->startSession();
25+
26+
$session->startTransaction( [
27+
'readConcern' => new \MongoDB\Driver\ReadConcern( "snapshot" ),
28+
'writeConcern' => new \MongoDB\Driver\WriteConcern( \MongoDB\Driver\WriteConcern::MAJORITY )
29+
] );
30+
31+
echo throws(function() use ($manager, $session) {
32+
$cmd = new \MongoDB\Driver\Command( [
33+
'update' => COLLECTION_NAME,
34+
'updates' => [ [ 'q' => [ 'employee' => 3 ], 'u' => [ '$set' => [ 'status' => 'Inactive' ] ] ] ]
35+
] );
36+
$manager->executeWriteCommand(
37+
DATABASE_NAME,
38+
$cmd,
39+
[
40+
'session' => $session,
41+
'writeConcern' => new \MongoDB\Driver\WriteConcern( \MongoDB\Driver\WriteConcern::MAJORITY )
42+
]
43+
);
44+
}, "MongoDB\Driver\Exception\InvalidArgumentException"), "\n";
45+
46+
?>
47+
===DONE===
48+
<?php exit(0); ?>
49+
--EXPECT--
50+
OK: Got MongoDB\Driver\Exception\InvalidArgumentException
51+
Cannot set write concern after starting transaction
52+
===DONE===
Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
--TEST--
2+
MongoDB\Driver\Session: Setting per-op readConcern or writeConcern in transaction (executeReadWriteCommand)
3+
--SKIPIF--
4+
<?php require __DIR__ . "/../utils/basic-skipif.inc"; ?>
5+
<?php skip_if_not_libmongoc_crypto(); ?>
6+
<?php skip_if_not_replica_set(); ?>
7+
<?php skip_if_server_version('<', '4.0'); ?>
8+
<?php skip_if_not_clean(); ?>
9+
--FILE--
10+
<?php
11+
require_once __DIR__ . "/../utils/basic.inc";
12+
13+
$manager = new MongoDB\Driver\Manager(URI);
14+
15+
/* Create collections as that can't be (automatically) done in a transaction */
16+
$manager->executeCommand(
17+
DATABASE_NAME,
18+
new \MongoDB\Driver\Command([ 'create' => COLLECTION_NAME ]),
19+
[ 'writeConcern' => new \MongoDB\Driver\WriteConcern( \MongoDB\Driver\WriteConcern::MAJORITY ) ]
20+
);
21+
22+
23+
/* Do the transaction */
24+
$session = $manager->startSession();
25+
26+
$session->startTransaction( [
27+
'readConcern' => new \MongoDB\Driver\ReadConcern( "snapshot" ),
28+
'writeConcern' => new \MongoDB\Driver\WriteConcern( \MongoDB\Driver\WriteConcern::MAJORITY )
29+
] );
30+
31+
echo throws(function() use ($manager, $session) {
32+
$cmd = new \MongoDB\Driver\Command( [
33+
'count' => COLLECTION_NAME,
34+
'query' => [ 'q' => [ 'employee' => 3 ] ]
35+
] );
36+
$manager->executeReadWriteCommand(
37+
DATABASE_NAME,
38+
$cmd,
39+
[
40+
'session' => $session,
41+
'readConcern' => new \MongoDB\Driver\ReadConcern( \MongoDB\Driver\ReadConcern::LOCAL )
42+
]
43+
);
44+
}, "MongoDB\Driver\Exception\InvalidArgumentException"), "\n";
45+
46+
echo throws(function() use ($manager, $session) {
47+
$cmd = new \MongoDB\Driver\Command( [
48+
'update' => COLLECTION_NAME,
49+
'updates' => [ [ 'q' => [ 'employee' => 3 ], 'u' => [ '$set' => [ 'status' => 'Inactive' ] ] ] ]
50+
] );
51+
$manager->executeReadWriteCommand(
52+
DATABASE_NAME,
53+
$cmd,
54+
[
55+
'session' => $session,
56+
'writeConcern' => new \MongoDB\Driver\WriteConcern( \MongoDB\Driver\WriteConcern::MAJORITY )
57+
]
58+
);
59+
}, "MongoDB\Driver\Exception\InvalidArgumentException"), "\n";
60+
61+
?>
62+
===DONE===
63+
<?php exit(0); ?>
64+
--EXPECT--
65+
OK: Got MongoDB\Driver\Exception\InvalidArgumentException
66+
Cannot set read concern after starting transaction
67+
OK: Got MongoDB\Driver\Exception\InvalidArgumentException
68+
Cannot set write concern after starting transaction
69+
===DONE===

0 commit comments

Comments
 (0)