Import: Handle uploads with sha1 starting with 0 properly
[mediawiki.git] / tests / phpunit / includes / libs / objectcache / MultiWriteBagOStuffTest.php
blob1d8f43a0e0868655c44ee236e02e6cfc20b2a8a0
1 <?php
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;
14 protected function setUp() {
15 parent::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'
23 ) );
26 public function testSetImmediate() {
27 $key = wfRandomString();
28 $value = wfRandomString();
29 $this->cache->set( $key, $value );
31 // Set in tier 1
32 $this->assertEquals( $value, $this->cache1->get( $key ), 'Written to tier 1' );
33 // Set in tier 2
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 ) {
41 return $value;
44 // XXX: DeferredUpdates bound to transactions in CLI mode
45 $dbw = wfGetDB( DB_MASTER );
46 $dbw->begin();
47 $this->cache->merge( $key, $func );
49 // Set in tier 1
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' );
54 $dbw->commit();
56 // Set in tier 2
57 $this->assertEquals( $value, $this->cache2->get( $key ), 'Written to tier 2' );
59 $key = wfRandomString();
61 $dbw->begin();
62 $this->cache->merge( $key, $func, 0, 1, BagOStuff::WRITE_SYNC );
64 // Set in tier 1
65 $this->assertEquals( $value, $this->cache1->get( $key ), 'Written to tier 1' );
66 // Also set in tier 2
67 $this->assertEquals( $value, $this->cache2->get( $key ), 'Written to tier 2' );
69 $dbw->commit();
72 public function testSetDelayed() {
73 $key = wfRandomString();
74 $value = wfRandomString();
76 // XXX: DeferredUpdates bound to transactions in CLI mode
77 $dbw = wfGetDB( DB_MASTER );
78 $dbw->begin();
79 $this->cache->set( $key, $value );
81 // Set in tier 1
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' );
86 $dbw->commit();
88 // Set in tier 2
89 $this->assertEquals( $value, $this->cache2->get( $key ), 'Written to tier 2' );