6 class MultiWriteBagOStuffTest
extends MediaWikiTestCase
{
7 /** @var HashBagOStuff */
9 /** @var HashBagOStuff */
11 /** @var MultiWriteBagOStuff */
14 protected function setUp() {
17 $this->cache1
= new HashBagOStuff();
18 $this->cache2
= new HashBagOStuff();
19 $this->cache
= new MultiWriteBagOStuff( array(
20 'caches' => array( $this->cache1
, $this->cache2
),
21 'replication' => 'async',
22 'asyncHandler' => 'DeferredUpdates::addCallableUpdate'
26 public function testSetImmediate() {
27 $key = wfRandomString();
28 $value = wfRandomString();
29 $this->cache
->set( $key, $value );
32 $this->assertEquals( $value, $this->cache1
->get( $key ), 'Written to tier 1' );
34 $this->assertEquals( $value, $this->cache2
->get( $key ), 'Written to tier 2' );
37 public function testSyncMerge() {
38 $key = wfRandomString();
39 $value = wfRandomString();
40 $func = function () use ( $value ) {
44 // XXX: DeferredUpdates bound to transactions in CLI mode
45 $dbw = wfGetDB( DB_MASTER
);
47 $this->cache
->merge( $key, $func );
50 $this->assertEquals( $value, $this->cache1
->get( $key ), 'Written to tier 1' );
51 // Not yet set in tier 2
52 $this->assertEquals( false, $this->cache2
->get( $key ), 'Not written to tier 2' );
57 $this->assertEquals( $value, $this->cache2
->get( $key ), 'Written to tier 2' );
59 $key = wfRandomString();
62 $this->cache
->merge( $key, $func, 0, 1, BagOStuff
::WRITE_SYNC
);
65 $this->assertEquals( $value, $this->cache1
->get( $key ), 'Written to tier 1' );
67 $this->assertEquals( $value, $this->cache2
->get( $key ), 'Written to tier 2' );
72 public function testSetDelayed() {
73 $key = wfRandomString();
74 $value = wfRandomString();
76 // XXX: DeferredUpdates bound to transactions in CLI mode
77 $dbw = wfGetDB( DB_MASTER
);
79 $this->cache
->set( $key, $value );
82 $this->assertEquals( $value, $this->cache1
->get( $key ), 'Written to tier 1' );
83 // Not yet set in tier 2
84 $this->assertEquals( false, $this->cache2
->get( $key ), 'Not written to tier 2' );
89 $this->assertEquals( $value, $this->cache2
->get( $key ), 'Written to tier 2' );