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
a49468ea
Unverified
Commit
a49468ea
authored
Mar 09, 2020
by
Andreas Braun
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
PHPLIB-496: Test collection and index creation in multi-doc transactions
parent
3777f5ae
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
526 additions
and
1 deletion
+526
-1
CommandExpectations.php
tests/SpecTests/CommandExpectations.php
+1
-1
Operation.php
tests/SpecTests/Operation.php
+84
-0
create-collection.json
tests/SpecTests/transactions/create-collection.json
+204
-0
create-index.json
tests/SpecTests/transactions/create-index.json
+237
-0
No files found.
tests/SpecTests/CommandExpectations.php
View file @
a49468ea
...
@@ -130,7 +130,7 @@ class CommandExpectations implements CommandSubscriber
...
@@ -130,7 +130,7 @@ class CommandExpectations implements CommandSubscriber
* configureFailPoint needs to be ignored as the targetedFailPoint
* configureFailPoint needs to be ignored as the targetedFailPoint
* operation will be caught by command monitoring and is also not
* operation will be caught by command monitoring and is also not
* present in the expected commands in spec tests. */
* present in the expected commands in spec tests. */
$o
->
ignoredCommandNames
=
[
'buildInfo'
,
'getParameter'
,
'configureFailPoint'
];
$o
->
ignoredCommandNames
=
[
'buildInfo'
,
'getParameter'
,
'configureFailPoint'
,
'listCollections'
,
'listIndexes'
];
return
$o
;
return
$o
;
}
}
...
...
tests/SpecTests/Operation.php
View file @
a49468ea
...
@@ -13,6 +13,8 @@ use MongoDB\Driver\Server;
...
@@ -13,6 +13,8 @@ use MongoDB\Driver\Server;
use
MongoDB\Driver\Session
;
use
MongoDB\Driver\Session
;
use
MongoDB\Driver\WriteConcern
;
use
MongoDB\Driver\WriteConcern
;
use
MongoDB\GridFS\Bucket
;
use
MongoDB\GridFS\Bucket
;
use
MongoDB\Model\CollectionInfo
;
use
MongoDB\Model\IndexInfo
;
use
MongoDB\Operation\FindOneAndReplace
;
use
MongoDB\Operation\FindOneAndReplace
;
use
MongoDB\Operation\FindOneAndUpdate
;
use
MongoDB\Operation\FindOneAndUpdate
;
use
stdClass
;
use
stdClass
;
...
@@ -20,6 +22,7 @@ use function array_diff_key;
...
@@ -20,6 +22,7 @@ use function array_diff_key;
use
function
array_map
;
use
function
array_map
;
use
function
fclose
;
use
function
fclose
;
use
function
fopen
;
use
function
fopen
;
use
function
iterator_to_array
;
use
function
MongoDB
\is_last_pipeline_operator_write
;
use
function
MongoDB
\is_last_pipeline_operator_write
;
use
function
MongoDB
\with_transaction
;
use
function
MongoDB
\with_transaction
;
use
function
stream_get_contents
;
use
function
stream_get_contents
;
...
@@ -359,6 +362,11 @@ final class Operation
...
@@ -359,6 +362,11 @@ final class Operation
array_map
([
$this
,
'prepareBulkWriteRequest'
],
$args
[
'requests'
]),
array_map
([
$this
,
'prepareBulkWriteRequest'
],
$args
[
'requests'
]),
$options
$options
);
);
case
'createIndex'
:
return
$collection
->
createIndex
(
$args
[
'keys'
],
array_diff_key
(
$args
,
[
'keys'
=>
1
])
);
case
'count'
:
case
'count'
:
case
'countDocuments'
:
case
'countDocuments'
:
case
'find'
:
case
'find'
:
...
@@ -466,6 +474,16 @@ final class Operation
...
@@ -466,6 +474,16 @@ final class Operation
$args
[
'pipeline'
],
$args
[
'pipeline'
],
array_diff_key
(
$args
,
[
'pipeline'
=>
1
])
array_diff_key
(
$args
,
[
'pipeline'
=>
1
])
);
);
case
'createCollection'
:
return
$database
->
createCollection
(
$args
[
'collection'
],
array_diff_key
(
$args
,
[
'collection'
=>
1
])
);
case
'dropCollection'
:
return
$database
->
dropCollection
(
$args
[
'collection'
],
array_diff_key
(
$args
,
[
'collection'
=>
1
])
);
case
'listCollections'
:
case
'listCollections'
:
return
$database
->
listCollections
(
$args
);
return
$database
->
listCollections
(
$args
);
case
'runCommand'
:
case
'runCommand'
:
...
@@ -570,6 +588,36 @@ final class Operation
...
@@ -570,6 +588,36 @@ final class Operation
$context
->
replaceArgumentSessionPlaceholder
(
$args
);
$context
->
replaceArgumentSessionPlaceholder
(
$args
);
switch
(
$this
->
name
)
{
switch
(
$this
->
name
)
{
case
'assertCollectionExists'
:
$databaseName
=
$args
[
'database'
];
$collectionName
=
$args
[
'collection'
];
$test
->
assertContains
(
$collectionName
,
$this
->
getCollectionNames
(
$context
,
$databaseName
));
return
null
;
case
'assertCollectionNotExists'
:
$databaseName
=
$args
[
'database'
];
$collectionName
=
$args
[
'collection'
];
$test
->
assertNotContains
(
$collectionName
,
$this
->
getCollectionNames
(
$context
,
$databaseName
));
return
null
;
case
'assertIndexExists'
:
$databaseName
=
$args
[
'database'
];
$collectionName
=
$args
[
'collection'
];
$indexName
=
$args
[
'index'
];
$test
->
assertContains
(
$indexName
,
$this
->
getIndexNames
(
$context
,
$databaseName
,
$collectionName
));
return
null
;
case
'assertIndexNotExists'
:
$databaseName
=
$args
[
'database'
];
$collectionName
=
$args
[
'collection'
];
$indexName
=
$args
[
'index'
];
$test
->
assertNotContains
(
$indexName
,
$this
->
getIndexNames
(
$context
,
$databaseName
,
$collectionName
));
return
null
;
case
'assertSessionPinned'
:
case
'assertSessionPinned'
:
$test
->
assertInstanceOf
(
Session
::
class
,
$args
[
'session'
]);
$test
->
assertInstanceOf
(
Session
::
class
,
$args
[
'session'
]);
$test
->
assertInstanceOf
(
Server
::
class
,
$args
[
'session'
]
->
getServer
());
$test
->
assertInstanceOf
(
Server
::
class
,
$args
[
'session'
]
->
getServer
());
...
@@ -599,6 +647,37 @@ final class Operation
...
@@ -599,6 +647,37 @@ final class Operation
}
}
}
}
/**
* @param string $databaseName
*
* @return array
*/
private
function
getCollectionNames
(
Context
$context
,
$databaseName
)
{
return
array_map
(
function
(
CollectionInfo
$collectionInfo
)
{
return
$collectionInfo
->
getName
();
},
iterator_to_array
(
$context
->
selectDatabase
(
$databaseName
)
->
listCollections
())
);
}
/**
* @param string $databaseName
* @param string $collectionName
*
* @return array
*/
private
function
getIndexNames
(
Context
$context
,
$databaseName
,
$collectionName
)
{
return
array_map
(
function
(
IndexInfo
$indexInfo
)
{
return
$indexInfo
->
getName
();
},
iterator_to_array
(
$context
->
selectCollection
(
$databaseName
,
$collectionName
)
->
listIndexes
())
);
}
/**
/**
* @throws LogicException if the operation object is unsupported
* @throws LogicException if the operation object is unsupported
*/
*/
...
@@ -657,6 +736,9 @@ final class Operation
...
@@ -657,6 +736,9 @@ final class Operation
return
ResultExpectation
::
ASSERT_BULKWRITE
;
return
ResultExpectation
::
ASSERT_BULKWRITE
;
case
'count'
:
case
'count'
:
case
'countDocuments'
:
case
'countDocuments'
:
return
ResultExpectation
::
ASSERT_SAME
;
case
'createIndex'
:
return
ResultExpectation
::
ASSERT_MATCHES_DOCUMENT
;
case
'distinct'
:
case
'distinct'
:
case
'estimatedDocumentCount'
:
case
'estimatedDocumentCount'
:
return
ResultExpectation
::
ASSERT_SAME
;
return
ResultExpectation
::
ASSERT_SAME
;
...
@@ -700,6 +782,8 @@ final class Operation
...
@@ -700,6 +782,8 @@ final class Operation
case
'aggregate'
:
case
'aggregate'
:
case
'listCollections'
:
case
'listCollections'
:
return
ResultExpectation
::
ASSERT_SAME_DOCUMENTS
;
return
ResultExpectation
::
ASSERT_SAME_DOCUMENTS
;
case
'createCollection'
:
case
'dropCollection'
:
case
'runCommand'
:
case
'runCommand'
:
return
ResultExpectation
::
ASSERT_MATCHES_DOCUMENT
;
return
ResultExpectation
::
ASSERT_MATCHES_DOCUMENT
;
case
'watch'
:
case
'watch'
:
...
...
tests/SpecTests/transactions/create-collection.json
0 → 100644
View file @
a49468ea
{
"runOn"
:
[
{
"minServerVersion"
:
"4.3.4"
,
"topology"
:
[
"replicaset"
,
"sharded"
]
}
],
"database_name"
:
"transaction-tests"
,
"collection_name"
:
"test"
,
"data"
:
[],
"tests"
:
[
{
"description"
:
"explicitly create collection using create command"
,
"operations"
:
[
{
"name"
:
"dropCollection"
,
"object"
:
"database"
,
"arguments"
:
{
"collection"
:
"test"
}
},
{
"name"
:
"startTransaction"
,
"object"
:
"session0"
},
{
"name"
:
"createCollection"
,
"object"
:
"database"
,
"arguments"
:
{
"session"
:
"session0"
,
"collection"
:
"test"
}
},
{
"name"
:
"assertCollectionNotExists"
,
"object"
:
"testRunner"
,
"arguments"
:
{
"database"
:
"transaction-tests"
,
"collection"
:
"test"
}
},
{
"name"
:
"commitTransaction"
,
"object"
:
"session0"
},
{
"name"
:
"assertCollectionExists"
,
"object"
:
"testRunner"
,
"arguments"
:
{
"database"
:
"transaction-tests"
,
"collection"
:
"test"
}
}
],
"expectations"
:
[
{
"command_started_event"
:
{
"command"
:
{
"drop"
:
"test"
,
"writeConcern"
:
null
},
"command_name"
:
"drop"
,
"database_name"
:
"transaction-tests"
}
},
{
"command_started_event"
:
{
"command"
:
{
"create"
:
"test"
,
"lsid"
:
"session0"
,
"txnNumber"
:
{
"$numberLong"
:
"1"
},
"startTransaction"
:
true
,
"autocommit"
:
false
,
"writeConcern"
:
null
},
"command_name"
:
"create"
,
"database_name"
:
"transaction-tests"
}
},
{
"command_started_event"
:
{
"command"
:
{
"commitTransaction"
:
1
,
"lsid"
:
"session0"
,
"txnNumber"
:
{
"$numberLong"
:
"1"
},
"startTransaction"
:
null
,
"autocommit"
:
false
,
"writeConcern"
:
null
},
"command_name"
:
"commitTransaction"
,
"database_name"
:
"admin"
}
}
]
},
{
"description"
:
"implicitly create collection using insert"
,
"operations"
:
[
{
"name"
:
"dropCollection"
,
"object"
:
"database"
,
"arguments"
:
{
"collection"
:
"test"
}
},
{
"name"
:
"startTransaction"
,
"object"
:
"session0"
},
{
"name"
:
"insertOne"
,
"object"
:
"collection"
,
"arguments"
:
{
"session"
:
"session0"
,
"document"
:
{
"_id"
:
1
}
},
"result"
:
{
"insertedId"
:
1
}
},
{
"name"
:
"assertCollectionNotExists"
,
"object"
:
"testRunner"
,
"arguments"
:
{
"database"
:
"transaction-tests"
,
"collection"
:
"test"
}
},
{
"name"
:
"commitTransaction"
,
"object"
:
"session0"
},
{
"name"
:
"assertCollectionExists"
,
"object"
:
"testRunner"
,
"arguments"
:
{
"database"
:
"transaction-tests"
,
"collection"
:
"test"
}
}
],
"expectations"
:
[
{
"command_started_event"
:
{
"command"
:
{
"drop"
:
"test"
,
"writeConcern"
:
null
},
"command_name"
:
"drop"
,
"database_name"
:
"transaction-tests"
}
},
{
"command_started_event"
:
{
"command"
:
{
"insert"
:
"test"
,
"documents"
:
[
{
"_id"
:
1
}
],
"ordered"
:
true
,
"readConcern"
:
null
,
"lsid"
:
"session0"
,
"txnNumber"
:
{
"$numberLong"
:
"1"
},
"startTransaction"
:
true
,
"autocommit"
:
false
,
"writeConcern"
:
null
},
"command_name"
:
"insert"
,
"database_name"
:
"transaction-tests"
}
},
{
"command_started_event"
:
{
"command"
:
{
"commitTransaction"
:
1
,
"lsid"
:
"session0"
,
"txnNumber"
:
{
"$numberLong"
:
"1"
},
"startTransaction"
:
null
,
"autocommit"
:
false
,
"writeConcern"
:
null
},
"command_name"
:
"commitTransaction"
,
"database_name"
:
"admin"
}
}
]
}
]
}
tests/SpecTests/transactions/create-index.json
0 → 100644
View file @
a49468ea
{
"runOn"
:
[
{
"minServerVersion"
:
"4.3.4"
,
"topology"
:
[
"replicaset"
,
"sharded"
]
}
],
"database_name"
:
"transaction-tests"
,
"collection_name"
:
"test"
,
"data"
:
[],
"tests"
:
[
{
"description"
:
"create index on a non-existing collection"
,
"operations"
:
[
{
"name"
:
"dropCollection"
,
"object"
:
"database"
,
"arguments"
:
{
"collection"
:
"test"
}
},
{
"name"
:
"startTransaction"
,
"object"
:
"session0"
},
{
"name"
:
"createIndex"
,
"object"
:
"collection"
,
"arguments"
:
{
"session"
:
"session0"
,
"name"
:
"t_1"
,
"keys"
:
{
"x"
:
1
}
}
},
{
"name"
:
"assertIndexNotExists"
,
"object"
:
"testRunner"
,
"arguments"
:
{
"database"
:
"transaction-tests"
,
"collection"
:
"test"
,
"index"
:
"t_1"
}
},
{
"name"
:
"commitTransaction"
,
"object"
:
"session0"
},
{
"name"
:
"assertIndexExists"
,
"object"
:
"testRunner"
,
"arguments"
:
{
"database"
:
"transaction-tests"
,
"collection"
:
"test"
,
"index"
:
"t_1"
}
}
],
"expectations"
:
[
{
"command_started_event"
:
{
"command"
:
{
"drop"
:
"test"
,
"writeConcern"
:
null
},
"command_name"
:
"drop"
,
"database_name"
:
"transaction-tests"
}
},
{
"command_started_event"
:
{
"command"
:
{
"createIndexes"
:
"test"
,
"indexes"
:
[
{
"name"
:
"t_1"
,
"key"
:
{
"x"
:
1
}
}
],
"lsid"
:
"session0"
,
"txnNumber"
:
{
"$numberLong"
:
"1"
},
"startTransaction"
:
true
,
"autocommit"
:
false
,
"writeConcern"
:
null
},
"command_name"
:
"createIndexes"
,
"database_name"
:
"transaction-tests"
}
},
{
"command_started_event"
:
{
"command"
:
{
"commitTransaction"
:
1
,
"lsid"
:
"session0"
,
"txnNumber"
:
{
"$numberLong"
:
"1"
},
"startTransaction"
:
null
,
"autocommit"
:
false
,
"writeConcern"
:
null
},
"command_name"
:
"commitTransaction"
,
"database_name"
:
"admin"
}
}
]
},
{
"description"
:
"create index on a collection created within the same transaction"
,
"operations"
:
[
{
"name"
:
"dropCollection"
,
"object"
:
"database"
,
"arguments"
:
{
"collection"
:
"test"
}
},
{
"name"
:
"startTransaction"
,
"object"
:
"session0"
},
{
"name"
:
"createCollection"
,
"object"
:
"database"
,
"arguments"
:
{
"session"
:
"session0"
,
"collection"
:
"test"
}
},
{
"name"
:
"createIndex"
,
"object"
:
"collection"
,
"arguments"
:
{
"session"
:
"session0"
,
"name"
:
"t_1"
,
"keys"
:
{
"x"
:
1
}
}
},
{
"name"
:
"assertIndexNotExists"
,
"object"
:
"testRunner"
,
"arguments"
:
{
"database"
:
"transaction-tests"
,
"collection"
:
"test"
,
"index"
:
"t_1"
}
},
{
"name"
:
"commitTransaction"
,
"object"
:
"session0"
},
{
"name"
:
"assertIndexExists"
,
"object"
:
"testRunner"
,
"arguments"
:
{
"database"
:
"transaction-tests"
,
"collection"
:
"test"
,
"index"
:
"t_1"
}
}
],
"expectations"
:
[
{
"command_started_event"
:
{
"command"
:
{
"drop"
:
"test"
,
"writeConcern"
:
null
},
"command_name"
:
"drop"
,
"database_name"
:
"transaction-tests"
}
},
{
"command_started_event"
:
{
"command"
:
{
"create"
:
"test"
,
"lsid"
:
"session0"
,
"txnNumber"
:
{
"$numberLong"
:
"1"
},
"startTransaction"
:
true
,
"autocommit"
:
false
,
"writeConcern"
:
null
},
"command_name"
:
"create"
,
"database_name"
:
"transaction-tests"
}
},
{
"command_started_event"
:
{
"command"
:
{
"createIndexes"
:
"test"
,
"indexes"
:
[
{
"name"
:
"t_1"
,
"key"
:
{
"x"
:
1
}
}
],
"lsid"
:
"session0"
,
"writeConcern"
:
null
},
"command_name"
:
"createIndexes"
,
"database_name"
:
"transaction-tests"
}
},
{
"command_started_event"
:
{
"command"
:
{
"commitTransaction"
:
1
,
"lsid"
:
"session0"
,
"txnNumber"
:
{
"$numberLong"
:
"1"
},
"startTransaction"
:
null
,
"autocommit"
:
false
,
"writeConcern"
:
null
},
"command_name"
:
"commitTransaction"
,
"database_name"
:
"admin"
}
}
]
}
]
}
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