MediaWiki
REL1_31
ReplicatedBagOStuffTest.php
Go to the documentation of this file.
1
<?php
2
3
class
ReplicatedBagOStuffTest
extends
MediaWikiTestCase
{
5
private
$writeCache
;
7
private
$readCache
;
9
private
$cache
;
10
11
protected
function
setUp
() {
12
parent::setUp();
13
14
$this->writeCache =
new
HashBagOStuff
();
15
$this->readCache =
new
HashBagOStuff
();
16
$this->
cache
=
new
ReplicatedBagOStuff
( [
17
'writeFactory'
=> $this->writeCache,
18
'readFactory'
=> $this->readCache,
19
] );
20
}
21
25
public
function
testSet
() {
26
$key =
wfRandomString
();
27
$value
=
wfRandomString
();
28
$this->
cache
->set( $key,
$value
);
29
30
// Write to master.
31
$this->assertEquals( $this->writeCache->get( $key ),
$value
);
32
// Don't write to slave. Replication is deferred to backend.
33
$this->assertEquals( $this->readCache->get( $key ),
false
);
34
}
35
39
public
function
testGet
() {
40
$key =
wfRandomString
();
41
42
$write =
wfRandomString
();
43
$this->writeCache->set( $key, $write );
44
$read =
wfRandomString
();
45
$this->readCache->set( $key, $read );
46
47
// Read from slave.
48
$this->assertEquals( $this->
cache
->get( $key ), $read );
49
}
50
54
public
function
testGetAbsent
() {
55
$key =
wfRandomString
();
56
$value
=
wfRandomString
();
57
$this->writeCache->set( $key,
$value
);
58
59
// Don't read from master. No failover if value is absent.
60
$this->assertEquals( $this->
cache
->get( $key ),
false
);
61
}
62
}
wfRandomString
wfRandomString( $length=32)
Get a random string containing a number of pseudo-random hex characters.
Definition
GlobalFunctions.php:305
HashBagOStuff
Simple store for keeping values in an associative array for the current process.
Definition
HashBagOStuff.php:31
MediaWikiTestCase
Definition
MediaWikiTestCase.php:17
ReplicatedBagOStuffTest
Definition
ReplicatedBagOStuffTest.php:3
ReplicatedBagOStuffTest\testGetAbsent
testGetAbsent()
ReplicatedBagOStuff::get.
Definition
ReplicatedBagOStuffTest.php:54
ReplicatedBagOStuffTest\testGet
testGet()
ReplicatedBagOStuff::get.
Definition
ReplicatedBagOStuffTest.php:39
ReplicatedBagOStuffTest\testSet
testSet()
ReplicatedBagOStuff::set.
Definition
ReplicatedBagOStuffTest.php:25
ReplicatedBagOStuffTest\$readCache
HashBagOStuff $readCache
Definition
ReplicatedBagOStuffTest.php:7
ReplicatedBagOStuffTest\setUp
setUp()
Definition
ReplicatedBagOStuffTest.php:11
ReplicatedBagOStuffTest\$writeCache
HashBagOStuff $writeCache
Definition
ReplicatedBagOStuffTest.php:5
ReplicatedBagOStuffTest\$cache
ReplicatedBagOStuff $cache
Definition
ReplicatedBagOStuffTest.php:9
ReplicatedBagOStuff
A cache class that directs writes to one set of servers and reads to another.
Definition
ReplicatedBagOStuff.php:34
cache
you have access to all of the normal MediaWiki so you can get a DB use the cache
Definition
maintenance.txt:55
$value
$value
Definition
styleTest.css.php:45
tests
phpunit
includes
libs
objectcache
ReplicatedBagOStuffTest.php
Generated on Mon Nov 25 2024 15:36:25 for MediaWiki by
1.10.0