Skip to content

Commit ec5a5ac

Browse files
authored
Merge pull request #63 from sandrokeil/feature/disable-isolated
Allow to disable MongoDB $isolated
2 parents 98e5cd7 + 4405efa commit ec5a5ac

6 files changed

+83
-11
lines changed

.travis.yml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
language: php
22

33
php:
4-
- 5.5
54
- 5.6
65
- 7
76

src/Container/MongoDbEventStoreAdapterFactory.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,8 @@ public function __invoke(ContainerInterface $container)
5858
$config['db_name'],
5959
$config['write_concern'],
6060
$config['transaction_timeout'],
61-
$config['stream_collection_map']
61+
$config['stream_collection_map'],
62+
!empty($config['disable_isolated']) ? true : false
6263
);
6364
}
6465

src/MongoDbEventStoreAdapter.php

Lines changed: 23 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,15 @@ final class MongoDbEventStoreAdapter implements Adapter, CanHandleTransaction
8989
*/
9090
private $streamCollectionMap = [];
9191

92+
/**
93+
* Disable $isolated in MongoDB update
94+
*
95+
* This is only useful if you want to upgrade to MongoDB 4.0
96+
*
97+
* @var bool
98+
*/
99+
private $disableIsolated;
100+
92101
/**
93102
* @param MessageFactory $messageFactory
94103
* @param MessageConverter $messageConverter
@@ -97,6 +106,7 @@ final class MongoDbEventStoreAdapter implements Adapter, CanHandleTransaction
97106
* @param array|null $writeConcern
98107
* @param int|null $transactionTimeout
99108
* @param array $streamCollectionMap
109+
* @param bool $disableIsolated
100110
*/
101111
public function __construct(
102112
MessageFactory $messageFactory,
@@ -105,7 +115,8 @@ public function __construct(
105115
$dbName,
106116
array $writeConcern = null,
107117
$transactionTimeout = null,
108-
array $streamCollectionMap = []
118+
array $streamCollectionMap = [],
119+
$disableIsolated = false
109120
) {
110121
Assertion::minLength($dbName, 1, 'Mongo database name is missing');
111122

@@ -114,6 +125,7 @@ public function __construct(
114125
$this->mongoClient = $mongoClient;
115126
$this->dbName = $dbName;
116127
$this->streamCollectionMap = $streamCollectionMap;
128+
$this->disableIsolated = (bool)$disableIsolated;
117129

118130
if (null !== $writeConcern) {
119131
$this->writeConcern = $writeConcern;
@@ -302,12 +314,18 @@ public function commit()
302314

303315
$updateBatch = $this->getUpdateBatch($this->currentStreamName);
304316

317+
$q = [
318+
'transaction_id' => $this->transactionId,
319+
'$isolated' => 1
320+
];
321+
322+
if ($this->disableIsolated) {
323+
unset($q['$isolated']);
324+
}
325+
305326
$updateBatch->add(
306327
[
307-
'q' => [
308-
'transaction_id' => $this->transactionId,
309-
'$isolated' => 1
310-
],
328+
'q' => $q,
311329
'u' => [
312330
'$unset' => [
313331
'expire_at' => 1,

tests/MongoDbEventStoreAdapterTest.php renamed to tests/AbstractMongoDbEventStoreAdapterTest.php

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,17 +24,17 @@
2424
* Class MongoDbEventStoreAdapterTest
2525
* @package ProophTest\EventStore\Adapter\MongoDb
2626
*/
27-
final class MongoDbEventStoreAdapterTest extends TestCase
27+
abstract class AbstractMongoDbEventStoreAdapterTest extends TestCase
2828
{
2929
/**
3030
* @var MongoDbEventStoreAdapter
3131
*/
32-
private $adapter;
32+
protected $adapter;
3333

3434
/**
3535
* @var \MongoClient
3636
*/
37-
private $client;
37+
protected $client;
3838

3939
protected function setUp()
4040
{
@@ -47,10 +47,16 @@ protected function setUp()
4747
new FQCNMessageFactory(),
4848
new NoOpMessageConverter(),
4949
$this->client,
50-
$dbName
50+
$dbName,
51+
null,
52+
null,
53+
[],
54+
$this->disableIsolated()
5155
);
5256
}
5357

58+
abstract public function disableIsolated();
59+
5460
protected function tearDown()
5561
{
5662
if (null !== $this->client) {
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
<?php
2+
/*
3+
* This file is part of the prooph/event-store-mongodb-adapter.
4+
* (c) 2014 - 2015 prooph software GmbH <[email protected]>
5+
*
6+
* For the full copyright and license information, please view the LICENSE
7+
* file that was distributed with this source code.
8+
*
9+
* Date: 08/08/15 - 20:32
10+
*/
11+
12+
namespace ProophTest\EventStore\Adapter\MongoDb;
13+
14+
/**
15+
* Class MongoDbEventStoreAdapterTest
16+
* @package ProophTest\EventStore\Adapter\MongoDb
17+
*/
18+
final class MongoDbEventStoreAdapterDisabledIsolatedTest extends AbstractMongoDbEventStoreAdapterTest
19+
{
20+
public function disableIsolated()
21+
{
22+
return true;
23+
}
24+
}
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
<?php
2+
/*
3+
* This file is part of the prooph/event-store-mongodb-adapter.
4+
* (c) 2014 - 2015 prooph software GmbH <[email protected]>
5+
*
6+
* For the full copyright and license information, please view the LICENSE
7+
* file that was distributed with this source code.
8+
*
9+
* Date: 08/08/15 - 20:32
10+
*/
11+
12+
namespace ProophTest\EventStore\Adapter\MongoDb;
13+
14+
/**
15+
* Class MongoDbEventStoreAdapterTest
16+
* @package ProophTest\EventStore\Adapter\MongoDb
17+
*/
18+
final class MongoDbEventStoreAdapterIsolatedTest extends AbstractMongoDbEventStoreAdapterTest
19+
{
20+
public function disableIsolated()
21+
{
22+
return false;
23+
}
24+
}

0 commit comments

Comments
 (0)