aboutsummaryrefslogtreecommitdiffstats
path: root/tests/lib/Lock/DBLockingProviderTest.php
blob: 860e8d73cf0831604f7bcf9a7b3d1bfe5d8adf3d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
<?php
/**
 * @author Robin Appelman <icewind@owncloud.com>
 *
 * @copyright Copyright (c) 2015, ownCloud, Inc.
 * @license AGPL-3.0
 *
 * This code is free software: you can redistribute it and/or modify
 * it under the terms of the GNU Affero General Public License, version 3,
 * as published by the Free Software Foundation.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
 * GNU Affero General Public License for more details.
 *
 * You should have received a copy of the GNU Affero General Public License, version 3,
 * along with this program.  If not, see <http://www.gnu.org/licenses/>
 *
 */

namespace Test\Lock;

use OCP\AppFramework\Utility\ITimeFactory;
use OCP\Lock\ILockingProvider;

/**
 * Class DBLockingProvider
 *
 * @group DB
 *
 * @package Test\Lock
 */
class DBLockingProviderTest extends LockingProvider {
	/**
	 * @var \OC\Lock\DBLockingProvider
	 */
	protected $instance;

	/**
	 * @var \OCP\IDBConnection
	 */
	protected $connection;

	/**
	 * @var \OCP\AppFramework\Utility\ITimeFactory
	 */
	protected $timeFactory;

	protected $currentTime;

	protected function setUp(): void {
		$this->currentTime = time();
		$this->timeFactory = $this->createMock(ITimeFactory::class);
		$this->timeFactory->expects($this->any())
			->method('getTime')
			->willReturnCallback(function () {
				return $this->currentTime;
			});
		parent::setUp();
	}

	/**
	 * @return \OCP\Lock\ILockingProvider
	 */
	protected function getInstance() {
		$this->connection = \OC::$server->getDatabaseConnection();
		return new \OC\Lock\DBLockingProvider($this->connection, $this->timeFactory, 3600);
	}

	protected function tearDown(): void {
		$this->connection->executeQuery('DELETE FROM `*PREFIX*file_locks`');
		parent::tearDown();
	}

	public function testCleanEmptyLocks() {
		$this->currentTime = 100;
		$this->instance->acquireLock('foo', ILockingProvider::LOCK_EXCLUSIVE);
		$this->instance->acquireLock('asd', ILockingProvider::LOCK_EXCLUSIVE);

		$this->currentTime = 200;
		$this->instance->acquireLock('bar', ILockingProvider::LOCK_EXCLUSIVE);
		$this->instance->changeLock('asd', ILockingProvider::LOCK_SHARED);

		$this->currentTime = 150 + 3600;

		$this->assertEquals(3, $this->getLockEntryCount());

		$this->instance->cleanExpiredLocks();

		$this->assertEquals(2, $this->getLockEntryCount());
	}

	private function getLockEntryCount() {
		$query = $this->connection->prepare('SELECT count(*) FROM `*PREFIX*file_locks`');
		$query->execute();
		return $query->fetchOne();
	}

	protected function getLockValue($key) {
		$query = $this->connection->getQueryBuilder();
		$query->select('lock')
			->from('file_locks')
			->where($query->expr()->eq('key', $query->createNamedParameter($key)));

		$result = $query->execute();
		$rows = $result->fetchOne();
		$result->closeCursor();

		return $rows;
	}

