Page Menu
Home
WickedGov Phorge
Search
Configure Global Search
Log In
Files
F7406720
ServerInfoTest.php
No One
Temporary
Actions
Download File
Edit File
Delete File
View Transforms
Subscribe
Flag For Later
Award Token
Size
5 KB
Referenced Files
None
Subscribers
None
ServerInfoTest.php
View Options
<?php
use
PHPUnit\Framework\TestCase
;
use
Wikimedia\Rdbms\ServerInfo
;
/**
* @covers \Wikimedia\Rdbms\ServerInfo
*/
class
ServerInfoTest
extends
TestCase
{
use
MediaWikiCoversValidator
;
private
function
serverConfigs
(
$extra
=
[],
$flags
=
DBO_DEFAULT
)
{
return
[
// Primary DB
0
=>
$extra
+
[
'host'
=>
'db0'
,
'serverName'
=>
'testhost0'
,
'dbname'
=>
'testwiki'
,
'tablePrefix'
=>
'prefix'
,
'user'
=>
'dbuser'
,
'password'
=>
'verystrongpassword'
,
'type'
=>
'mysql'
,
'flags'
=>
$flags
,
'load'
=>
0
,
],
// Main replica DBs
1
=>
$extra
+
[
'host'
=>
'db1'
,
'serverName'
=>
'testhost1'
,
'dbname'
=>
'testwiki'
,
'tablePrefix'
=>
'prefix'
,
'user'
=>
'dbuser'
,
'password'
=>
'verystrongpassword'
,
'type'
=>
'mysql'
,
'flags'
=>
$flags
,
'load'
=>
100
,
],
2
=>
$extra
+
[
'host'
=>
'db2'
,
'serverName'
=>
'testhost2'
,
'dbname'
=>
'testwiki'
,
'tablePrefix'
=>
'prefix'
,
'user'
=>
'dbuser'
,
'password'
=>
'verystrongpassword'
,
'type'
=>
'mysql'
,
'flags'
=>
$flags
,
'load'
=>
100
,
],
// RC replica DBs
3
=>
$extra
+
[
'host'
=>
'db3'
,
'serverName'
=>
'testhost3'
,
'dbname'
=>
'testwiki'
,
'tablePrefix'
=>
'prefix'
,
'user'
=>
'dbuser'
,
'password'
=>
'verystrongpassword'
,
'type'
=>
'mysql'
,
'flags'
=>
$flags
,
'load'
=>
0
,
'groupLoads'
=>
[
'foo'
=>
100
,
'bar'
=>
100
],
],
// Logging replica DBs
4
=>
$extra
+
[
'host'
=>
'db4'
,
'serverName'
=>
'testhost4'
,
'dbname'
=>
'testwiki'
,
'tablePrefix'
=>
'prefix'
,
'user'
=>
'dbuser'
,
'password'
=>
'verystrongpassword'
,
'type'
=>
'mysql'
,
'flags'
=>
$flags
,
'load'
=>
0
,
'groupLoads'
=>
[
'baz'
=>
100
],
],
5
=>
$extra
+
[
'host'
=>
'db5'
,
'serverName'
=>
'testhost5'
,
'dbname'
=>
'testwiki'
,
'tablePrefix'
=>
'prefix'
,
'user'
=>
'dbuser'
,
'password'
=>
'verystrongpassword'
,
'type'
=>
'mysql'
,
'flags'
=>
$flags
,
'load'
=>
0
,
'groupLoads'
=>
[
'baz'
=>
100
],
],
// Maintenance query replica DBs
6
=>
$extra
+
[
'host'
=>
'db6'
,
'serverName'
=>
'testhost6'
,
'dbname'
=>
'testwiki'
,
'tablePrefix'
=>
'prefix'
,
'user'
=>
'dbuser'
,
'password'
=>
'verystrongpassword'
,
'type'
=>
'mysql'
,
'flags'
=>
$flags
,
'load'
=>
0
,
'groupLoads'
=>
[
'vslow'
=>
100
],
],
// Replica DB that only has a copy of some static tables
7
=>
$extra
+
[
'host'
=>
'db7'
,
'serverName'
=>
'testhost7'
,
'dbname'
=>
'testwiki'
,
'tablePrefix'
=>
'prefix'
,
'user'
=>
'dbuser'
,
'password'
=>
'verystrongpassword'
,
'type'
=>
'mysql'
,
'flags'
=>
$flags
,
'load'
=>
0
,
'groupLoads'
=>
[
'archive'
=>
100
],
'is static'
=>
true
]
];
}
private
function
createInfoHolderFromArray
(
$servers
):
ServerInfo
{
$holder
=
new
ServerInfo
();
foreach
(
$holder
->
normalizeServerMaps
(
$servers
)
as
$i
=>
$server
)
{
$holder
->
addServer
(
$i
,
$server
);
}
return
$holder
;
}
public
function
testWithoutReplica
()
{
$primaryInfo
=
$this
->
serverConfigs
()[
0
];
$holder
=
$this
->
createInfoHolderFromArray
(
[
$primaryInfo
]
);
$primaryInfo
[
'groupLoads'
]
=
[];
$this
->
assertSame
(
1
,
$holder
->
getServerCount
()
);
$this
->
assertFalse
(
$holder
->
hasReplicaServers
()
);
$this
->
assertFalse
(
$holder
->
hasStreamingReplicaServers
()
);
$this
->
assertTrue
(
$holder
->
hasServerIndex
(
0
)
);
$this
->
assertFalse
(
$holder
->
hasServerIndex
(
1
)
);
$this
->
assertFalse
(
$holder
->
hasServerIndex
(
999
)
);
$this
->
assertSame
(
$primaryInfo
,
$holder
->
getServerInfo
(
0
)
);
$this
->
assertSame
(
$primaryInfo
,
$holder
->
getServerInfoStrict
(
0
)
);
$this
->
assertSame
(
'testhost0'
,
$holder
->
getPrimaryServerName
()
);
}
public
function
testWithReplica
()
{
// Simulate web request with DBO_TRX
$holder
=
$this
->
createInfoHolderFromArray
(
$this
->
serverConfigs
(
[],
DBO_TRX
)
);
$this
->
assertSame
(
8
,
$holder
->
getServerCount
()
);
$this
->
assertTrue
(
$holder
->
hasReplicaServers
()
);
$this
->
assertTrue
(
$holder
->
hasStreamingReplicaServers
()
);
$this
->
assertSame
(
'testhost0'
,
$holder
->
getPrimaryServerName
()
);
for
(
$i
=
0
;
$i
<
$holder
->
getServerCount
();
++
$i
)
{
$this
->
assertIsString
(
$holder
->
getServerName
(
$i
)
);
$this
->
assertIsArray
(
$holder
->
getServerInfo
(
$i
)
);
$this
->
assertIsString
(
$holder
->
getServerType
(
$i
)
);
}
$this
->
assertFalse
(
$holder
->
hasServerIndex
(
999
)
);
}
public
function
testNonExistentServerInfoStrict
()
{
$holder
=
$this
->
createInfoHolderFromArray
(
$this
->
serverConfigs
(
[],
DBO_TRX
)
);
$this
->
expectException
(
InvalidArgumentException
::
class
);
$holder
->
getServerInfoStrict
(
999
);
}
public
function
testNonExistentFieldInfoStrict
()
{
$holder
=
$this
->
createInfoHolderFromArray
(
$this
->
serverConfigs
(
[],
DBO_TRX
)
);
$this
->
expectException
(
InvalidArgumentException
::
class
);
$holder
->
getServerInfoStrict
(
0
,
'non-existent-field'
);
}
}
File Metadata
Details
Attached
Mime Type
text/x-php
Expires
Sat, Nov 21, 20:34 (1 w, 4 d ago)
Storage Engine
local-disk
Storage Format
Raw Data
Storage Handle
cc/ec/ae618b2da2334ca8acc1942fccf8
Default Alt Text
ServerInfoTest.php (5 KB)
Attached To
Mode
rMWPROD MediaWiki Production
Attached
Detach File
Event Timeline
Log In to Comment