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
3ece7495
Commit
3ece7495
authored
Oct 17, 2017
by
kvwalker
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
PHPLIB-268 Add option maxAwaitTimeMS on getMore commands
parent
d1061386
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
62 additions
and
1 deletion
+62
-1
apiargs-MongoDBCollection-method-find-option.yaml
...ncludes/apiargs-MongoDBCollection-method-find-option.yaml
+4
-0
apiargs-common-option.yaml
docs/includes/apiargs-common-option.yaml
+11
-0
Find.php
src/Operation/Find.php
+8
-1
FindFunctionalTest.php
tests/Operation/FindFunctionalTest.php
+35
-0
FindTest.php
tests/Operation/FindTest.php
+4
-0
No files found.
docs/includes/apiargs-MongoDBCollection-method-find-option.yaml
View file @
3ece7495
...
...
@@ -93,6 +93,10 @@ interface: phpmethod
operation
:
~
optional
:
true
---
source
:
file
:
apiargs-common-option.yaml
ref
:
maxAwaitTimeMS
---
source
:
file
:
apiargs-common-option.yaml
ref
:
maxTimeMS
...
...
docs/includes/apiargs-common-option.yaml
View file @
3ece7495
...
...
@@ -10,6 +10,17 @@ operation: ~
optional
:
true
---
arg_name
:
option
name
:
maxAwaitTimeMS
type
:
integer
description
:
|
Positive integer denoting the time limit in milliseconds for the server to block
a getMore operation if no data is available. This option should only be used if
cursorType is TAILABLE_AWAIT.
interface
:
phpmethod
operation
:
~
optional
:
true
---
arg_name
:
option
name
:
readConcern
type
:
:php:`MongoDB\\Driver\\ReadConcern <class.mongodb-driver-readconcern>`
description
:
|
...
...
src/Operation/Find.php
View file @
3ece7495
...
...
@@ -78,6 +78,9 @@ class Find implements Executable
*
* * max (document): The exclusive upper bound for a specific index.
*
* * maxAwaitTimeMS (integer): The maxium amount of time for the server to wait
* on new documents to satisfy a query, if cursorType is TAILABLE_AWAIT.
*
* * maxScan (integer): Maximum number of documents or index keys to scan
* when executing the query.
*
...
...
@@ -179,6 +182,10 @@ class Find implements Executable
throw
InvalidArgumentException
::
invalidType
(
'"max" option'
,
$options
[
'max'
],
'array or object'
);
}
if
(
isset
(
$options
[
'maxAwaitTimeMS'
])
&&
!
is_integer
(
$options
[
'maxAwaitTimeMS'
]))
{
throw
InvalidArgumentException
::
invalidType
(
'"maxAwaitTimeMS" option'
,
$options
[
'maxAwaitTimeMS'
],
'integer'
);
}
if
(
isset
(
$options
[
'maxScan'
])
&&
!
is_integer
(
$options
[
'maxScan'
]))
{
throw
InvalidArgumentException
::
invalidType
(
'"maxScan" option'
,
$options
[
'maxScan'
],
'integer'
);
}
...
...
@@ -298,7 +305,7 @@ class Find implements Executable
}
}
foreach
([
'allowPartialResults'
,
'batchSize'
,
'comment'
,
'hint'
,
'limit'
,
'maxScan'
,
'maxTimeMS'
,
'noCursorTimeout'
,
'oplogReplay'
,
'projection'
,
'readConcern'
,
'returnKey'
,
'showRecordId'
,
'skip'
,
'snapshot'
,
'sort'
]
as
$option
)
{
foreach
([
'allowPartialResults'
,
'batchSize'
,
'comment'
,
'hint'
,
'limit'
,
'max
AwaitTimeMS'
,
'max
Scan'
,
'maxTimeMS'
,
'noCursorTimeout'
,
'oplogReplay'
,
'projection'
,
'readConcern'
,
'returnKey'
,
'showRecordId'
,
'skip'
,
'snapshot'
,
'sort'
]
as
$option
)
{
if
(
isset
(
$this
->
options
[
$option
]))
{
$options
[
$option
]
=
$this
->
options
[
$option
];
}
...
...
tests/Operation/FindFunctionalTest.php
View file @
3ece7495
...
...
@@ -3,7 +3,9 @@
namespace
MongoDB\Tests\Operation
;
use
MongoDB\Driver\BulkWrite
;
use
MongoDB\Operation\CreateCollection
;
use
MongoDB\Operation\CreateIndexes
;
use
MongoDB\Operation\DropCollection
;
use
MongoDB\Operation\Find
;
use
MongoDB\Tests\CommandObserver
;
use
stdClass
;
...
...
@@ -123,6 +125,39 @@ class FindFunctionalTest extends FunctionalTestCase
];
}
public
function
testMaxAwaitTimeMS
()
{
$maxAwaitTimeMS
=
10
;
// Create a capped collection.
$databaseName
=
$this
->
getDatabaseName
();
$cappedCollectionName
=
$this
->
getCollectionName
();
$cappedCollectionOptions
=
[
'capped'
=>
true
,
'max'
=>
100
,
'size'
=>
1048576
,
];
$operation
=
new
CreateCollection
(
$databaseName
,
$cappedCollectionName
,
$cappedCollectionOptions
);
$operation
->
execute
(
$this
->
getPrimaryServer
());
// Insert documents into the capped collection.
$bulkWrite
=
new
BulkWrite
([
'ordered'
=>
true
]);
$bulkWrite
->
insert
([
'_id'
=>
1
]);
$result
=
$this
->
manager
->
executeBulkWrite
(
$this
->
getNamespace
(),
$bulkWrite
);
$operation
=
new
Find
(
$databaseName
,
$cappedCollectionName
,
[],
[
'cursorType'
=>
Find
::
TAILABLE_AWAIT
,
'maxAwaitTimeMS'
=>
$maxAwaitTimeMS
]);
$cursor
=
$operation
->
execute
(
$this
->
getPrimaryServer
());
$it
=
new
\IteratorIterator
(
$cursor
);
// Make sure we await results for no more than the maxAwaitTimeMS.
$it
->
rewind
();
$it
->
next
();
$startTime
=
microtime
(
true
);
$it
->
next
();
$this
->
assertGreaterThanOrEqual
(
$maxAwaitTimeMS
*
0.001
,
microtime
(
true
)
-
$startTime
);
}
/**
* Create data fixtures.
*
...
...
tests/Operation/FindTest.php
View file @
3ece7495
...
...
@@ -60,6 +60,10 @@ class FindTest extends TestCase
$options
[][]
=
[
'max'
=>
$value
];
}
foreach
(
$this
->
getInvalidIntegerVAlues
()
as
$value
)
{
$options
[][]
=
[
'maxAwaitTimeMS'
=>
$value
];
}
foreach
(
$this
->
getInvalidIntegerValues
()
as
$value
)
{
$options
[][]
=
[
'maxScan'
=>
$value
];
}
...
...
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