Merge "Update wikimedia/normalized-exception to 2.1.1"
[mediawiki.git] / tests / phpunit / includes / objectcache / SqlBagOStuffIntegrationTest.php
blob4472a11ed120b0a85776ba5ac8d0c0cdc96bcf6d
1 <?php
3 /**
4 * @group BagOStuff
5 * @group Database
6 * @covers \SqlBagOStuff
7 */
8 class SqlBagOStuffIntegrationTest extends BagOStuffTestBase {
9 protected function newCacheInstance() {
10 return $this->getServiceContainer()->getObjectCacheFactory()->getInstance( CACHE_DB );
13 public function testFallback() {
14 if ( $this->getDb()->getType() !== 'mysql' ) {
15 $this->markTestSkipped( "Does not work with sqlite and postgres" );
17 global $wgDBserver, $wgDBport, $wgDBname, $wgDBuser, $wgDBpassword, $wgDBtype;
18 $cache = new SqlBagOStuff( [
19 'keyspace' => 'test',
20 'servers' => [ 'pc1' => [
21 'serverName' => 'db0',
22 'host' => $wgDBserver,
23 'port' => $wgDBport,
24 'dbname' => $wgDBname,
25 'user' => $wgDBuser,
26 'password' => $wgDBpassword,
27 'type' => $wgDBtype,
28 ], 'pc2' => [
29 'serverName' => 'db1',
30 'host' => $wgDBserver . 'nocoonection',
31 'port' => $wgDBport,
32 'dbname' => $wgDBname . 'nocoonection',
33 'user' => $wgDBuser . 'nocoonection',
34 'password' => $wgDBpassword . 'nocoonection',
35 'type' => $wgDBtype,
36 ] ],
37 'shards' => 1
38 ] );
40 // around half of these must fallback. Test shows keyname3 does.
41 for ( $i = 0; $i < 10; $i++ ) {
42 $cache->set( 'keyname' . (string)$i, 'value' . (string)$i );
43 $res = $cache->get( 'keyname' . (string)$i );
45 $this->assertSame( 'value' . (string)$i, $res );
48 // Testing getMulti
49 $keys = [];
50 for ( $i = 0; $i < 10; $i++ ) {
51 $cache->set( 'keyname' . (string)$i, 'value' . (string)$i );
52 $keys[] = 'keyname' . (string)$i;
54 $res = $cache->getMulti( $keys );
55 for ( $i = 0; $i < 10; $i++ ) {
56 $this->assertSame( 'value' . (string)$i, $res['keyname' . (string)$i] );