38 $mockDB = $this->getMockBuilder(
'DatabaseMysqli' )
39 ->disableOriginalConstructor()
43 'class' => $deprecated,
44 'connection' => $mockDB,
45 # Various other parameters required:
48 'serverTemplate' => [],
51 $this->
hideDeprecated(
'$wgLBFactoryConf must be updated. See RELEASE-NOTES for details' );
54 $this->assertEquals( $expected, $result );
59 # Format: new class, old class
60 [ Wikimedia\Rdbms\LBFactorySimple::class,
'LBFactory_Simple' ],
61 [ Wikimedia\Rdbms\LBFactorySingle::class,
'LBFactory_Single' ],
62 [ Wikimedia\Rdbms\LBFactoryMulti::class,
'LBFactory_Multi' ],
63 [ Wikimedia\Rdbms\LBFactorySimple::class,
'LBFactorySimple' ],
64 [ Wikimedia\Rdbms\LBFactorySingle::class,
'LBFactorySingle' ],
65 [ Wikimedia\Rdbms\LBFactoryMulti::class,
'LBFactoryMulti' ],
86 $lb = $factory->getMainLB();
89 $this->assertTrue( $dbw->getLBInfo(
'master' ),
'master shows as master' );
92 $this->assertTrue(
$dbr->getLBInfo(
'master' ),
'DB_REPLICA also gets the master' );
125 'servers' => $servers,
126 'loadMonitorClass' =>
'LoadMonitorNull'
128 $lb = $factory->getMainLB();
131 $this->assertTrue( $dbw->getLBInfo(
'master' ),
'master shows as master' );
134 $dbw->getLBInfo(
'clusterMasterHost' ),
135 'cluster master set' );
138 $this->assertTrue(
$dbr->getLBInfo(
'replica' ),
'slave shows as slave' );
141 $dbr->getLBInfo(
'clusterMasterHost' ),
142 'cluster master set' );
144 $factory->shutdown();
152 'sectionsByDB' => [],
159 'serverTemplate' => [
171 'loadMonitorClass' =>
'LoadMonitorNull'
173 $lb = $factory->getMainLB();
176 $this->assertTrue( $dbw->getLBInfo(
'master' ),
'master shows as master' );
179 $this->assertTrue(
$dbr->getLBInfo(
'replica' ),
'slave shows as slave' );
181 $factory->shutdown();
189 $now = microtime(
true );
190 $mockDB = $this->getMockBuilder(
'DatabaseMysqli' )
191 ->disableOriginalConstructor()
193 $mockDB->method(
'writesOrCallbacksPending' )->willReturn(
true );
194 $mockDB->method(
'lastDoneWrites' )->willReturn( $now );
195 $mockDB->method(
'getMasterPos' )->willReturn( $mPos );
197 $lb = $this->getMockBuilder(
'LoadBalancer' )
198 ->disableOriginalConstructor()
200 $lb->method(
'getConnection' )->willReturn( $mockDB );
201 $lb->method(
'getServerCount' )->willReturn( 2 );
202 $lb->method(
'parentInfo' )->willReturn( [
'id' =>
"main-DEFAULT" ] );
203 $lb->method(
'getAnyOpenConnection' )->willReturn( $mockDB );
204 $lb->method(
'hasOrMadeRecentMasterChanges' )->will( $this->returnCallback(
205 function () use ( $mockDB ) {
207 $p |= call_user_func( [ $mockDB,
'writesOrCallbacksPending' ] );
208 $p |= call_user_func( [ $mockDB,
'lastDoneWrites' ] );
213 $lb->method(
'getMasterPos' )->willReturn( $mPos );
220 'agent' =>
"Totally-Not-FireFox"
224 $mockDB->expects( $this->exactly( 2 ) )->method(
'writesOrCallbacksPending' );
225 $mockDB->expects( $this->exactly( 2 ) )->method(
'lastDoneWrites' );
230 $cp->shutdownLB( $lb );
238 'agent' =>
"Totally-Not-FireFox"
242 $lb->expects( $this->once() )
243 ->method(
'waitFor' )->with( $this->equalTo( $mPos ) );
248 $cp->shutdownLB( $lb );
256 'sectionsByDB' => [],
262 'serverTemplate' => $serverOverride + [
273 'loadMonitorClass' =>
'LoadMonitorNull',
283 $dbPath =
"$tmpDir/unit_test_db.sqlite";
284 file_put_contents( $dbPath,
'' );
286 $tempFsFile->autocollect();
293 [
'dbFilePath' => $dbPath ]
295 $lb = $factory->getMainLB();
308 $lb->reuseConnection(
$db );
318 "Correct full table name"
324 "Correct full table name"
330 "Correct full table name"
333 $factory->setDomainPrefix(
'my_' );
341 "Correct full table name"
346 "Correct full table name"
349 $factory->closeAll();
358 $dbPath =
"$tmpDir/unit_test_db.sqlite";
359 file_put_contents( $dbPath,
'' );
361 $tempFsFile->autocollect();
366 $dbname =
'unittest-domain';
368 [
'localDomain' => $dbname ],
369 [
'dbname' => $dbname,
'dbFilePath' => $dbPath ]
371 $lb = $factory->getMainLB();
374 $lb->reuseConnection(
$db );
384 "Correct full table name"
390 "Correct full table name"
396 "Correct full table name"
399 $factory->setDomainPrefix(
'my_' );
404 "Correct full table name"
409 "Correct full table name"
415 "Correct full table name"
422 }
catch ( \Wikimedia\Rdbms\DBConnectionError
$e ) {
425 $this->assertInstanceOf(
'\Wikimedia\Rdbms\DBConnectionError',
$e );
428 \MediaWiki\suppressWarnings();
429 $this->assertFalse(
$db->
selectDB(
'garbage-db' ) );
430 \MediaWiki\restoreWarnings();
433 $factory->closeAll();
$wgDBuser
Database username.
$wgSQLiteDataDir
To override default SQLite data directory ($docroot/../data)
$wgDBserver
Database host name or IP address.
$wgDBpassword
Database user's password.
wfWikiID()
Get an ASCII string identifying this wiki This is used as a prefix in memcached keys.
Simple store for keeping values in an associative array for the current process.
quoteTable(Database $db, $table)
testChronologyProtector()
testLBFactorySimpleServer()
newLBFactoryMulti(array $baseOverride=[], array $serverOverride=[])
testLBFactorySimpleServers()
testGetLBFactoryClass( $expected, $deprecated)
getLBFactoryClassProvider
getLBFactoryClassProvider()
static getLBFactoryClass(array $config)
Returns the LBFactory class to use and the load balancer configuration.
This class is used to hold the location and do limited manipulation of files stored temporarily (this...
returning false will NOT prevent logging $e
controlled by $wgMainCacheType controlled by $wgParserCacheType controlled by $wgMessageCacheType If you set CACHE_NONE to one of the three control default value for MediaWiki still create a but requests to it are no ops and we always fall through to the database If the cache daemon can t be it should also disable itself fairly smoothly By $wgMemc is used but when it is $parserMemc or $messageMemc this is mentioned $wgDBname