File: retryable-writes-002.phpt

package info (click to toggle)
php-mongodb 1.15.0%2B1.11.1%2B1.9.2%2B1.7.5-1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 63,984 kB
  • sloc: ansic: 328,429; xml: 10,797; php: 4,235; sh: 179; python: 47; pascal: 36; makefile: 3
file content (85 lines) | stat: -rw-r--r-- 2,821 bytes parent folder | download | duplicates (3)
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
--TEST--
Retryable writes: supported multi-statement operations include transaction IDs
--SKIPIF--
<?php require __DIR__ . "/../utils/basic-skipif.inc"; ?>
<?php skip_if_not_libmongoc_crypto(); ?>
<?php skip_if_not_replica_set_or_sharded_cluster_with_replica_set(); ?>
<?php skip_if_not_clean(); ?>
--FILE--
<?php
require_once __DIR__ . "/../utils/basic.inc";

class TransactionIdObserver implements MongoDB\Driver\Monitoring\CommandSubscriber
{
    public function commandStarted(MongoDB\Driver\Monitoring\CommandStartedEvent $event): void
    {
        $command = $event->getCommand();
        $hasTransactionId = isset($command->lsid) && isset($command->txnNumber);

        printf("%s command includes transaction ID: %s\n", $event->getCommandName(), $hasTransactionId ? 'yes' : 'no');
    }

    public function commandSucceeded(MongoDB\Driver\Monitoring\CommandSucceededEvent $event): void
    {
    }

    public function commandFailed(MongoDB\Driver\Monitoring\CommandFailedEvent $event): void
    {
    }
}

$observer = new TransactionIdObserver;
MongoDB\Driver\Monitoring\addSubscriber($observer);

$manager = create_test_manager();

echo "Testing multi-statement bulk write (ordered=true)\n";
$bulk = new MongoDB\Driver\BulkWrite(['ordered' => true]);
$bulk->delete(['x' => 1], ['limit' => 1]);
$bulk->insert(['x' => 1]);
$bulk->update(['x' => 1], ['$inc' => ['x' => 1]]);
$bulk->update(['x' => 1], ['x' => 2]);
$manager->executeBulkWrite(NS, $bulk);

echo "\nTesting multi-statement bulk write (ordered=false)\n";
$bulk = new MongoDB\Driver\BulkWrite(['ordered' => false]);
$bulk->delete(['x' => 1], ['limit' => 1]);
$bulk->insert(['x' => 1]);
$bulk->update(['x' => 1], ['$inc' => ['x' => 1]]);
$bulk->update(['x' => 1], ['x' => 2]);
$manager->executeBulkWrite(NS, $bulk);

echo "\nTesting insertMany (ordered=true)\n";
$bulk = new MongoDB\Driver\BulkWrite(['ordered' => true]);
$bulk->insert(['x' => 1]);
$bulk->insert(['x' => 2]);
$manager->executeBulkWrite(NS, $bulk);

echo "\nTesting insertMany (ordered=false)\n";
$bulk = new MongoDB\Driver\BulkWrite(['ordered' => false]);
$bulk->insert(['x' => 1]);
$bulk->insert(['x' => 2]);
$manager->executeBulkWrite(NS, $bulk);

MongoDB\Driver\Monitoring\removeSubscriber($observer);

?>
===DONE===
<?php exit(0); ?>
--EXPECT--
Testing multi-statement bulk write (ordered=true)
delete command includes transaction ID: yes
insert command includes transaction ID: yes
update command includes transaction ID: yes

Testing multi-statement bulk write (ordered=false)
delete command includes transaction ID: yes
insert command includes transaction ID: yes
update command includes transaction ID: yes

Testing insertMany (ordered=true)
insert command includes transaction ID: yes

Testing insertMany (ordered=false)
insert command includes transaction ID: yes
===DONE===