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() {
28 $this->cache
->set( $key, $value );
31 $this->assertEquals( $value, $this->writeCache
->get( $key ) );
32 // Don't write to replica. Replication is deferred to backend.
33 $this->assertFalse( $this->readCache
->get( $key ) );
37 * @covers ReplicatedBagOStuff::get
39 public function testGet() {
43 $this->writeCache
->set( $key, $write );
44 $read = 'another value';
45 $this->readCache
->set( $key, $read );
48 $this->assertEquals( $read, $this->cache
->get( $key ) );
52 * @covers ReplicatedBagOStuff::get
54 public function testGetAbsent() {
57 $this->writeCache
->set( $key, $value );
59 // Don't read from master. No failover if value is absent.
60 $this->assertFalse( $this->cache
->get( $key ) );