Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Contribute to GitLab
Sign in
Toggle navigation
M
mongo-php-library
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
sinan
mongo-php-library
Commits
428d2172
Commit
428d2172
authored
Mar 13, 2018
by
Katherine Walker
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
PHPLIB-335: ChangeStream::next() should increment key even if ResumeTokenException is thrown
parent
e847b06c
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
38 additions
and
2 deletions
+38
-2
ChangeStream.php
src/ChangeStream.php
+2
-2
WatchFunctionalTest.php
tests/Operation/WatchFunctionalTest.php
+36
-0
No files found.
src/ChangeStream.php
View file @
428d2172
...
...
@@ -95,11 +95,11 @@ class ChangeStream implements Iterator
try
{
$this
->
csIt
->
next
();
if
(
$this
->
valid
())
{
$this
->
resumeToken
=
$this
->
extractResumeToken
(
$this
->
csIt
->
current
());
if
(
$this
->
hasAdvanced
)
{
$this
->
key
++
;
}
$this
->
hasAdvanced
=
true
;
$this
->
resumeToken
=
$this
->
extractResumeToken
(
$this
->
csIt
->
current
());
}
}
catch
(
RuntimeException
$e
)
{
if
(
strpos
(
$e
->
getMessage
(),
"not master"
)
!==
false
)
{
...
...
@@ -127,8 +127,8 @@ class ChangeStream implements Iterator
try
{
$this
->
csIt
->
rewind
();
if
(
$this
->
valid
())
{
$this
->
resumeToken
=
$this
->
extractResumeToken
(
$this
->
csIt
->
current
());
$this
->
hasAdvanced
=
true
;
$this
->
resumeToken
=
$this
->
extractResumeToken
(
$this
->
csIt
->
current
());
}
}
catch
(
RuntimeException
$e
)
{
if
(
strpos
(
$e
->
getMessage
(),
"not master"
)
!==
false
)
{
...
...
tests/Operation/WatchFunctionalTest.php
View file @
428d2172
...
...
@@ -7,6 +7,7 @@ use MongoDB\Driver\Manager;
use
MongoDB\Driver\ReadPreference
;
use
MongoDB\Driver\Server
;
use
MongoDB\Driver\Exception\ConnectionTimeoutException
;
use
MongoDB\Exception\ResumeTokenException
;
use
MongoDB\Operation\DatabaseCommand
;
use
MongoDB\Operation\InsertOne
;
use
MongoDB\Operation\Watch
;
...
...
@@ -552,6 +553,41 @@ class WatchFunctionalTest extends FunctionalTestCase
$this
->
assertSame
(
1
,
$changeStream
->
key
());
}
public
function
testResumeTokenNotFoundAdvancesKey
()
{
$pipeline
=
[[
'$project'
=>
[
'_id'
=>
0
]]];
$operation
=
new
Watch
(
$this
->
manager
,
$this
->
getDatabaseName
(),
$this
->
getCollectionName
(),
$pipeline
,
$this
->
defaultOptions
);
$changeStream
=
$operation
->
execute
(
$this
->
getPrimaryServer
());
/* Note: we intentionally do not start iteration with rewind() to ensure
* that we test extraction functionality within next(). */
$this
->
insertDocument
([
'x'
=>
1
]);
$this
->
insertDocument
([
'x'
=>
2
]);
$this
->
insertDocument
([
'x'
=>
3
]);
try
{
$changeStream
->
rewind
();
$this
->
fail
(
'ResumeTokenException was not thrown'
);
}
catch
(
ResumeTokenException
$e
)
{}
$this
->
assertSame
(
0
,
$changeStream
->
key
());
try
{
$changeStream
->
next
();
$this
->
fail
(
'ResumeTokenException was not thrown'
);
}
catch
(
ResumeTokenException
$e
)
{}
$this
->
assertSame
(
1
,
$changeStream
->
key
());
try
{
$changeStream
->
next
();
$this
->
fail
(
'ResumeTokenException was not thrown'
);
}
catch
(
ResumeTokenException
$e
)
{}
$this
->
assertSame
(
2
,
$changeStream
->
key
());
}
private
function
insertDocument
(
$document
)
{
$insertOne
=
new
InsertOne
(
$this
->
getDatabaseName
(),
$this
->
getCollectionName
(),
$document
);
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment