rdbms: Rename "memCache" to "memStash" in LBFactory
[mediawiki.git] / tests / phpunit / includes / libs / objectcache / ReplicatedBagOStuffTest.php
blob1b502ec14bdcd5907b59c2bbfc9ca55c6a4f0f2c
1 <?php
3 class ReplicatedBagOStuffTest extends MediaWikiTestCase {
4 /** @var HashBagOStuff */
5 private $writeCache;
6 /** @var HashBagOStuff */
7 private $readCache;
8 /** @var ReplicatedBagOStuff */
9 private $cache;
11 protected function setUp() {
12 parent::setUp();
14 $this->writeCache = new HashBagOStuff();
15 $this->readCache = new HashBagOStuff();
16 $this->cache = new ReplicatedBagOStuff( [
17 'writeFactory' => $this->writeCache,
18 'readFactory' => $this->readCache,
19 ] );
22 /**
23 * @covers ReplicatedBagOStuff::set
25 public function testSet() {
26 $key = wfRandomString();
27 $value = wfRandomString();
28 $this->cache->set( $key, $value );
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 );
36 /**
37 * @covers ReplicatedBagOStuff::get
39 public function testGet() {
40 $key = wfRandomString();
42 $write = wfRandomString();
43 $this->writeCache->set( $key, $write );
44 $read = wfRandomString();
45 $this->readCache->set( $key, $read );
47 // Read from slave.
48 $this->assertEquals( $this->cache->get( $key ), $read );
51 /**
52 * @covers ReplicatedBagOStuff::get
54 public function testGetAbsent() {
55 $key = wfRandomString();
56 $value = wfRandomString();
57 $this->writeCache->set( $key, $value );
59 // Don't read from master. No failover if value is absent.
60 $this->assertEquals( $this->cache->get( $key ), false );