|
| 1 | +--TEST-- |
| 2 | +MongoDB\Driver\Manager::executeReadWriteCommand() pins transaction to server |
| 3 | +--SKIPIF-- |
| 4 | +<?php require __DIR__ . "/../utils/basic-skipif.inc"; ?> |
| 5 | +<?php skip_if_not_mongos_with_replica_set(); ?> |
| 6 | +<?php skip_if_server_version('<', '4.1.6'); ?> |
| 7 | +<?php skip_if_not_clean(); ?> |
| 8 | +--FILE-- |
| 9 | +<?php |
| 10 | +require_once __DIR__ . "/../utils/basic.inc"; |
| 11 | + |
| 12 | +$manager = new MongoDB\Driver\Manager(URI); |
| 13 | + |
| 14 | +/* Create collections as that can't be (automatically) done in a transaction */ |
| 15 | +$manager->executeReadWriteCommand( |
| 16 | + DATABASE_NAME, |
| 17 | + new \MongoDB\Driver\Command([ 'create' => COLLECTION_NAME ]), |
| 18 | + [ 'writeConcern' => new \MongoDB\Driver\WriteConcern( \MongoDB\Driver\WriteConcern::MAJORITY ) ] |
| 19 | +); |
| 20 | + |
| 21 | +$session = $manager->startSession(); |
| 22 | +var_dump($session->getServer() instanceof \MongoDB\Driver\Server); |
| 23 | + |
| 24 | +$session->startTransaction(); |
| 25 | +var_dump($session->getServer() instanceof \MongoDB\Driver\Server); |
| 26 | + |
| 27 | +$command = new MongoDB\Driver\Command([ |
| 28 | + 'aggregate' => COLLECTION_NAME, |
| 29 | + 'pipeline' => [['$group' => ['_id' => 1]]], |
| 30 | + 'cursor' => (object) [] |
| 31 | +]); |
| 32 | +$manager->executeReadWriteCommand(DATABASE_NAME, $command, ['session' => $session]); |
| 33 | + |
| 34 | +$pinnedServer = $session->getServer(); |
| 35 | +var_dump($pinnedServer instanceof \MongoDB\Driver\Server); |
| 36 | + |
| 37 | +$bulk = new MongoDB\Driver\BulkWrite(); |
| 38 | +$bulk->insert(['x' => 1]); |
| 39 | +$manager->executeBulkWrite(NS, $bulk, ['session' => $session]); |
| 40 | + |
| 41 | +$session->commitTransaction(); |
| 42 | + |
| 43 | +var_dump($session->getServer() == $pinnedServer); |
| 44 | + |
| 45 | +$bulk = new MongoDB\Driver\BulkWrite(); |
| 46 | +$bulk->insert(['x' => 1]); |
| 47 | +$manager->executeBulkWrite(NS, $bulk, ['session' => $session]); |
| 48 | + |
| 49 | +var_dump($session->getServer() instanceof \MongoDB\Driver\Server); |
| 50 | + |
| 51 | +?> |
| 52 | +===DONE=== |
| 53 | +<?php exit(0); ?> |
| 54 | +--EXPECT-- |
| 55 | +bool(false) |
| 56 | +bool(false) |
| 57 | +bool(true) |
| 58 | +bool(true) |
| 59 | +bool(false) |
| 60 | +===DONE=== |
0 commit comments