MediaWiki  1.30.2
ReplicatedBagOStuffTest.php
Go to the documentation of this file.
1 <?php
2 
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();
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();
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 }
false
processing should stop and the error should be shown to the user * false
Definition: hooks.txt:187
ReplicatedBagOStuffTest
Definition: ReplicatedBagOStuffTest.php:3
HashBagOStuff
Simple store for keeping values in an associative array for the current process.
Definition: HashBagOStuff.php:31
cache
you have access to all of the normal MediaWiki so you can get a DB use the cache
Definition: maintenance.txt:52
ReplicatedBagOStuffTest\testGetAbsent
testGetAbsent()
ReplicatedBagOStuff::get.
Definition: ReplicatedBagOStuffTest.php:54
php
injection txt This is an overview of how MediaWiki makes use of dependency injection The design described here grew from the discussion of RFC T384 The term dependency this means that anything an object needs to operate should be injected from the the object itself should only know narrow no concrete implementation of the logic it relies on The requirement to inject everything typically results in an architecture that based on two main types of and essentially stateless service objects that use other service objects to operate on the value objects As of the beginning MediaWiki is only starting to use the DI approach Much of the code still relies on global state or direct resulting in a highly cyclical dependency which acts as the top level factory for services in MediaWiki which can be used to gain access to default instances of various services MediaWikiServices however also allows new services to be defined and default services to be redefined Services are defined or redefined by providing a callback the instantiator that will return a new instance of the service When it will create an instance of MediaWikiServices and populate it with the services defined in the files listed by thereby bootstrapping the DI framework Per $wgServiceWiringFiles lists includes ServiceWiring php
Definition: injection.txt:35
ReplicatedBagOStuffTest\testSet
testSet()
ReplicatedBagOStuff::set.
Definition: ReplicatedBagOStuffTest.php:25
MediaWikiTestCase
Definition: MediaWikiTestCase.php:15
ReplicatedBagOStuffTest\$cache
ReplicatedBagOStuff $cache
Definition: ReplicatedBagOStuffTest.php:9
ReplicatedBagOStuffTest\$writeCache
HashBagOStuff $writeCache
Definition: ReplicatedBagOStuffTest.php:5
$value
$value
Definition: styleTest.css.php:45
ReplicatedBagOStuffTest\setUp
setUp()
Definition: ReplicatedBagOStuffTest.php:11
ReplicatedBagOStuffTest\$readCache
HashBagOStuff $readCache
Definition: ReplicatedBagOStuffTest.php:7
ReplicatedBagOStuffTest\testGet
testGet()
ReplicatedBagOStuff::get.
Definition: ReplicatedBagOStuffTest.php:39
ReplicatedBagOStuff
A cache class that directs writes to one set of servers and reads to another.
Definition: ReplicatedBagOStuff.php:33
wfRandomString
wfRandomString( $length=32)
Get a random string containing a number of pseudo-random hex characters.
Definition: GlobalFunctions.php:370