Skip to content

Commit c21866d

Browse files
committed
Merged pull request #901
2 parents c6d1d78 + 2844939 commit c21866d

File tree

1 file changed

+70
-0
lines changed

1 file changed

+70
-0
lines changed
Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
--TEST--
2+
MongoDB\Driver\Session: Setting per-op readConcern or writeConcern in transaction
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->executeCommand(
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->executeCommand(
52+
DATABASE_NAME,
53+
$cmd,
54+
[
55+
'session' => $session,
56+
'writeConcern' => new \MongoDB\Driver\WriteConcern(
57+
\MongoDB\Driver\WriteConcern::MAJORITY )
58+
]
59+
);
60+
}, "MongoDB\Driver\Exception\InvalidArgumentException"), "\n";
61+
62+
?>
63+
===DONE===
64+
<?php exit(0); ?>
65+
--EXPECT--
66+
OK: Got MongoDB\Driver\Exception\InvalidArgumentException
67+
Cannot set read concern after starting transaction
68+
OK: Got MongoDB\Driver\Exception\InvalidArgumentException
69+
Cannot set write concern after starting transaction
70+
===DONE===

0 commit comments

Comments
 (0)