Debian Codegraph @

tests/phpunit/unit/includes/objectcache/SqlBagOStuffTest.php

raw symbols SCIP
1 <?php
2
3 /**
4 * @covers \SqlBagOStuff
5 * @group BagOStuff
6 */
7 class SqlBagOStuffTest extends MediaWikiUnitTestCase {
8 public static function provideMakeKey() {
9 yield [ 'local', 'first', [ 'second', 'third' ],
10 'local:first:second:third' ];
11 yield [ 'local with spaces', 'first:first', [ 'second:second' ],
12 'local_with_spaces:first%3Afirst:second%3Asecond' ];
13 $longA = str_repeat( 'a', 128 );
14 $longB = str_repeat( 'b', 128 );
15 $longC = str_repeat( 'c', 128 );
16 yield [ 'global fairly long', 'first', [ $longA, $longB ],
17 'global_fairly_long:first:' . $longA . ':#73045f89f89b1604b62a6ae1ab4d4133' ];
18 yield [ 'global really long', 'first', [ $longA, $longB, $longC ],
19 'global_really_long:BagOStuff-long-key:##99f6adc828cfb6c892501f20153bd028' ];
20 }
21
22 /**
23 * @param string $keyspace
24 * @param string $class
25 * @param array $components
26 * @param string $expected
27 * @dataProvider SqlBagOStuffTest::provideMakeKey
28 */
29 public function testMakeKey(
30 string $keyspace,
31 string $class,
32 array $components,
33 string $expected
34 ) {
35 $cache = new SqlBagOStuff( [
36 'keyspace' => $keyspace,
37 'servers' => []
38 ] );
39 $this->assertSame( $expected, $cache->makeKey( $class, ...$components ) );
40 }
41
42 public function testSisterKeys() {
43 $cache = new SqlBagOStuff( [
44 'keyspace' => 'test',
45 'servers' => [ 'pc1' => [], 'pc2' => [], 'pc3' => [], 'pc4' => [], 'pc5' => [], 'pc6' => [] ],
46 'shards' => 30
47 ] );
48 $cacheObj = \Wikimedia\TestingAccessWrapper::newFromObject( $cache );
49
50 [ $indexFirstKey, $tableNameFirstKey ] = $cacheObj->getKeyLocation( 'Test123' );
51 [ $indexSecondKey, $tableNameSecondKey ] = $cacheObj->getKeyLocation( 'Test133' );
52 $this->assertNotEquals( $indexFirstKey, $indexSecondKey );
53 $this->assertNotEquals( $tableNameFirstKey, $tableNameSecondKey );
54
55 [ $indexFirstKey, $tableNameFirstKey ] = $cacheObj->getKeyLocation( 'Test123|#|12345' );
56 [ $indexSecondKey, $tableNameSecondKey ] = $cacheObj->getKeyLocation( 'Test123|#|54321' );
57 $this->assertSame( $indexFirstKey, $indexSecondKey );
58 $this->assertSame( $tableNameFirstKey, $tableNameSecondKey );
59
60 [ $indexFirstKey, $tableNameFirstKey ] = $cacheObj->getKeyLocation(
61 $cache->makeKey( 'Test123', '|#|', '12345' )
62 );
63 [ $indexSecondKey, $tableNameSecondKey ] = $cacheObj->getKeyLocation(
64 $cache->makeKey( 'Test123', '|#|', '54321' )
65 );
66 $this->assertSame( $indexFirstKey, $indexSecondKey );
67 $this->assertSame( $tableNameFirstKey, $tableNameSecondKey );
68 }
69 }