Merge "registration: Allow extensions to specify which MW core versions they require"
[lhc/web/wiklou.git] / tests / phpunit / includes / objectcache / MultiWriteBagOStuffTest.php
1 <?php
2
3 /**
4 * @group Database
5 */
6 class MultiWriteBagOStuffTest extends MediaWikiTestCase {
7 /** @var HashBagOStuff */
8 private $cache1;
9 /** @var HashBagOStuff */
10 private $cache2;
11 /** @var MultiWriteBagOStuff */
12 private $cache;
13
14 protected function setUp() {
15 parent::setUp();
16
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 ) );
23 }
24
25 public function testSetImmediate() {
26 $key = wfRandomString();
27 $value = wfRandomString();
28 $this->cache->set( $key, $value );
29
30 // Set in tier 1
31 $this->assertEquals( $value, $this->cache1->get( $key ), 'Written to tier 1' );
32 // Set in tier 2
33 $this->assertEquals( $value, $this->cache2->get( $key ), 'Written to tier 2' );
34 }
35
36 public function testSetDelayed() {
37 $key = wfRandomString();
38 $value = wfRandomString();
39
40 // XXX: DeferredUpdates bound to transactions in CLI mode
41 $dbw = wfGetDB( DB_MASTER );
42 $dbw->begin();
43 $this->cache->set( $key, $value );
44
45 // Set in tier 1
46 $this->assertEquals( $value, $this->cache1->get( $key ), 'Written to tier 1' );
47 // Not yet set in tier 2
48 $this->assertEquals( false, $this->cache2->get( $key ), 'Not written to tier 2' );
49
50 $dbw->commit();
51
52 // Set in tier 2
53 $this->assertEquals( $value, $this->cache2->get( $key ), 'Written to tier 2' );
54 }
55 }