Skip to content

Commit e98829b

Browse files
committed
Merge pull request #657
2 parents 261b605 + f9452d8 commit e98829b

File tree

6 files changed

+91
-4
lines changed

6 files changed

+91
-4
lines changed

mongo-orchestration/sharded_clusters/cluster.json

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,13 @@
7474
"logappend": true,
7575
"port": 4300,
7676
"bind_ip_all": true
77+
},
78+
{
79+
"logpath": "/tmp/SHARDED/ROUTER/4301/mongod.log",
80+
"ipv6": true,
81+
"logappend": true,
82+
"port": 4301,
83+
"bind_ip_all": true
7784
}
7885
]
7986
}

mongo-orchestration/sharded_clusters/cluster_replset.json

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,13 @@
9898
"logappend": true,
9999
"port": 4430,
100100
"bind_ip_all": true
101+
},
102+
{
103+
"logpath": "/tmp/SHARDED-RS/ROUTER/4431/mongod.log",
104+
"ipv6": true,
105+
"logappend": true,
106+
"port": 4431,
107+
"bind_ip_all": true
101108
}
102109
]
103110
}

tests/FunctionalTestCase.php

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,68 @@ public function tearDown()
3838
parent::tearDown();
3939
}
4040

41+
public static function getUri($allowMultipleMongoses = false)
42+
{
43+
$uri = parent::getUri();
44+
45+
if ($allowMultipleMongoses) {
46+
return $uri;
47+
}
48+
49+
$urlParts = parse_url($uri);
50+
if ($urlParts === false) {
51+
return $uri;
52+
}
53+
54+
// Only modify URIs using the mongodb scheme
55+
if ($urlParts['scheme'] !== 'mongodb') {
56+
return $uri;
57+
}
58+
59+
$hosts = explode(',', $urlParts['host']);
60+
$numHosts = count($hosts);
61+
if ($numHosts === 1) {
62+
return $uri;
63+
}
64+
65+
$manager = new Manager($uri);
66+
if ($manager->selectServer(new ReadPreference(ReadPreference::RP_PRIMARY))->getType() !== Server::TYPE_MONGOS) {
67+
return $uri;
68+
}
69+
70+
// Re-append port to last host
71+
if (isset($urlParts['port'])) {
72+
$hosts[$numHosts-1] .= ':' . $urlParts['port'];
73+
}
74+
75+
$parts = [
76+
'mongodb://'
77+
];
78+
79+
if (isset($urlParts['user'], $urlParts['pass'])) {
80+
$parts += [
81+
$urlParts['user'],
82+
':',
83+
$urlParts['pass'],
84+
'@',
85+
];
86+
}
87+
88+
$parts[] = $hosts[0];
89+
90+
if (isset($urlParts['path'])) {
91+
$parts[] = $urlParts['path'];
92+
}
93+
if (isset($urlParts['query'])) {
94+
$parts += [
95+
'?',
96+
$urlParts['path']
97+
];
98+
}
99+
100+
return implode('', $parts);
101+
}
102+
41103
protected function assertCollectionCount($namespace, $count)
42104
{
43105
list($databaseName, $collectionName) = explode('.', $namespace, 2);

tests/Operation/WatchFunctionalTest.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,14 +55,17 @@ public function testGetResumeToken()
5555
$this->insertDocument(['x' => 2]);
5656

5757
$changeStream->next();
58+
$this->assertTrue($changeStream->valid());
5859
$this->assertSameDocument($changeStream->current()->_id, $changeStream->getResumeToken());
5960

6061
$changeStream->next();
62+
$this->assertTrue($changeStream->valid());
6163
$this->assertSameDocument($changeStream->current()->_id, $changeStream->getResumeToken());
6264

6365
$this->insertDocument(['x' => 3]);
6466

6567
$changeStream->next();
68+
$this->assertTrue($changeStream->valid());
6669
$this->assertSameDocument($changeStream->current()->_id, $changeStream->getResumeToken());
6770
}
6871

@@ -116,6 +119,7 @@ function (array $event) use (&$events) {
116119
$postBatchResumeToken = $this->getPostBatchResumeTokenFromReply($events[0]['succeeded']->getReply());
117120

118121
$changeStream->next();
122+
$this->assertTrue($changeStream->valid());
119123
$this->assertSameDocument($changeStream->current()->_id, $changeStream->getResumeToken());
120124

121125
$changeStream->next();

tests/SpecTests/RetryableWritesSpecTest.php

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
namespace MongoDB\Tests\SpecTests;
44

55
use LogicException;
6+
use MongoDB\Driver\Manager;
67
use stdClass;
78

89
/**
@@ -22,9 +23,12 @@ class RetryableWritesSpecTest extends FunctionalTestCase
2223
*/
2324
public function testRetryableWrites(stdClass $test, array $runOn = null, array $data)
2425
{
25-
// TODO: Revise this once a test environment with multiple mongos nodes is available (see: PHPLIB-430)
26+
if ($this->isShardedCluster() && ! $this->isShardedClusterUsingReplicasets()) {
27+
$this->markTestSkipped('Transaction numbers are only allowed on a replica set member or mongos (PHPC-1415)');
28+
}
29+
2630
if (isset($test->useMultipleMongoses) && $test->useMultipleMongoses && $this->isShardedCluster()) {
27-
$this->markTestSkipped('"useMultipleMongoses" is not supported');
31+
$this->manager = new Manager(static::getUri(true));
2832
}
2933

3034
if (isset($runOn)) {

tests/SpecTests/TransactionsSpecTest.php

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -123,9 +123,12 @@ public function testTransactions(stdClass $test, array $runOn = null, array $dat
123123
$this->markTestIncomplete(self::$incompleteTests[$this->dataDescription()]);
124124
}
125125

126-
// TODO: Revise this once a test environment with multiple mongos nodes is available (see: PHPLIB-430)
126+
if ($this->isShardedCluster()) {
127+
$this->markTestSkipped('PHP MongoDB driver 1.6.0alpha2 does not support running multi-document transactions on sharded clusters');
128+
}
129+
127130
if (isset($test->useMultipleMongoses) && $test->useMultipleMongoses && $this->isShardedCluster()) {
128-
$this->markTestIncomplete('"useMultipleMongoses" is not supported');
131+
$this->manager = new Manager(static::getUri(true));
129132
}
130133

131134
if (isset($runOn)) {

0 commit comments

Comments
 (0)