ltsecurityinc安防产品在线商城代码
This commit is contained in:
@@ -0,0 +1,115 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Magento\Framework\Lock\Backend;
|
||||
|
||||
use Magento\Framework\Lock\Backend\Cache;
|
||||
|
||||
/**
|
||||
* \Magento\Framework\Lock\Backend\Cache test case.
|
||||
*/
|
||||
class CacheTest extends \PHPUnit\Framework\TestCase
|
||||
{
|
||||
/**
|
||||
* @var Cache
|
||||
*/
|
||||
private $cacheInstance1;
|
||||
|
||||
/**
|
||||
* @var Cache
|
||||
*/
|
||||
private $cacheInstance2;
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
protected function setUp(): void
|
||||
{
|
||||
$objectManager = \Magento\TestFramework\Helper\Bootstrap::getObjectManager();
|
||||
|
||||
$frontendInterface1 = $objectManager->create(\Magento\Framework\App\Cache\Type\Config::class);
|
||||
$this->cacheInstance1 = new Cache($frontendInterface1);
|
||||
|
||||
$frontendInterface2 = $objectManager->create(\Magento\Framework\App\Cache\Type\Config::class);
|
||||
$this->cacheInstance2 = new Cache($frontendInterface2);
|
||||
}
|
||||
|
||||
/**
|
||||
* Verify lock mechanism in general.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testParallelLock(): void
|
||||
{
|
||||
$identifier1 = \uniqid('lock_name_1_', true);
|
||||
|
||||
$this->assertTrue($this->cacheInstance1->lock($identifier1));
|
||||
|
||||
$this->assertFalse($this->cacheInstance1->lock($identifier1, 0));
|
||||
$this->assertFalse($this->cacheInstance2->lock($identifier1, 0));
|
||||
}
|
||||
|
||||
/**
|
||||
* Verify that lock will be released after timeout expiration.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testParallelLockExpired(): void
|
||||
{
|
||||
$testLifeTime = 2;
|
||||
\Closure::bind(function (Cache $class) use ($testLifeTime) {
|
||||
$class->defaultLifetime = $testLifeTime;
|
||||
}, null, $this->cacheInstance1)($this->cacheInstance1);
|
||||
|
||||
$identifier1 = \uniqid('lock_name_1_', true);
|
||||
|
||||
$this->assertTrue($this->cacheInstance1->lock($identifier1, 0));
|
||||
$this->assertTrue($this->cacheInstance2->lock($identifier1, $testLifeTime + 1));
|
||||
|
||||
$this->cacheInstance2->unlock($identifier1);
|
||||
}
|
||||
|
||||
/**
|
||||
* Verify that lock will not be released by another lock name.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testParallelUnlock(): void
|
||||
{
|
||||
$identifier1 = \uniqid('lock_name_1_', true);
|
||||
$identifier2 = \uniqid('lock_name_2_', true);
|
||||
|
||||
$this->assertTrue($this->cacheInstance1->lock($identifier1, 30));
|
||||
$this->assertTrue($this->cacheInstance2->lock($identifier2, 30));
|
||||
|
||||
$this->assertFalse($this->cacheInstance2->unlock($identifier1));
|
||||
$this->assertTrue($this->cacheInstance2->unlock($identifier2));
|
||||
|
||||
$this->assertTrue($this->cacheInstance2->isLocked($identifier1));
|
||||
$this->assertFalse($this->cacheInstance2->isLocked($identifier2));
|
||||
}
|
||||
|
||||
/**
|
||||
* Verify that lock will not be released by another lock name when both locks will never be expired.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testParallelUnlockNoExpiration(): void
|
||||
{
|
||||
$identifier1 = \uniqid('lock_name_1_', true);
|
||||
$identifier2 = \uniqid('lock_name_2_', true);
|
||||
|
||||
$this->assertTrue($this->cacheInstance1->lock($identifier1, -1));
|
||||
$this->assertTrue($this->cacheInstance2->lock($identifier2, -1));
|
||||
|
||||
$this->assertFalse($this->cacheInstance2->unlock($identifier1));
|
||||
$this->assertTrue($this->cacheInstance2->unlock($identifier2));
|
||||
|
||||
$this->assertTrue($this->cacheInstance2->isLocked($identifier1));
|
||||
$this->assertFalse($this->cacheInstance2->isLocked($identifier2));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,57 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Magento\Framework\Lock\Backend;
|
||||
|
||||
use Magento\Framework\App\ResourceConnection;
|
||||
use Magento\Framework\App\DeploymentConfig;
|
||||
|
||||
/**
|
||||
* \Magento\Framework\Lock\Backend\Database test case.
|
||||
*/
|
||||
class DatabaseTest extends \PHPUnit\Framework\TestCase
|
||||
{
|
||||
/**
|
||||
* @var \Magento\Framework\Lock\Backend\Database
|
||||
*/
|
||||
private $model;
|
||||
|
||||
/**
|
||||
* @var \Magento\Framework\ObjectManagerInterface
|
||||
*/
|
||||
private $objectManager;
|
||||
|
||||
protected function setUp(): void
|
||||
{
|
||||
$this->objectManager = \Magento\TestFramework\Helper\Bootstrap::getObjectManager();
|
||||
$resourceConnection = $this->objectManager->create(ResourceConnection::class);
|
||||
$deploymentConfig = $this->objectManager->create(DeploymentConfig::class);
|
||||
// create object with new otherwise dummy locker is created because of di.xml preference for integration tests
|
||||
$this->model = new Database($resourceConnection, $deploymentConfig);
|
||||
}
|
||||
|
||||
public function testLockAndUnlock()
|
||||
{
|
||||
$name = 'test_lock';
|
||||
|
||||
$this->assertFalse($this->model->isLocked($name));
|
||||
|
||||
$this->assertTrue($this->model->lock($name));
|
||||
$this->assertTrue($this->model->isLocked($name));
|
||||
|
||||
$this->assertTrue($this->model->unlock($name));
|
||||
$this->assertFalse($this->model->isLocked($name));
|
||||
}
|
||||
|
||||
public function testUnlockWithoutExistingLock()
|
||||
{
|
||||
$name = 'test_lock';
|
||||
|
||||
$this->assertFalse($this->model->isLocked($name));
|
||||
$this->assertFalse($this->model->unlock($name));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,55 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Magento\Framework\Lock\Backend;
|
||||
|
||||
/**
|
||||
* \Magento\Framework\Lock\Backend\File test case
|
||||
*/
|
||||
class FileLockTest extends \PHPUnit\Framework\TestCase
|
||||
{
|
||||
/**
|
||||
* @var \Magento\Framework\Lock\Backend\FileLock
|
||||
*/
|
||||
private $model;
|
||||
|
||||
/**
|
||||
* @var \Magento\Framework\ObjectManagerInterface
|
||||
*/
|
||||
private $objectManager;
|
||||
|
||||
protected function setUp(): void
|
||||
{
|
||||
$this->objectManager = \Magento\TestFramework\Helper\Bootstrap::getObjectManager();
|
||||
$this->model = $this->objectManager->create(
|
||||
\Magento\Framework\Lock\Backend\FileLock::class,
|
||||
['path' => '/tmp']
|
||||
);
|
||||
}
|
||||
|
||||
public function testLockAndUnlock()
|
||||
{
|
||||
$name = 'test_lock';
|
||||
|
||||
$this->assertFalse($this->model->isLocked($name));
|
||||
|
||||
$this->assertTrue($this->model->lock($name));
|
||||
$this->assertTrue($this->model->isLocked($name));
|
||||
$this->assertFalse($this->model->lock($name, 2));
|
||||
|
||||
$this->assertTrue($this->model->unlock($name));
|
||||
$this->assertFalse($this->model->isLocked($name));
|
||||
}
|
||||
|
||||
public function testUnlockWithoutExistingLock()
|
||||
{
|
||||
$name = 'test_lock';
|
||||
|
||||
$this->assertFalse($this->model->isLocked($name));
|
||||
$this->assertFalse($this->model->unlock($name));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,90 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Magento\Framework\Lock\Backend;
|
||||
|
||||
use Magento\Framework\Lock\Backend\Zookeeper as ZookeeperLock;
|
||||
use Magento\Framework\Lock\LockBackendFactory;
|
||||
use Magento\Framework\Config\File\ConfigFilePool;
|
||||
use Magento\Framework\App\DeploymentConfig\FileReader;
|
||||
use Magento\Framework\Stdlib\ArrayManager;
|
||||
|
||||
/**
|
||||
* \Magento\Framework\Lock\Backend\Zookeeper test case
|
||||
*/
|
||||
class ZookeeperTest extends \PHPUnit\Framework\TestCase
|
||||
{
|
||||
/**
|
||||
* @var FileReader
|
||||
*/
|
||||
private $configReader;
|
||||
|
||||
/**
|
||||
* @var \Magento\Framework\ObjectManagerInterface
|
||||
*/
|
||||
private $objectManager;
|
||||
|
||||
/**
|
||||
* @var LockBackendFactory
|
||||
*/
|
||||
private $lockBackendFactory;
|
||||
|
||||
/**
|
||||
* @var ArrayManager
|
||||
*/
|
||||
private $arrayManager;
|
||||
|
||||
/**
|
||||
* @var ZookeeperLock
|
||||
*/
|
||||
private $model;
|
||||
|
||||
/**
|
||||
* @inheritdoc
|
||||
*/
|
||||
protected function setUp(): void
|
||||
{
|
||||
if (!extension_loaded('zookeeper')) {
|
||||
$this->markTestSkipped('php extension Zookeeper is not installed.');
|
||||
}
|
||||
|
||||
$this->objectManager = \Magento\TestFramework\Helper\Bootstrap::getObjectManager();
|
||||
$this->configReader = $this->objectManager->get(FileReader::class);
|
||||
$this->lockBackendFactory = $this->objectManager->create(LockBackendFactory::class);
|
||||
$this->arrayManager = $this->objectManager->create(ArrayManager::class);
|
||||
$config = $this->configReader->load(ConfigFilePool::APP_ENV);
|
||||
|
||||
if ($this->arrayManager->get('lock/provider', $config) !== 'zookeeper') {
|
||||
$this->markTestSkipped('Zookeeper is not configured during installation.');
|
||||
}
|
||||
|
||||
$this->model = $this->lockBackendFactory->create();
|
||||
$this->assertInstanceOf(ZookeeperLock::class, $this->model);
|
||||
}
|
||||
|
||||
public function testLockAndUnlock()
|
||||
{
|
||||
$name = 'test_lock';
|
||||
|
||||
$this->assertFalse($this->model->isLocked($name));
|
||||
|
||||
$this->assertTrue($this->model->lock($name));
|
||||
$this->assertTrue($this->model->isLocked($name));
|
||||
$this->assertFalse($this->model->lock($name, 2));
|
||||
|
||||
$this->assertTrue($this->model->unlock($name));
|
||||
$this->assertFalse($this->model->isLocked($name));
|
||||
}
|
||||
|
||||
public function testUnlockWithoutExistingLock()
|
||||
{
|
||||
$name = 'test_lock';
|
||||
|
||||
$this->assertFalse($this->model->isLocked($name));
|
||||
$this->assertFalse($this->model->unlock($name));
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user