diff options
author | jenkins-bot <jenkins-bot@gerrit.wikimedia.org> | 2023-08-02 22:26:21 +0000 |
---|---|---|
committer | Gerrit Code Review <gerrit@wikimedia.org> | 2023-08-02 22:26:21 +0000 |
commit | 4a27e538c30368a50d0de9f825f719202223a30e (patch) | |
tree | b1a53815750f92a81776d342b54580f24bb90b73 | |
parent | 87ebc862e960a69453080973d2b22141ffce3899 (diff) | |
parent | e5406a01a53989f301fd09c7aa932bd68a32a8b7 (diff) | |
download | mediawikicore-4a27e538c30368a50d0de9f825f719202223a30e.tar.gz mediawikicore-4a27e538c30368a50d0de9f825f719202223a30e.zip |
Merge "objectcache: Add test for key re-encoding in MultiBagOStuff"
-rw-r--r-- | tests/phpunit/includes/libs/objectcache/MultiWriteBagOStuffTest.php | 47 |
1 files changed, 47 insertions, 0 deletions
diff --git a/tests/phpunit/includes/libs/objectcache/MultiWriteBagOStuffTest.php b/tests/phpunit/includes/libs/objectcache/MultiWriteBagOStuffTest.php index c77436181028..2ac20ce265b4 100644 --- a/tests/phpunit/includes/libs/objectcache/MultiWriteBagOStuffTest.php +++ b/tests/phpunit/includes/libs/objectcache/MultiWriteBagOStuffTest.php @@ -141,6 +141,53 @@ class MultiWriteBagOStuffTest extends MediaWikiIntegrationTestCase { $this->assertSame( 'generic:a:b', $cache->makeKey( 'a', 'b' ) ); } + public function testConvertGenericKey() { + $cache1 = new class extends HashBagOStuff { + protected function makeKeyInternal( $keyspace, $components ) { + return $keyspace . ':short-one-way'; + } + + protected function convertGenericKey( $key ) { + $components = $this->componentsFromGenericKey( $key ); + $keyspace = array_shift( $components ); + return $this->makeKeyInternal( $keyspace, $components ); + } + }; + $cache2 = new class extends HashBagOStuff { + protected function makeKeyInternal( $keyspace, $components ) { + return $keyspace . ':short-another-way'; + } + + protected function convertGenericKey( $key ) { + $components = $this->componentsFromGenericKey( $key ); + $keyspace = array_shift( $components ); + return $this->makeKeyInternal( $keyspace, $components ); + } + + }; + + $cache = new MultiWriteBagOStuff( [ + 'caches' => [ $cache1, $cache2 ] + ] ); + $key = $cache->makeKey( 'a', 'b' ); + $cache->set( $key, 'my_value' ); + + $this->assertSame( + 'local:a:b', + $key + ); + $this->assertSame( + [ 'local:short-one-way' ], + array_keys( TestingAccessWrapper::newFromObject( $cache1 )->bag ), + 'key gets re-encoded for first backend' + ); + $this->assertSame( + [ 'local:short-another-way' ], + array_keys( TestingAccessWrapper::newFromObject( $cache2 )->bag ), + 'key gets re-encoded for second backend' + ); + } + public function testMakeGlobalKey() { $cache1 = $this->getMockBuilder( HashBagOStuff::class ) ->onlyMethods( [ 'makeGlobalKey' ] )->getMock(); |