public function testCounters() { $obj = new HarbormasterObject(); $conn_w = $obj->establishConnection('w'); // Test that the counter bascially behaves as expected. $this->assertEqual(1, LiskDAO::loadNextCounterValue($conn_w, 'a')); $this->assertEqual(2, LiskDAO::loadNextCounterValue($conn_w, 'a')); $this->assertEqual(3, LiskDAO::loadNextCounterValue($conn_w, 'a')); // This first insert is primarily a test that the previous LAST_INSERT_ID() // value does not bleed into the creation of a new counter. $this->assertEqual(1, LiskDAO::loadNextCounterValue($conn_w, 'b')); $this->assertEqual(2, LiskDAO::loadNextCounterValue($conn_w, 'b')); // Test alternate access/overwrite methods. $this->assertEqual(3, LiskDAO::loadCurrentCounterValue($conn_w, 'a')); LiskDAO::overwriteCounterValue($conn_w, 'a', 42); $this->assertEqual(42, LiskDAO::loadCurrentCounterValue($conn_w, 'a')); $this->assertEqual(43, LiskDAO::loadNextCounterValue($conn_w, 'a')); // These inserts alternate database connections. Since unit tests are // transactional by default, we need to break out of them or we'll deadlock // since the transactions don't normally close until we exit the test. LiskDAO::endIsolateAllLiskEffectsToTransactions(); try { $conn_1 = $obj->establishConnection('w', $force_new = true); $conn_2 = $obj->establishConnection('w', $force_new = true); $this->assertEqual(1, LiskDAO::loadNextCounterValue($conn_1, 'z')); $this->assertEqual(2, LiskDAO::loadNextCounterValue($conn_2, 'z')); $this->assertEqual(3, LiskDAO::loadNextCounterValue($conn_1, 'z')); $this->assertEqual(4, LiskDAO::loadNextCounterValue($conn_2, 'z')); $this->assertEqual(5, LiskDAO::loadNextCounterValue($conn_1, 'z')); LiskDAO::beginIsolateAllLiskEffectsToTransactions(); } catch (Exception $ex) { LiskDAO::beginIsolateAllLiskEffectsToTransactions(); throw $ex; } }
private function updateCursor($value) { LiskDAO::overwriteCounterValue(id(new PhabricatorWorkerTrigger())->establishConnection('w'), self::COUNTER_CURSOR, $value); }