| 1 |
<?php |
| 2 |
|
| 3 |
use MediaWiki\WikiMap\WikiMap; |
| 4 |
use Wikimedia\ObjectCache\HashBagOStuff; |
| 5 |
use Wikimedia\ObjectCache\WANObjectCache; |
| 6 |
|
| 7 |
class LocalAndForeignDBRepoTest extends MediaWikiIntegrationTestCase { |
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
public function testsSharedCacheKey() { |
| 13 |
$wikiId = WikiMap::getCurrentWikiDbDomain()->getId(); |
| 14 |
$wanCache = new WANObjectCache( [ 'cache' => new HashBagOStuff() ] ); |
| 15 |
$localRepo = new LocalRepo( [ |
| 16 |
'name' => 'local', |
| 17 |
'backend' => 'local-backend', |
| 18 |
'wanCache' => $wanCache |
| 19 |
] ); |
| 20 |
$foreignRepo = new ForeignDBViaLBRepo( [ |
| 21 |
'name' => 'local', |
| 22 |
'backend' => 'local-backend', |
| 23 |
'wiki' => $wikiId, |
| 24 |
'hasSharedCache' => true, |
| 25 |
'wanCache' => $wanCache |
| 26 |
] ); |
| 27 |
$foreignRepo2 = new ForeignDBViaLBRepo( [ |
| 28 |
'name' => 'local', |
| 29 |
'backend' => 'local-backend', |
| 30 |
'wiki' => 'weirdoutside-domain', |
| 31 |
'hasSharedCache' => true, |
| 32 |
'wanCache' => $wanCache |
| 33 |
] ); |
| 34 |
|
| 35 |
$sharedKeyForLocal = $localRepo->getSharedCacheKey( 'class', 93 ); |
| 36 |
$sharedKeyForForeign = $foreignRepo->getSharedCacheKey( 'class', 93 ); |
| 37 |
$sharedKeyForForiegn2 = $foreignRepo2->getSharedCacheKey( 'class', 93 ); |
| 38 |
|
| 39 |
$this->assertSame( |
| 40 |
$wanCache->makeGlobalKey( 'filerepo-class', $wikiId, 93 ), |
| 41 |
$sharedKeyForLocal, |
| 42 |
"Shared key (repo is on local domain)" |
| 43 |
); |
| 44 |
$this->assertSame( |
| 45 |
$sharedKeyForLocal, |
| 46 |
$sharedKeyForForeign, |
| 47 |
"Shared key (repo is on foreign domain)" |
| 48 |
); |
| 49 |
|
| 50 |
$this->assertSame( |
| 51 |
$wanCache->makeGlobalKey( 'filerepo-class', 'weirdoutside-domain', 93 ), |
| 52 |
$sharedKeyForForiegn2, |
| 53 |
"Shared key (repo is on a different foreign domain)" |
| 54 |
); |
| 55 |
} |
| 56 |
|
| 57 |
|
| 58 |
|
| 59 |
|
| 60 |
|
| 61 |
public function testsLocalCacheKey() { |
| 62 |
$wikiId = WikiMap::getCurrentWikiDbDomain()->getId(); |
| 63 |
$wanCache = new WANObjectCache( [ 'cache' => new HashBagOStuff() ] ); |
| 64 |
$localRepo = new LocalRepo( [ |
| 65 |
'name' => 'local', |
| 66 |
'backend' => 'local-backend', |
| 67 |
'wanCache' => $wanCache |
| 68 |
] ); |
| 69 |
$foreignRepo = new ForeignDBViaLBRepo( [ |
| 70 |
'name' => 'local', |
| 71 |
'backend' => 'local-backend', |
| 72 |
'wiki' => $wikiId, |
| 73 |
'hasSharedCache' => true, |
| 74 |
'wanCache' => $wanCache |
| 75 |
] ); |
| 76 |
|
| 77 |
$nonsharedKeyForLocal = $localRepo->getLocalCacheKey( 'class', 93 ); |
| 78 |
$nonsharedKeyForForeign = $foreignRepo->getLocalCacheKey( 'class', 93 ); |
| 79 |
|
| 80 |
$this->assertSame( |
| 81 |
$wanCache->makeKey( 'filerepo-class', 'local', 93 ), |
| 82 |
$nonsharedKeyForLocal, |
| 83 |
"Non-shared key (repo is on local domain)" |
| 84 |
); |
| 85 |
$this->assertSame( |
| 86 |
$wanCache->makeKey( 'filerepo-class', 'local', 93 ), |
| 87 |
$nonsharedKeyForForeign, |
| 88 |
"Non-shared key (repo is on local domain)" |
| 89 |
); |
| 90 |
} |
| 91 |
} |