Page Menu
Home
WickedGov Phorge
Search
Configure Global Search
Log In
Files
F5979906
SqlBagOStuffIntegrationTest.php
No One
Temporary
Actions
Download File
Edit File
Delete File
View Transforms
Subscribe
Flag For Later
Award Token
Size
3 KB
Referenced Files
None
Subscribers
None
SqlBagOStuffIntegrationTest.php
View Options
<?php
/**
* @group BagOStuff
* @group Database
* @covers \SqlBagOStuff
*/
class
SqlBagOStuffIntegrationTest
extends
BagOStuffTestBase
{
protected
function
newCacheInstance
()
{
return
$this
->
getServiceContainer
()->
getObjectCacheFactory
()->
getInstance
(
CACHE_DB
);
}
public
function
testFallback
()
{
if
(
$this
->
getDb
()->
getType
()
!==
'mysql'
)
{
$this
->
markTestSkipped
(
"Does not work with sqlite and postgres"
);
}
global
$wgDBserver
,
$wgDBport
,
$wgDBname
,
$wgDBuser
,
$wgDBpassword
,
$wgDBtype
;
$cache
=
new
SqlBagOStuff
(
[
'keyspace'
=>
'test'
,
'servers'
=>
[
'pc1'
=>
[
'serverName'
=>
'db0'
,
'host'
=>
$wgDBserver
,
'port'
=>
$wgDBport
,
'dbname'
=>
$wgDBname
,
'user'
=>
$wgDBuser
,
'password'
=>
$wgDBpassword
,
'type'
=>
$wgDBtype
,
],
'pc2'
=>
[
'serverName'
=>
'db1'
,
'host'
=>
$wgDBserver
.
'nocoonection'
,
'port'
=>
$wgDBport
,
'dbname'
=>
$wgDBname
.
'nocoonection'
,
'user'
=>
$wgDBuser
.
'nocoonection'
,
'password'
=>
$wgDBpassword
.
'nocoonection'
,
'type'
=>
$wgDBtype
,
]
],
'shards'
=>
1
]
);
// around half of these must fallback. Test shows keyname3 does.
for
(
$i
=
0
;
$i
<
10
;
$i
++
)
{
$cache
->
set
(
'keyname'
.
(
string
)
$i
,
'value'
.
(
string
)
$i
);
$res
=
$cache
->
get
(
'keyname'
.
(
string
)
$i
);
$this
->
assertSame
(
'value'
.
(
string
)
$i
,
$res
);
}
// Testing getMulti
$keys
=
[];
for
(
$i
=
0
;
$i
<
10
;
$i
++
)
{
$cache
->
set
(
'keyname'
.
(
string
)
$i
,
'value'
.
(
string
)
$i
);
$keys
[]
=
'keyname'
.
(
string
)
$i
;
}
$res
=
$cache
->
getMulti
(
$keys
);
for
(
$i
=
0
;
$i
<
10
;
$i
++
)
{
$this
->
assertSame
(
'value'
.
(
string
)
$i
,
$res
[
'keyname'
.
(
string
)
$i
]
);
}
}
public
function
testDataRedundancy
()
{
$dbFileName1
=
$this
->
getNewTempFile
();
$dbFileName2
=
$this
->
getNewTempFile
();
$cache
=
new
SqlBagOStuff
(
[
'keyspace'
=>
'test'
,
'servers'
=>
[
'ms1'
=>
[
'serverName'
=>
'db0'
,
'dbname'
=>
'unittest_ms1'
,
'type'
=>
'sqlite'
,
'dbFilePath'
=>
$dbFileName1
,
],
'ms2'
=>
[
'serverName'
=>
'db1'
,
'dbname'
=>
'unittest_ms2'
,
'type'
=>
'sqlite'
,
'dbFilePath'
=>
$dbFileName2
,
]
],
'shards'
=>
1
,
'dataRedundancy'
=>
2
,
]
);
for
(
$i
=
0
;
$i
<
10
;
$i
++
)
{
$cache
->
set
(
'keyname'
.
(
string
)
$i
,
'value'
.
(
string
)
$i
,
60
);
$res
=
$cache
->
get
(
'keyname'
.
(
string
)
$i
);
$this
->
assertSame
(
'value'
.
(
string
)
$i
,
$res
);
}
// Testing getMulti
$keys
=
[];
for
(
$i
=
0
;
$i
<
10
;
$i
++
)
{
$cache
->
set
(
'keyname'
.
(
string
)
$i
,
'value'
.
(
string
)
$i
,
60
);
$keys
[]
=
'keyname'
.
(
string
)
$i
;
}
$res
=
$cache
->
getMulti
(
$keys
);
for
(
$i
=
0
;
$i
<
10
;
$i
++
)
{
$this
->
assertSame
(
'value'
.
(
string
)
$i
,
$res
[
'keyname'
.
(
string
)
$i
]
);
}
// Now let's depool ms2
$cacheDepooled
=
new
SqlBagOStuff
(
[
'keyspace'
=>
'test'
,
'servers'
=>
[
'ms1'
=>
[
'serverName'
=>
'db0'
,
'dbname'
=>
'unittest_ms1'
,
'type'
=>
'sqlite'
,
'dbFilePath'
=>
$dbFileName1
,
]
],
'shards'
=>
1
]
);
$keys
=
[];
for
(
$i
=
0
;
$i
<
10
;
$i
++
)
{
// Picking slightly higher TTL so the exptime ends up higher. In reality it doesn't matter
// but unittest runs all of this under 1 second so the exptime ends up being the same.
$cacheDepooled
->
set
(
'keyname'
.
(
string
)
$i
,
'valueNewer'
.
(
string
)
$i
,
61
);
$keys
[]
=
'keyname'
.
(
string
)
$i
;
}
$res
=
$cache
->
getMulti
(
$keys
);
for
(
$i
=
0
;
$i
<
10
;
$i
++
)
{
// Must give the newer value only!
$this
->
assertSame
(
'valueNewer'
.
(
string
)
$i
,
$res
[
'keyname'
.
(
string
)
$i
]
);
}
// Also checking when the value is only set in one cache
$cacheDepooled
->
set
(
'keyname2025'
,
'value2025'
,
60
);
$this
->
assertSame
(
'value2025'
,
$cache
->
get
(
'keyname2025'
)
);
}
}
File Metadata
Details
Attached
Mime Type
text/x-php
Expires
Sat, Oct 3, 21:08 (5 d, 16 h ago)
Storage Engine
local-disk
Storage Format
Raw Data
Storage Handle
c8/5d/d09748f014ca21a815e2167b789e
Default Alt Text
SqlBagOStuffIntegrationTest.php (3 KB)
Attached To
Mode
rMWPROD MediaWiki Production
Attached
Detach File
Event Timeline
Log In to Comment