	public function testDoubleShared() {
		$this->instance->acquireLock('foo', ILockingProvider::LOCK_SHARED);
		$this->instance->acquireLock('foo', ILockingProvider::LOCK_SHARED);

		$this->assertEquals(1, $this->getLockValue('foo'));

		$this->instance->releaseLock('foo', ILockingProvider::LOCK_SHARED);

		$this->assertEquals(1, $this->getLockValue('foo'));

		$this->instance->releaseLock('foo', ILockingProvider::LOCK_SHARED);

		$this->assertEquals(1, $this->getLockValue('foo'));

		$this->instance->releaseAll();

		$this->assertEquals(0, $this->getLockValue('foo'));
	}
}
class="w"> "Oracle erabiltzaile edota pasahitza ez dira egokiak.", "PostgreSQL username and/or password not valid" : "PostgreSQL erabiltzaile edota pasahitza ez dira egokiak.", "Mac OS X is not supported and %s will not work properly on this platform. Use it at your own risk! " : "Mac OS X-ek ez du sostengurik eta %s gaizki ibili daiteke plataforma honetan. Erabiltzekotan, zure ardurapean.", "For the best results, please consider using a GNU/Linux server instead." : "Emaitza hobeak izateko, mesedez gogoan hartu GNU/Linux zerbitzari bat erabiltzea.", "Please remove the open_basedir setting within your php.ini or switch to 64-bit PHP." : "Mesedez kendu open_basedir ezarpena zure php.ini-tik edo aldatu 64-biteko PHPra.", "Set an admin username." : "Ezarri administraziorako erabiltzaile izena.", "Set an admin password." : "Ezarri administraziorako pasahitza.", "Can't create or write into the data directory %s" : "Ezin da %s datu karpeta sortu edo bertan idatzi ", "Sharing backend %s must implement the interface OCP\\Share_Backend" : "%s elkarbanaketa motorra OCP\\Share_Backend interfazea inplementatu behar du ", "Sharing backend %s not found" : "Ez da %s elkarbanaketa motorra aurkitu", "Sharing backend for %s not found" : "Ez da %srako elkarbanaketa motorrik aurkitu", "Open »%s«" : "Ireki »%s«", "You are not allowed to share %s" : "Ez zadue %s elkarbanatzeko baimendua", "Expiration date is in the past" : "Iraungitze-data iraganean dago", "Could not find category \"%s\"" : "Ezin da \"%s\" kategoria aurkitu", "Sunday" : "Igandea", "Monday" : "Astelehena", "Tuesday" : "Asteartea", "Wednesday" : "Asteazkena", "Thursday" : "Osteguna", "Friday" : "Ostirala", "Saturday" : "Larunbata", "Sun." : "Ig.", "Mon." : "Al.", "Tue." : "Ar.", "Wed." : "Az.", "Thu." : "Og.", "Fri." : "Ol.", "Sat." : "Lr.", "Su" : "Ig", "Mo" : "Al", "Tu" : "Ar", "We" : "Az", "Th" : "Og", "Fr" : "Ol", "Sa" : "Lr", "January" : "Urtarrila", "February" : "Otsaila", "March" : "Martxoa", "April" : "Apirila", "May" : "Maiatza", "June" : "Ekaina", "July" : "Uztaila", "August" : "Abuztua", "September" : "Iraila", "October" : "Urria", "November" : "Azaroa", "December" : "Abendua", "Jan." : "Urt.", "Feb." : "Ots.", "Mar." : "Mar.", "Apr." : "Api.", "May." : "Mai.", "Jun." : "Eka.", "Jul." : "Uzt.", "Aug." : "Abu.", "Sep." : "Ira.", "Oct." : "Urr.", "Nov." : "Aza.", "Dec." : "Abe.", "A valid username must be provided" : "Baliozko erabiltzaile izena eman behar da", "A valid password must be provided" : "Baliozko pasahitza eman behar da", "The username is already being used" : "Erabiltzaile izena dagoeneko erabiltzen ari da", "User disabled" : "Erabiltzaile desgaituta", "Login canceled by app" : "Aplikazioa saioa bertan behera utzi du", "Can't read file" : "Ezin da fitxategia irakurri", "Application is not enabled" : "Aplikazioa ez dago gaituta", "Authentication error" : "Autentifikazio errorea", "Token expired. Please reload page." : "Tokena iraungitu da. Mesedez birkargatu orria.", "No database drivers (sqlite, mysql, or postgresql) installed." : "Ez dago datubaseen (sqlite, mysql edo postgresql) driverrik instalatuta.", "Cannot write into \"config\" directory" : "Ezin da idatzi \"config\" karpetan", "Cannot write into \"apps\" directory" : "Ezin da idatzi \"apps\" karpetan", "Setting locale to %s failed" : "Lokala %sra ezartzeak huts egin du", "Please install one of these locales on your system and restart your webserver." : "Instalatu hauetako lokal bat zure sisteman eta berrabiarazi zure web zerbitzaria.", "Please ask your server administrator to install the module." : "Mesedez eskatu zure zerbitzariaren kudeatzaileari modulua instala dezan.", "PHP module %s not installed." : "PHPren %s modulua ez dago instalaturik.", "This is probably caused by a cache/accelerator such as Zend OPcache or eAccelerator." : "Hau ziur aski cache/accelerator batek eragin du, hala nola Zend OPcache edo eAccelerator.", "PHP modules have been installed, but they are still listed as missing?" : "PHP moduluak instalatu dira, baina oraindik faltan bezala markatuta daude?", "Please ask your server administrator to restart the web server." : "Mesedez eskatu zerbitzariaren kudeatzaileari web zerbitzaria berrabiarazteko.", "PostgreSQL >= 9 required" : "PostgreSQL >= 9 behar da", "Please upgrade your database version" : "Mesedez eguneratu zure datu basearen bertsioa", "Please change the permissions to 0770 so that the directory cannot be listed by other users." : "Mesedez aldatu baimenak 0770ra beste erabiltzaileek karpetan sartu ezin izateko.", "Could not obtain lock type %d on \"%s\"." : "Ezin da lortu sarraia mota %d \"%s\"-an.", "Library %s with a version higher than %s is required - available version %s." : "%s liburutegiak %s baino bertsio handiagoa izan behar du - dagoen bertsioa %s.", "Library %s with a version lower than %s is required - available version %s." : "%s liburutegiak %s baino bertsio txikiagoa izan behar du - dagoen bertsioa %s.", "Create" : "Sortu", "Change" : "Aldatu", "Delete" : "Ezabatu", "Share" : "Partekatu", "Unlimited" : "Mugagabea", "Verifying" : "Egiaztatzen", "Verify" : "Egiaztatu", "Sharing %s failed, because the backend does not allow shares from type %i" : "%s partekatzeak huts egin du, motorrak %i motako partekatzeak baimentzen ez dituelako", "Sharing %s failed, because the file does not exist" : "%s elkarbanatzeak huts egin du, fitxategia ez delako existitzen", "Sharing %s failed, because the user %s does not exist" : "%s elkarbanatzeak huts egin du, %s erabiltzailea existitzen ez delako", "Sharing %s failed, because the user %s is not a member of any groups that %s is a member of" : "%s elkarbanatzeak huts egin du, %s erabiltzailea ez delako %s partaide den talderen bateko partaidea", "Sharing %s failed, because this item is already shared with %s" : "%s elkarbanatzeak huts egin du, dagoeneko %s erabiltzailearekin elkarbanatuta dagoelako", "Sharing %s failed, because the group %s does not exist" : "%s elkarbanatzeak huts egin du, %s taldea ez delako existitzen", "Sharing %s failed, because %s is not a member of the group %s" : "%s elkarbanatzeak huts egin du, %s ez delako %s taldearen partaidea", "You need to provide a password to create a public link, only protected links are allowed" : "Lotura publiko bat sortzeko pasahitza idatzi behar duzu, bakarrik babestutako loturak baimenduta daude", "Sharing %s failed, because sharing with links is not allowed" : "%s elkarbanatzeak huts egin du, lotura bidezko elkarbanatzea baimendua ez dagoelako", "Sharing %s failed, could not find %s, maybe the server is currently unreachable." : "%s partekatzeak huts egin du, ezin da %s aurkitu, agian zerbitzaria orain ez dago eskuragarri.", "Share type %s is not valid for %s" : "%s elkarbanaketa mota ez da %srentzako egokia", "Cannot set expiration date. Shares cannot expire later than %s after they have been shared" : "Ezin izan da iraungitze-data ezarri. Partekatzeak ezin dira partekatu eta %s baino beranduago iraungi.", "Cannot set expiration date. Expiration date is in the past" : "Ezin izan da iraungitze data ezarri. Iraungitze data iraganean dago.", "Sharing %s failed, because the permissions exceed permissions granted to %s" : "%s elkarbanatzeak huts egin du, baimenak %sri emandakoak baino gehiago direlako", "Sharing %s failed, because resharing is not allowed" : "%s elkarbanatzeak huts egin du, ber-elkarbanatzea baimenduta ez dagoelako", "Sharing %s failed, because the sharing backend for %s could not find its source" : "%s elkarbanatzeak huts egin du, %sren elkarbanaketa motorrak bere iturria aurkitu ezin duelako", "Sharing %s failed, because the file could not be found in the file cache" : "%s elkarbanatzeak huts egin du, fitxategia katxean aurkitu ez delako", "%s shared »%s« with you" : "%s-ek »%s« zurekin partekatu du", "%s via %s" : "%s %s bidez" }, "nplurals=2; plural=(n != 1);");