67 # Format: new class, old class
68 [ Wikimedia\Rdbms\LBFactorySimple::class,
'LBFactory_Simple' ],
69 [ Wikimedia\Rdbms\LBFactorySingle::class,
'LBFactory_Single' ],
70 [ Wikimedia\Rdbms\LBFactoryMulti::class,
'LBFactory_Multi' ],
71 [ Wikimedia\Rdbms\LBFactorySimple::class,
'LBFactorySimple' ],
72 [ Wikimedia\Rdbms\LBFactorySingle::class,
'LBFactorySingle' ],
73 [ Wikimedia\Rdbms\LBFactoryMulti::class,
'LBFactoryMulti' ],
197 $now = microtime(
true );
200 $m1Pos =
new MySQLMasterPos(
'db1034-bin.000976/843431247', $now );
201 $m2Pos =
new MySQLMasterPos(
'db1064-bin.002400/794074907', $now );
204 $mockDB1 = $this->getMockBuilder( DatabaseMysqli::class )
205 ->disableOriginalConstructor()
207 $mockDB1->method(
'writesOrCallbacksPending' )->willReturn(
true );
208 $mockDB1->method(
'lastDoneWrites' )->willReturn( $now );
209 $mockDB1->method(
'getMasterPos' )->willReturn( $m1Pos );
211 $lb1 = $this->getMockBuilder( LoadBalancer::class )
212 ->disableOriginalConstructor()
214 $lb1->method(
'getConnection' )->willReturn( $mockDB1 );
215 $lb1->method(
'getServerCount' )->willReturn( 2 );
216 $lb1->method(
'getAnyOpenConnection' )->willReturn( $mockDB1 );
217 $lb1->method(
'hasOrMadeRecentMasterChanges' )->will( $this->returnCallback(
218 function () use ( $mockDB1 ) {
220 $p |= call_user_func( [ $mockDB1,
'writesOrCallbacksPending' ] );
221 $p |= call_user_func( [ $mockDB1,
'lastDoneWrites' ] );
226 $lb1->method(
'getMasterPos' )->willReturn( $m1Pos );
227 $lb1->method(
'getServerName' )->with( 0 )->willReturn(
'master1' );
229 $mockDB2 = $this->getMockBuilder( DatabaseMysqli::class )
230 ->disableOriginalConstructor()
232 $mockDB2->method(
'writesOrCallbacksPending' )->willReturn(
true );
233 $mockDB2->method(
'lastDoneWrites' )->willReturn( $now );
234 $mockDB2->method(
'getMasterPos' )->willReturn( $m2Pos );
236 $lb2 = $this->getMockBuilder( LoadBalancer::class )
237 ->disableOriginalConstructor()
239 $lb2->method(
'getConnection' )->willReturn( $mockDB2 );
240 $lb2->method(
'getServerCount' )->willReturn( 2 );
241 $lb2->method(
'getAnyOpenConnection' )->willReturn( $mockDB2 );
242 $lb2->method(
'hasOrMadeRecentMasterChanges' )->will( $this->returnCallback(
243 function () use ( $mockDB2 ) {
245 $p |= call_user_func( [ $mockDB2,
'writesOrCallbacksPending' ] );
246 $p |= call_user_func( [ $mockDB2,
'lastDoneWrites' ] );
251 $lb2->method(
'getMasterPos' )->willReturn( $m2Pos );
252 $lb2->method(
'getServerName' )->with( 0 )->willReturn(
'master2' );
259 'agent' =>
"Totally-Not-FireFox"
263 $mockDB1->expects( $this->exactly( 1 ) )->method(
'writesOrCallbacksPending' );
264 $mockDB1->expects( $this->exactly( 1 ) )->method(
'lastDoneWrites' );
265 $mockDB2->expects( $this->exactly( 1 ) )->method(
'writesOrCallbacksPending' );
266 $mockDB2->expects( $this->exactly( 1 ) )->method(
'lastDoneWrites' );
272 $cp->shutdownLB( $lb1 );
273 $cp->shutdownLB( $lb2 );
275 $cp->shutdown(
null,
'sync', $cpIndex );
277 $this->assertEquals( 1, $cpIndex,
"CP write index set" );
282 $lb1 = $this->getMockBuilder( LoadBalancer::class )
283 ->disableOriginalConstructor()
285 $lb1->method(
'getServerCount' )->willReturn( 2 );
286 $lb1->method(
'getServerName' )->with( 0 )->willReturn(
'master1' );
287 $lb1->expects( $this->once() )
288 ->method(
'waitFor' )->with( $this->equalTo( $m1Pos ) );
290 $lb2 = $this->getMockBuilder( LoadBalancer::class )
291 ->disableOriginalConstructor()
293 $lb2->method(
'getServerCount' )->willReturn( 2 );
294 $lb2->method(
'getServerName' )->with( 0 )->willReturn(
'master2' );
295 $lb2->expects( $this->once() )
296 ->method(
'waitFor' )->with( $this->equalTo( $m2Pos ) );
302 'agent' =>
"Totally-Not-FireFox"
311 $cp->shutdownLB( $lb1 );
312 $cp->shutdownLB( $lb2 );
314 $cp->shutdown(
null,
'sync', $cpIndex );
316 $this->assertEquals(
null, $cpIndex,
"CP write index retained" );