jenkins-bot has submitted this change and it was merged. ( 
https://gerrit.wikimedia.org/r/358999 )

Change subject: objectcache: Forward MultiWriteBagOStuff::makeKey to primary 
backend
......................................................................


objectcache: Forward MultiWriteBagOStuff::makeKey to primary backend

Similar to what WANObjectCache and CachedBagOStuff are already doing.

Also add missing tests for WANObjectCache (similar to those for 
CachedBagOStuff).

Bug: T167465
Change-Id: I1a0c9324726aa6a1b221def985773b1b819181fd
---
M includes/libs/objectcache/MultiWriteBagOStuff.php
M tests/phpunit/includes/libs/objectcache/MultiWriteBagOStuffTest.php
M tests/phpunit/includes/libs/objectcache/WANObjectCacheTest.php
3 files changed, 79 insertions(+), 0 deletions(-)

Approvals:
  Gergő Tisza: Looks good to me, but someone else must approve
  Brion VIBBER: Looks good to me, approved
  jenkins-bot: Verified



diff --git a/includes/libs/objectcache/MultiWriteBagOStuff.php 
b/includes/libs/objectcache/MultiWriteBagOStuff.php
index 9dcfa7c..687c67c 100644
--- a/includes/libs/objectcache/MultiWriteBagOStuff.php
+++ b/includes/libs/objectcache/MultiWriteBagOStuff.php
@@ -226,4 +226,12 @@
 
                return $ret;
        }
+
+       public function makeKey() {
+               return call_user_func_array( [ $this->caches[0], __FUNCTION__ 
], func_get_args() );
+       }
+
+       public function makeGlobalKey() {
+               return call_user_func_array( [ $this->caches[0], __FUNCTION__ 
], func_get_args() );
+       }
 }
diff --git 
a/tests/phpunit/includes/libs/objectcache/MultiWriteBagOStuffTest.php 
b/tests/phpunit/includes/libs/objectcache/MultiWriteBagOStuffTest.php
index 38d63e3..775709f 100644
--- a/tests/phpunit/includes/libs/objectcache/MultiWriteBagOStuffTest.php
+++ b/tests/phpunit/includes/libs/objectcache/MultiWriteBagOStuffTest.php
@@ -98,4 +98,39 @@
                // Set in tier 2
                $this->assertEquals( $value, $this->cache2->get( $key ), 
'Written to tier 2' );
        }
+
+       /**
+        * @covers MultiWriteBagOStuff::makeKey
+        */
+       public function testMakeKey() {
+               $cache1 = $this->getMockBuilder( HashBagOStuff::class )
+                       ->setMethods( [ 'makeKey' ] )->getMock();
+               $cache1->expects( $this->once() )->method( 'makeKey' )
+                       ->willReturn( 'special' );
+
+               $cache2 = $this->getMockBuilder( HashBagOStuff::class )
+                       ->setMethods( [ 'makeKey' ] )->getMock();
+               $cache2->expects( $this->never() )->method( 'makeKey' );
+
+               $cache = new MultiWriteBagOStuff( [ 'caches' => [ $cache1, 
$cache2 ] ] );
+               $this->assertSame( 'special', $cache->makeKey( 'a', 'b' ) );
+       }
+
+       /**
+        * @covers MultiWriteBagOStuff::makeGlobalKey
+        */
+       public function testMakeGlobalKey() {
+               $cache1 = $this->getMockBuilder( HashBagOStuff::class )
+                       ->setMethods( [ 'makeGlobalKey' ] )->getMock();
+               $cache1->expects( $this->once() )->method( 'makeGlobalKey' )
+                       ->willReturn( 'special' );
+
+               $cache2 = $this->getMockBuilder( HashBagOStuff::class )
+                       ->setMethods( [ 'makeGlobalKey' ] )->getMock();
+               $cache2->expects( $this->never() )->method( 'makeGlobalKey' );
+
+               $cache = new MultiWriteBagOStuff( [ 'caches' => [ $cache1, 
$cache2 ] ] );
+
+               $this->assertSame( 'special', $cache->makeGlobalKey( 'a', 'b' ) 
);
+       }
 }
diff --git a/tests/phpunit/includes/libs/objectcache/WANObjectCacheTest.php 
b/tests/phpunit/includes/libs/objectcache/WANObjectCacheTest.php
index 728e671..2b04366 100644
--- a/tests/phpunit/includes/libs/objectcache/WANObjectCacheTest.php
+++ b/tests/phpunit/includes/libs/objectcache/WANObjectCacheTest.php
@@ -1191,4 +1191,40 @@
                        [ null, 86400, 800, .2, 800 ]
                ];
        }
+
+       /**
+        * @covers WANObjectCache::makeKey
+        */
+       public function testMakeKey() {
+               $backend = $this->getMockBuilder( HashBagOStuff::class )
+                       ->setMethods( [ 'makeKey' ] )->getMock();
+               $backend->expects( $this->once() )->method( 'makeKey' )
+                       ->willReturn( 'special' );
+
+               $wanCache = new WANObjectCache( [
+                       'cache' => $backend,
+                       'pool' => 'testcache-hash',
+                       'relayer' => new EventRelayerNull( [] )
+               ] );
+
+               $this->assertSame( 'special', $wanCache->makeKey( 'a', 'b' ) );
+       }
+
+       /**
+        * @covers WANObjectCache::makeGlobalKey
+        */
+       public function testMakeGlobalKey() {
+               $backend = $this->getMockBuilder( HashBagOStuff::class )
+                       ->setMethods( [ 'makeGlobalKey' ] )->getMock();
+               $backend->expects( $this->once() )->method( 'makeGlobalKey' )
+                       ->willReturn( 'special' );
+
+               $wanCache = new WANObjectCache( [
+                       'cache' => $backend,
+                       'pool' => 'testcache-hash',
+                       'relayer' => new EventRelayerNull( [] )
+               ] );
+
+               $this->assertSame( 'special', $wanCache->makeGlobalKey( 'a', 
'b' ) );
+       }
 }

-- 
To view, visit https://gerrit.wikimedia.org/r/358999
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: merged
Gerrit-Change-Id: I1a0c9324726aa6a1b221def985773b1b819181fd
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/core
Gerrit-Branch: master
Gerrit-Owner: Krinkle <krinklem...@gmail.com>
Gerrit-Reviewer: Aaron Schulz <asch...@wikimedia.org>
Gerrit-Reviewer: Brion VIBBER <br...@wikimedia.org>
Gerrit-Reviewer: Gergő Tisza <gti...@wikimedia.org>
Gerrit-Reviewer: Krinkle <krinklem...@gmail.com>
Gerrit-Reviewer: Legoktm <lego...@member.fsf.org>
Gerrit-Reviewer: jenkins-bot <>

_______________________________________________
MediaWiki-commits mailing list
MediaWiki-commits@lists.wikimedia.org
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to