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
43e742ad
Commit
43e742ad
authored
Jan 30, 2018
by
Katherine Walker
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
PHPLIB-276: Add maxAwaitTimeMS support for change streams
parent
76ef2717
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
33 additions
and
3 deletions
+33
-3
Aggregate.php
src/Operation/Aggregate.php
+10
-1
ChangeStream.php
src/Operation/ChangeStream.php
+2
-1
ChangeStreamFunctionalTest.php
tests/Operation/ChangeStreamFunctionalTest.php
+17
-0
FindFunctionalTest.php
tests/Operation/FindFunctionalTest.php
+4
-1
No files found.
src/Operation/Aggregate.php
View file @
43e742ad
...
...
@@ -163,6 +163,10 @@ class Aggregate implements Executable
throw
InvalidArgumentException
::
invalidType
(
'"hint" option'
,
$options
[
'hint'
],
'string or array or object'
);
}
if
(
isset
(
$options
[
'maxAwaitTimeMS'
])
&&
!
is_integer
(
$options
[
'maxAwaitTimeMS'
]))
{
throw
InvalidArgumentException
::
invalidType
(
'"maxAwaitTimeMS" option'
,
$options
[
'maxAwaitTimeMS'
],
'integer'
);
}
if
(
isset
(
$options
[
'maxTimeMS'
])
&&
!
is_integer
(
$options
[
'maxTimeMS'
]))
{
throw
InvalidArgumentException
::
invalidType
(
'"maxTimeMS" option'
,
$options
[
'maxTimeMS'
],
'integer'
);
}
...
...
@@ -277,6 +281,7 @@ class Aggregate implements Executable
'aggregate'
=>
$this
->
collectionName
,
'pipeline'
=>
$this
->
pipeline
,
];
$cmdOptions
=
[];
// Servers < 2.6 do not support any command options
if
(
!
$isCursorSupported
)
{
...
...
@@ -303,13 +308,17 @@ class Aggregate implements Executable
$cmd
[
'hint'
]
=
is_array
(
$this
->
options
[
'hint'
])
?
(
object
)
$this
->
options
[
'hint'
]
:
$this
->
options
[
'hint'
];
}
if
(
isset
(
$this
->
options
[
'maxAwaitTimeMS'
]))
{
$cmdOptions
[
'maxAwaitTimeMS'
]
=
$this
->
options
[
'maxAwaitTimeMS'
];
}
if
(
$this
->
options
[
'useCursor'
])
{
$cmd
[
'cursor'
]
=
isset
(
$this
->
options
[
"batchSize"
])
?
[
'batchSize'
=>
$this
->
options
[
"batchSize"
]]
:
new
stdClass
;
}
return
new
Command
(
$cmd
);
return
new
Command
(
$cmd
,
$cmdOptions
);
}
/**
...
...
src/Operation/ChangeStream.php
View file @
43e742ad
...
...
@@ -147,7 +147,7 @@ class ChangeStream implements Executable
private
function
createAggregateOptions
()
{
$aggOptions
=
array_intersect_key
(
$this
->
options
,
[
'batchSize'
=>
1
,
'collation'
=>
1
]);
$aggOptions
=
array_intersect_key
(
$this
->
options
,
[
'batchSize'
=>
1
,
'collation'
=>
1
,
'maxAwaitTimeMS'
=>
1
]);
if
(
!
$aggOptions
)
{
return
[];
}
...
...
@@ -174,6 +174,7 @@ class ChangeStream implements Executable
array_unshift
(
$this
->
pipeline
,
$changeStreamArray
);
$cmd
=
new
Aggregate
(
$this
->
databaseName
,
$this
->
collectionName
,
$this
->
pipeline
,
$this
->
createAggregateOptions
());
return
$cmd
;
}
...
...
tests/Operation/ChangeStreamFunctionalTest.php
View file @
43e742ad
...
...
@@ -237,4 +237,21 @@ class ChangeStreamFunctionalTest extends FunctionalTestCase
]);
$this
->
assertEquals
(
$changeStreamResult
->
current
(),
$expectedResult
);
}
public
function
testMaxAwaitTimeMS
()
{
$this
->
collection
=
new
Collection
(
$this
->
manager
,
$this
->
getDatabaseName
(),
$this
->
getCollectionName
());
$maxAwaitTimeMS
=
10
;
$changeStreamResult
=
$this
->
collection
->
watch
([],
[
'maxAwaitTimeMS'
=>
$maxAwaitTimeMS
]);
/* Make sure we await results for at least maxAwaitTimeMS, since no new
* documents should be inserted to wake up the server's command thread.
* Also ensure that we don't wait too long (server default is one
* second). */
$startTime
=
microtime
(
true
);
$changeStreamResult
->
rewind
();
$this
->
assertGreaterThanOrEqual
(
$maxAwaitTimeMS
*
0.001
,
microtime
(
true
)
-
$startTime
);
$this
->
assertLessThan
(
0.5
,
microtime
(
true
)
-
$startTime
);
}
}
tests/Operation/FindFunctionalTest.php
View file @
43e742ad
...
...
@@ -154,7 +154,10 @@ class FindFunctionalTest extends FunctionalTestCase
$cursor
=
$operation
->
execute
(
$this
->
getPrimaryServer
());
$it
=
new
\IteratorIterator
(
$cursor
);
// Make sure we await results for no more than the maxAwaitTimeMS.
/* Make sure we await results for at least maxAwaitTimeMS, since no new
* documents should be inserted to wake up the server's query thread.
* Also ensure that we don't wait too long (server default is one
* second). */
$it
->
rewind
();
$it
->
next
();
$startTime
=
microtime
(
true
);
...
...
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