File: SqlBagOStuffTest.php

package info (click to toggle)
mediawiki 1%3A1.43.3%2Bdfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 417,464 kB
  • sloc: php: 1,062,949; javascript: 664,290; sql: 9,714; python: 5,458; xml: 3,489; sh: 1,131; makefile: 64
file content (69 lines) | stat: -rw-r--r-- 2,481 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
<?php

/**
 * @covers \SqlBagOStuff
 * @group BagOStuff
 */
class SqlBagOStuffTest extends MediaWikiUnitTestCase {
	public static function provideMakeKey() {
		yield [ 'local', 'first', [ 'second', 'third' ],
			'local:first:second:third' ];
		yield [ 'local with spaces', 'first:first', [ 'second:second' ],
			'local_with_spaces:first%3Afirst:second%3Asecond' ];
		$longA = str_repeat( 'a', 128 );
		$longB = str_repeat( 'b', 128 );
		$longC = str_repeat( 'c', 128 );
		yield [ 'global fairly long', 'first', [ $longA, $longB ],
			'global_fairly_long:first:' . $longA . ':#73045f89f89b1604b62a6ae1ab4d4133' ];
		yield [ 'global really long', 'first', [ $longA, $longB, $longC ],
			'global_really_long:BagOStuff-long-key:##99f6adc828cfb6c892501f20153bd028' ];
	}

	/**
	 * @param string $keyspace
	 * @param string $class
	 * @param array $components
	 * @param string $expected
	 * @dataProvider SqlBagOStuffTest::provideMakeKey
	 */
	public function testMakeKey(
		string $keyspace,
		string $class,
		array $components,
		string $expected
	) {
		$cache = new SqlBagOStuff( [
			'keyspace' => $keyspace,
			'servers' => []
		] );
		$this->assertSame( $expected, $cache->makeKey( $class, ...$components ) );
	}

	public function testSisterKeys() {
		$cache = new SqlBagOStuff( [
			'keyspace' => 'test',
			'servers' => [ 'pc1' => [], 'pc2' => [], 'pc3' => [], 'pc4' => [], 'pc5' => [], 'pc6' => [] ],
			'shards' => 30
		] );
		$cacheObj = \Wikimedia\TestingAccessWrapper::newFromObject( $cache );

		[ $indexFirstKey, $tableNameFirstKey ] = $cacheObj->getKeyLocation( 'Test123' );
		[ $indexSecondKey, $tableNameSecondKey ] = $cacheObj->getKeyLocation( 'Test133' );
		$this->assertNotEquals( $indexFirstKey, $indexSecondKey );
		$this->assertNotEquals( $tableNameFirstKey, $tableNameSecondKey );

		[ $indexFirstKey, $tableNameFirstKey ] = $cacheObj->getKeyLocation( 'Test123|#|12345' );
		[ $indexSecondKey, $tableNameSecondKey ] = $cacheObj->getKeyLocation( 'Test123|#|54321' );
		$this->assertSame( $indexFirstKey, $indexSecondKey );
		$this->assertSame( $tableNameFirstKey, $tableNameSecondKey );

		[ $indexFirstKey, $tableNameFirstKey ] = $cacheObj->getKeyLocation(
			$cache->makeKey( 'Test123', '|#|', '12345' )
		);
		[ $indexSecondKey, $tableNameSecondKey ] = $cacheObj->getKeyLocation(
			$cache->makeKey( 'Test123', '|#|', '54321' )
		);
		$this->assertSame( $indexFirstKey, $indexSecondKey );
		$this->assertSame( $tableNameFirstKey, $tableNameSecondKey );
	}
}