Skip to content

Commit 209b2bd

Browse files
committed
Simplify method verbs in LockInterface
1 parent bf8409b commit 209b2bd

File tree

7 files changed

+26
-23
lines changed

7 files changed

+26
-23
lines changed

app/code/Magento/Cron/Observer/ProcessCronQueueObserver.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -229,7 +229,7 @@ public function execute(\Magento\Framework\Event\Observer $observer)
229229

230230
// Note: we acquire the lock here instead of above, as it should be taken by standalone (child) process,
231231
// not by the parent process.
232-
if (!$this->lockManager->acquireLock(self::LOCK_PREFIX . $groupId, self::LOCK_TIMEOUT)) {
232+
if (!$this->lockManager->lock(self::LOCK_PREFIX . $groupId, self::LOCK_TIMEOUT)) {
233233
$this->logger->warning(
234234
sprintf(
235235
"Could not acquire lock for cron group: %s, skipping run",
@@ -279,7 +279,7 @@ public function execute(\Magento\Framework\Event\Observer $observer)
279279
$schedule->save();
280280
}
281281

282-
$this->lockManager->releaseLock(self::LOCK_PREFIX . $groupId);
282+
$this->lockManager->unlock(self::LOCK_PREFIX . $groupId);
283283
}
284284
}
285285

app/code/Magento/Cron/Test/Unit/Observer/ProcessCronQueueObserverTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -143,8 +143,8 @@ protected function setUp()
143143
$this->lockManagerMock = $this->getMockBuilder(\Magento\Framework\Lock\LockManagerInterface::class)
144144
->disableOriginalConstructor()
145145
->getMock();
146-
$this->lockManagerMock->method('acquireLock')->willReturn(true);
147-
$this->lockManagerMock->method('releaseLock')->willReturn(true);
146+
$this->lockManagerMock->method('lock')->willReturn(true);
147+
$this->lockManagerMock->method('unlock')->willReturn(true);
148148

149149
$this->observer = $this->createMock(\Magento\Framework\Event\Observer::class);
150150

dev/tests/integration/testsuite/Magento/Framework/Lock/Backend/DatabaseTest.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -27,24 +27,24 @@ protected function setUp()
2727
$this->model = $this->objectManager->create(\Magento\Framework\Lock\Backend\Database::class);
2828
}
2929

30-
public function testLockAndRelease()
30+
public function testLockAndUnlock()
3131
{
3232
$name = 'test_lock';
3333

3434
$this->assertFalse($this->model->isLocked($name));
3535

36-
$this->assertTrue($this->model->acquireLock($name));
36+
$this->assertTrue($this->model->lock($name));
3737
$this->assertTrue($this->model->isLocked($name));
3838

39-
$this->assertTrue($this->model->releaseLock($name));
39+
$this->assertTrue($this->model->unlock($name));
4040
$this->assertFalse($this->model->isLocked($name));
4141
}
4242

43-
public function testReleaseLockWithoutExistingLock()
43+
public function testUnlockWithoutExistingLock()
4444
{
4545
$name = 'test_lock';
4646

4747
$this->assertFalse($this->model->isLocked($name));
48-
$this->assertFalse($this->model->releaseLock($name));
48+
$this->assertFalse($this->model->unlock($name));
4949
}
5050
}

lib/internal/Magento/Framework/Lock/Backend/Database.php

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ public function __construct(
4747
* @throws InputException
4848
* @throws AlreadyExistsException
4949
*/
50-
public function acquireLock(string $name, int $timeout = -1): bool
50+
public function lock(string $name, int $timeout = -1): bool
5151
{
5252
$name = $this->addPrefix($name);
5353

@@ -58,7 +58,10 @@ public function acquireLock(string $name, int $timeout = -1): bool
5858
*/
5959
if ($this->currentLock) {
6060
throw new AlreadyExistsException(
61-
new Phrase('This connection is already holding lock for $1', [$this->currentLock])
61+
new Phrase(
62+
'Current connection is already holding lock for $1, only single lock allowed',
63+
[$this->currentLock]
64+
)
6265
);
6366
}
6467

@@ -81,7 +84,7 @@ public function acquireLock(string $name, int $timeout = -1): bool
8184
* @return bool
8285
* @throws InputException
8386
*/
84-
public function releaseLock(string $name): bool
87+
public function unlock(string $name): bool
8588
{
8689
$name = $this->addPrefix($name);
8790

lib/internal/Magento/Framework/Lock/LockManagerInterface.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ interface LockManagerInterface
2222
* @return bool
2323
* @api
2424
*/
25-
public function acquireLock(string $name, int $timeout = -1): bool;
25+
public function lock(string $name, int $timeout = -1): bool;
2626

2727
/**
2828
* Releases a lock
@@ -31,7 +31,7 @@ public function acquireLock(string $name, int $timeout = -1): bool;
3131
* @return bool
3232
* @api
3333
*/
34-
public function releaseLock(string $name): bool;
34+
public function unlock(string $name): bool;
3535

3636
/**
3737
* Tests if lock is set

lib/internal/Magento/Framework/Lock/README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,6 @@
33
Lock library provides mechanism to acquire Magento system-wide lock. Default implementation is based on MySQL locks, where any locks are automatically released on connection close.
44

55
The library provides interface *LockManagerInterface* which provides following methods:
6-
* *acquireLock* - Acquires a named lock
7-
* *releaseLock* - Releases a named lock
6+
* *lock* - Acquires a named lock
7+
* *unlock* - Releases a named lock
88
* *isLocked* - Tests if a named lock exists

lib/internal/Magento/Framework/Lock/Test/Unit/Backend/DatabaseTest.php

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -61,33 +61,33 @@ protected function setUp()
6161
);
6262
}
6363

64-
public function testAcquireLock()
64+
public function testLock()
6565
{
6666
$this->statement->expects($this->once())
6767
->method('fetchColumn')
6868
->willReturn(true);
6969

70-
$this->assertTrue($this->database->acquireLock('testLock'));
70+
$this->assertTrue($this->database->lock('testLock'));
7171
}
7272

7373
/**
7474
* @expectedException \Magento\Framework\Exception\InputException
7575
*/
76-
public function testAcquireLockWithTooLongName()
76+
public function testlockWithTooLongName()
7777
{
78-
$this->database->acquireLock('BbXbyf9rIY5xuAVdviQJmh76FyoeeVHTDpcjmcImNtgpO4Hnz4xk76ZGEyYALvrQu');
78+
$this->database->lock('BbXbyf9rIY5xuAVdviQJmh76FyoeeVHTDpcjmcImNtgpO4Hnz4xk76ZGEyYALvrQu');
7979
}
8080

8181
/**
8282
* @expectedException \Magento\Framework\Exception\AlreadyExistsException
8383
*/
84-
public function testAcquireLockWithAlreadyAcquiredLockInSameSession()
84+
public function testlockWithAlreadyAcquiredLockInSameSession()
8585
{
8686
$this->statement->expects($this->any())
8787
->method('fetchColumn')
8888
->willReturn(true);
8989

90-
$this->database->acquireLock('testLock');
91-
$this->database->acquireLock('differentLock');
90+
$this->database->lock('testLock');
91+
$this->database->lock('differentLock');
9292
}
9393
}

0 commit comments

Comments
 (0)