public function testGetWriteConnection()
 {
     $connection = $this->getConnectionMock();
     $lb = $this->getLoadBalancerMock();
     $lb->expects($this->once())->method('getConnection')->with(DB_MASTER)->will($this->returnValue($connection));
     $manager = new ConsistentReadConnectionManager($lb);
     $actual = $manager->getWriteConnection();
     $this->assertSame($connection, $actual);
 }
 /**
  * @see UsageTracker::pruneStaleUsages
  *
  * @param int $pageId
  * @param string $lastUpdatedBefore timestamp
  *
  * @return EntityUsage[]
  * @throws Exception
  * @throws UsageTrackerException
  */
 public function pruneStaleUsages($pageId, $lastUpdatedBefore)
 {
     // NOTE: while logically we'd like the below to be atomic, we don't wrap it in a
     // transaction to prevent long lock retention during big updates.
     $db = $this->connectionManager->getWriteConnection();
     try {
         $usageTable = $this->newUsageTable($db);
         $pruned = $usageTable->pruneStaleUsages($pageId, $lastUpdatedBefore);
         $this->connectionManager->releaseConnection($db);
         return $pruned;
     } catch (Exception $ex) {
         $this->connectionManager->releaseConnection($db);
         if ($ex instanceof DBError) {
             throw new UsageTrackerException($ex->getMessage(), $ex->getCode(), $ex);
         } else {
             throw $ex;
         }
     }
 }