1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114
|
--TEST--
Causal consistency: first read or write in session updates operationTime
--SKIPIF--
<?php require __DIR__ . "/../utils/basic-skipif.inc"; ?>
<?php skip_if_not_libmongoc_crypto(); ?>
<?php skip_if_not_replica_set_or_mongos_with_replica_set(); ?>
<?php skip_if_server_version('<', '3.6'); ?>
<?php skip_if_not_clean(); ?>
--FILE--
<?php
require_once __DIR__ . "/../utils/basic.inc";
class Test implements MongoDB\Driver\Monitoring\CommandSubscriber
{
private $lastSeenOperationTime;
public function executeBulkWrite()
{
$this->lastSeenOperationTime = null;
MongoDB\Driver\Monitoring\addSubscriber($this);
$manager = new MongoDB\Driver\Manager(URI);
$session = $manager->startSession();
$bulk = new MongoDB\Driver\BulkWrite;
$bulk->insert(['x' => 1]);
$manager->executeBulkWrite(NS, $bulk, ['session' => $session]);
printf("Session reports last seen operationTime: %s\n", ($session->getOperationTime() == $this->lastSeenOperationTime) ? 'yes' : 'no');
MongoDB\Driver\Monitoring\removeSubscriber($this);
}
public function executeCommand()
{
$this->lastSeenOperationTime = null;
MongoDB\Driver\Monitoring\addSubscriber($this);
$manager = new MongoDB\Driver\Manager(URI);
$session = $manager->startSession();
$command = new MongoDB\Driver\Command(['ping' => 1]);
$manager->executeCommand(DATABASE_NAME, $command, ['session' => $session]);
printf("Session reports last seen operationTime: %s\n", ($session->getOperationTime() == $this->lastSeenOperationTime) ? 'yes' : 'no');
MongoDB\Driver\Monitoring\removeSubscriber($this);
}
public function executeQuery()
{
$this->lastSeenOperationTime = null;
MongoDB\Driver\Monitoring\addSubscriber($this);
$manager = new MongoDB\Driver\Manager(URI);
$session = $manager->startSession();
$query = new MongoDB\Driver\Query([]);
$manager->executeQuery(NS, $query, ['session' => $session]);
printf("Session reports last seen operationTime: %s\n", ($session->getOperationTime() == $this->lastSeenOperationTime) ? 'yes' : 'no');
MongoDB\Driver\Monitoring\removeSubscriber($this);
}
public function commandStarted(MongoDB\Driver\Monitoring\CommandStartedEvent $event)
{
}
public function commandSucceeded(MongoDB\Driver\Monitoring\CommandSucceededEvent $event)
{
$reply = $event->getReply();
$hasOperationTime = isset($reply->{'operationTime'});
printf("%s command reply includes operationTime: %s\n", $event->getCommandName(), $hasOperationTime ? 'yes' : 'no');
if ($hasOperationTime) {
$this->lastSeenOperationTime = $reply->operationTime;
}
}
public function commandFailed(MongoDB\Driver\Monitoring\CommandFailedEvent $event)
{
}
}
echo "Testing executeBulkWrite()\n";
(new Test)->executeBulkWrite();
echo "\nTesting executeCommand()\n";
(new Test)->executeCommand();
echo "\nTesting executeQuery()\n";
(new Test)->executeQuery();
?>
===DONE===
<?php exit(0); ?>
--EXPECT--
Testing executeBulkWrite()
insert command reply includes operationTime: yes
Session reports last seen operationTime: yes
Testing executeCommand()
ping command reply includes operationTime: yes
Session reports last seen operationTime: yes
Testing executeQuery()
find command reply includes operationTime: yes
Session reports last seen operationTime: yes
===DONE===
|