3 class ReplicatedBagOStuffTest
extends MediaWikiTestCase
{
4 /** @var HashBagOStuff */
6 /** @var HashBagOStuff */
8 /** @var ReplicatedBagOStuff */
11 protected function setUp() {
14 $this->writeCache
= new HashBagOStuff();
15 $this->readCache
= new HashBagOStuff();
16 $this->cache
= new ReplicatedBagOStuff( [
17 'writeFactory' => $this->writeCache
,
18 'readFactory' => $this->readCache
,
23 * @covers ReplicatedBagOStuff::set
25 public function testSet() {
26 $key = wfRandomString();
27 $value = wfRandomString();
28 $this->cache
->set( $key, $value );
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 );
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 );
48 $this->assertEquals( $this->cache
->get( $key ), $read );
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 );