MediaWiki REL1_31
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}
wfRandomString( $length=32)
Get a random string containing a number of pseudo-random hex characters.
Simple store for keeping values in an associative array for the current process.
testGetAbsent()
ReplicatedBagOStuff::get.
testGet()
ReplicatedBagOStuff::get.
testSet()
ReplicatedBagOStuff::set.
A cache class that directs writes to one set of servers and reads to another.
you have access to all of the normal MediaWiki so you can get a DB use the cache