-
Notifications
You must be signed in to change notification settings - Fork 266
PHPLIB-712: Allow hint for unacknowledged writes using OP_MSG when supported by the server #859
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,6 +7,7 @@ | |
use MongoDB\Driver\BulkWrite; | ||
use MongoDB\Driver\WriteConcern; | ||
use MongoDB\Exception\BadMethodCallException; | ||
use MongoDB\Exception\UnsupportedException; | ||
use MongoDB\Operation\Delete; | ||
use MongoDB\Tests\CommandObserver; | ||
|
||
|
@@ -63,6 +64,46 @@ public function testDeleteMany(): void | |
$this->assertSameDocuments($expected, $this->collection->find()); | ||
} | ||
|
||
public function testHintOptionUnsupportedClientSideError(): void | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Are these scenarios not covered by the automated spec tests, or did you want to ensure that the correct exception thrown? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Had I not implemented PHPLIB-711, we could rely on the spec tests to differentiate between PHPLIB's UnsupportedException and the BulkWriteException thrown from PHPC encountering libmongoc's client-side error. However, I think unwrapping BulkWriteExceptions is necessary to properly differentiate cilent-side and server-side errors. With PHPLIB-711 implemented, the unwrapped BulkWriteException (in this particular case) and UnsupportedException are both considered client-side errors so the spec tests really cannot differentiate. That's where these tests come in, to explicitly assert that PHPLIB raises its own internal exception. |
||
{ | ||
if (version_compare($this->getServerVersion(), '3.4.0', '>=')) { | ||
$this->markTestSkipped('server reports error for unsupported delete options'); | ||
} | ||
|
||
$operation = new Delete( | ||
$this->getDatabaseName(), | ||
$this->getCollectionName(), | ||
[], | ||
0, | ||
['hint' => '_id_'] | ||
); | ||
|
||
$this->expectException(UnsupportedException::class); | ||
$this->expectExceptionMessage('Hint is not supported by the server executing this operation'); | ||
|
||
$operation->execute($this->getPrimaryServer()); | ||
} | ||
|
||
public function testHintOptionAndUnacknowledgedWriteConcernUnsupportedClientSideError(): void | ||
{ | ||
if (version_compare($this->getServerVersion(), '4.4.0', '>=')) { | ||
$this->markTestSkipped('hint is supported'); | ||
} | ||
|
||
$operation = new Delete( | ||
$this->getDatabaseName(), | ||
$this->getCollectionName(), | ||
[], | ||
0, | ||
['hint' => '_id_', 'writeConcern' => new WriteConcern(0)] | ||
); | ||
|
||
$this->expectException(UnsupportedException::class); | ||
$this->expectExceptionMessage('Hint is not supported by the server executing this operation'); | ||
|
||
$operation->execute($this->getPrimaryServer()); | ||
} | ||
|
||
public function testSessionOption(): void | ||
{ | ||
if (version_compare($this->getServerVersion(), '3.6.0', '<')) { | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This will ultimately be used for detecting whether
hint
andw:0
are being used together on an unsupported server.I also plan to add a method that detects an unacknowledged write concern. Since FindAndModify will also need to be addressed by this PR, I'll likely end up fixing PHPLIB-709 in the process.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Implemented
is_write_concern_acknowledged
, which is now used in the Update, Delete, and FindAndModify operations. PHPLIB-709 has been fixed in the process.