57 'queryLogger' =>
MediaWiki\Logger\LoggerFactory::getInstance(
'DBQuery' ),
59 'chronologyCallback' =>
function () use ( &
$called ) {
64 $ld = DatabaseDomain::newFromId( $lb->getLocalDomainID() );
65 $this->assertEquals(
$wgDBname, $ld->getDatabase(),
'local domain DB set' );
66 $this->assertEquals( $this->
dbPrefix(), $ld->getTablePrefix(),
'local domain prefix set' );
71 $this->assertTrue( $dbw->getLBInfo(
'master' ),
'master shows as master' );
72 $this->assertTrue( $dbw->getFlag( $dbw::DBO_TRX ),
"DBO_TRX set on master" );
76 $this->assertTrue(
$dbr->getLBInfo(
'master' ),
'DB_REPLICA also gets the master' );
77 $this->assertTrue(
$dbr->getFlag( $dbw::DBO_TRX ),
"DBO_TRX set on replica" );
79 if ( !$lb->getServerAttributes( $lb->getWriterIndex() )[$dbw::ATTR_DB_LEVEL_LOCKING] ) {
80 $dbwAuto = $lb->getConnection(
DB_MASTER, [],
false, $lb::CONN_TRX_AUTOCOMMIT );
82 $dbwAuto->getFlag( $dbw::DBO_TRX ),
"No DBO_TRX with CONN_TRX_AUTOCOMMIT" );
83 $this->assertTrue( $dbw->getFlag( $dbw::DBO_TRX ),
"DBO_TRX still set on master" );
84 $this->assertNotEquals(
85 $dbw, $dbwAuto,
"CONN_TRX_AUTOCOMMIT uses separate connection" );
87 $dbrAuto = $lb->getConnection(
DB_REPLICA, [],
false, $lb::CONN_TRX_AUTOCOMMIT );
89 $dbrAuto->getFlag( $dbw::DBO_TRX ),
"No DBO_TRX with CONN_TRX_AUTOCOMMIT" );
90 $this->assertTrue(
$dbr->getFlag( $dbw::DBO_TRX ),
"DBO_TRX still set on replica" );
91 $this->assertNotEquals(
92 $dbr, $dbrAuto,
"CONN_TRX_AUTOCOMMIT uses separate connection" );
94 $dbwAuto2 = $lb->getConnection(
DB_MASTER, [],
false, $lb::CONN_TRX_AUTOCOMMIT );
95 $this->assertEquals( $dbwAuto2, $dbwAuto,
"CONN_TRX_AUTOCOMMIT reuses connections" );
130 'servers' => $servers,
132 'queryLogger' =>
MediaWiki\Logger\LoggerFactory::getInstance(
'DBQuery' ),
133 'loadMonitorClass' => LoadMonitorNull::class
137 $this->assertTrue( $dbw->getLBInfo(
'master' ),
'master shows as master' );
140 $dbw->getLBInfo(
'clusterMasterHost' ),
141 'cluster master set' );
142 $this->assertTrue( $dbw->getFlag( $dbw::DBO_TRX ),
"DBO_TRX set on master" );
146 $this->assertTrue(
$dbr->getLBInfo(
'replica' ),
'replica shows as replica' );
149 $dbr->getLBInfo(
'clusterMasterHost' ),
150 'cluster master set' );
151 $this->assertTrue(
$dbr->getFlag( $dbw::DBO_TRX ),
"DBO_TRX set on replica" );
154 if ( !$lb->getServerAttributes( $lb->getWriterIndex() )[$dbw::ATTR_DB_LEVEL_LOCKING] ) {
155 $dbwAuto = $lb->getConnection(
DB_MASTER, [],
false, $lb::CONN_TRX_AUTOCOMMIT );
157 $dbwAuto->getFlag( $dbw::DBO_TRX ),
"No DBO_TRX with CONN_TRX_AUTOCOMMIT" );
158 $this->assertTrue( $dbw->getFlag( $dbw::DBO_TRX ),
"DBO_TRX still set on master" );
159 $this->assertNotEquals(
160 $dbw, $dbwAuto,
"CONN_TRX_AUTOCOMMIT uses separate connection" );
162 $dbrAuto = $lb->getConnection(
DB_REPLICA, [],
false, $lb::CONN_TRX_AUTOCOMMIT );
164 $dbrAuto->getFlag( $dbw::DBO_TRX ),
"No DBO_TRX with CONN_TRX_AUTOCOMMIT" );
165 $this->assertTrue(
$dbr->getFlag( $dbw::DBO_TRX ),
"DBO_TRX still set on replica" );
166 $this->assertNotEquals(
167 $dbr, $dbrAuto,
"CONN_TRX_AUTOCOMMIT uses separate connection" );
169 $dbwAuto2 = $lb->getConnection(
DB_MASTER, [],
false, $lb::CONN_TRX_AUTOCOMMIT );
170 $this->assertEquals( $dbwAuto2, $dbwAuto,
"CONN_TRX_AUTOCOMMIT reuses connections" );
178 $db->
delete(
'some_table', [
'id' => 57634126 ], __METHOD__ );
179 $this->fail(
'Write operation should have failed!' );
182 $constraint =
new PHPUnit_Framework_Constraint_StringContains(
'Write operation' );
184 if ( !$constraint->evaluate( $ex->getMessage(),
'',
true ) ) {
204 $this->assertNotSame(
206 $db->
query(
"CREATE TABLE $table (id INT, time INT)", __METHOD__ ),
209 $this->assertNotSame(
211 $db->
query(
"DELETE FROM $table WHERE id=57634126", __METHOD__ ),
216 $db->
query(
"DROP TABLE $table", __METHOD__,
true );
225 'dbname' =>
'my_unittest_wiki',
226 'tablePrefix' =>
'unittest_',
228 'dbDirectory' =>
"some_directory",
234 'servers' => $servers,
235 'localDomain' =>
new DatabaseDomain(
'my_unittest_wiki',
null,
'unittest_' ),
236 'loadMonitorClass' => LoadMonitorNull::class
239 $this->assertTrue( $lb->getServerAttributes( 0 )[Database::ATTR_DB_LEVEL_LOCKING] );
244 'user' =>
'wikiuser',
245 'password' =>
'none',
246 'dbname' =>
'my_unittest_wiki',
247 'tablePrefix' =>
'unittest_',
253 'user' =>
'wikiuser',
254 'password' =>
'none',
255 'dbname' =>
'my_unittest_wiki',
256 'tablePrefix' =>
'unittest_',
263 'servers' => $servers,
264 'localDomain' =>
new DatabaseDomain(
'my_unittest_wiki',
null,
'unittest_' ),
265 'loadMonitorClass' => LoadMonitorNull::class
268 $this->assertFalse( $lb->getServerAttributes( 1 )[Database::ATTR_DB_LEVEL_LOCKING] );
283 $i = $lb->getWriterIndex();
284 $this->assertEquals(
null, $lb->getAnyOpenConnection( $i ) );
285 $conn1 = $lb->getConnection( $i );
286 $this->assertNotEquals(
null, $conn1 );
287 $this->assertEquals( $conn1, $lb->getAnyOpenConnection( $i ) );
288 $conn2 = $lb->getConnection( $i, [],
false, $lb::CONN_TRX_AUTOCOMMIT );
289 $this->assertNotEquals(
null, $conn2 );
290 if ( $lb->getServerAttributes( $i )[Database::ATTR_DB_LEVEL_LOCKING] ) {
291 $this->assertEquals(
null,
292 $lb->getAnyOpenConnection( $i, $lb::CONN_TRX_AUTOCOMMIT ) );
293 $this->assertEquals( $conn1,
295 $i, [],
false, $lb::CONN_TRX_AUTOCOMMIT ), $lb::CONN_TRX_AUTOCOMMIT );
297 $this->assertEquals( $conn2,
298 $lb->getAnyOpenConnection( $i, $lb::CONN_TRX_AUTOCOMMIT ) );
299 $this->assertEquals( $conn2,
300 $lb->getConnection( $i, [],
false, $lb::CONN_TRX_AUTOCOMMIT ) );
$wgDBuser
Database username.
$wgSQLiteDataDir
To override default SQLite data directory ($docroot/../data)
$wgDBserver
Database host name or IP address.
$wgDBpassword
Database user's password.
Database \Wikimedia\Rdbms\LoadBalancer.
assertWriteForbidden(Database $db)
assertWriteAllowed(Database $db)
testOpenConnection()
LoadBalancer::openConnection() LoadBalancer::getAnyOpenConnection()
Class to handle database/prefix specification for IDatabase domains.
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