|
4 | 4 |
|
5 | 5 | use InvalidArgumentException;
|
6 | 6 | use MongoDB\Driver\Exception\RuntimeException;
|
| 7 | +use MongoDB\Driver\Server; |
| 8 | +use MongoDB\Exception\UnsupportedException; |
7 | 9 | use MongoDB\Model\IndexInfo;
|
8 | 10 | use MongoDB\Operation\CreateIndexes;
|
9 | 11 | use MongoDB\Operation\ListIndexes;
|
@@ -171,6 +173,52 @@ function (array $event) {
|
171 | 173 | );
|
172 | 174 | }
|
173 | 175 |
|
| 176 | + public function testCommitQuorumOption() |
| 177 | + { |
| 178 | + if (version_compare($this->getServerVersion(), '4.3.4', '<')) { |
| 179 | + $this->markTestSkipped('commitQuorum is not supported'); |
| 180 | + } |
| 181 | + |
| 182 | + if ($this->getPrimaryServer()->getType() !== Server::TYPE_RS_PRIMARY) { |
| 183 | + $this->markTestSkipped('commitQuorum is only supported on replica sets'); |
| 184 | + } |
| 185 | + |
| 186 | + (new CommandObserver())->observe( |
| 187 | + function () { |
| 188 | + $operation = new CreateIndexes( |
| 189 | + $this->getDatabaseName(), |
| 190 | + $this->getCollectionName(), |
| 191 | + [['key' => ['x' => 1]]], |
| 192 | + ['commitQuorum' => 'majority'] |
| 193 | + ); |
| 194 | + |
| 195 | + $operation->execute($this->getPrimaryServer()); |
| 196 | + }, |
| 197 | + function (array $event) { |
| 198 | + $this->assertObjectHasAttribute('commitQuorum', $event['started']->getCommand()); |
| 199 | + } |
| 200 | + ); |
| 201 | + } |
| 202 | + |
| 203 | + public function testCommitQuorumUnsupported() |
| 204 | + { |
| 205 | + if (version_compare($this->getServerVersion(), '4.3.4', '>=')) { |
| 206 | + $this->markTestSkipped('commitQuorum is supported'); |
| 207 | + } |
| 208 | + |
| 209 | + $operation = new CreateIndexes( |
| 210 | + $this->getDatabaseName(), |
| 211 | + $this->getCollectionName(), |
| 212 | + [['key' => ['x' => 1]]], |
| 213 | + ['commitQuorum' => 'majority'] |
| 214 | + ); |
| 215 | + |
| 216 | + $this->expectException(UnsupportedException::class); |
| 217 | + $this->expectExceptionMessage('The "commitQuorum" option is not supported by the server executing this operation'); |
| 218 | + |
| 219 | + $operation->execute($this->getPrimaryServer()); |
| 220 | + } |
| 221 | + |
174 | 222 | /**
|
175 | 223 | * Asserts that an index with the given name exists for the collection.
|
176 | 224 | *
|
|
0 commit comments