blob: 2a97e1b1218bfde2a3d819dbf8c74c69420e3fa7 (
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
|
<?php
namespace OCA\OJSXC;
use OCP\AppFramework\Db\DoesNotExistException;
use Test\TestCase;
use OCA\OJSXC\AppInfo\Application;
use OCA\OJSXC\MemLock;
//function time() {
// return DbLockTest::$time;
//}
/**
* @group DB
*/
class MemLockTest extends TestCase {
/**
* @var \OCA\OJSXC\MemLock
*/
private $memLock;
/**
* @var \OCA\OJSXC\MemLock
*/
private $memLock2;
/**
* @var \OCP\AppFramework\IAppContainer
*/
private $container;
/**
* @var \OCP\ICache
*/
private $memCache;
public static $time;
public function setUp() {
parent::setUp();
$app = new Application();
$this->container = $app->getContainer();
}
/**
* Tests the setLock and stillLocked function by setting up and lock
* and then setting a new lock.
*/
public function testLock() {
global $time;
$time = 4;
$cache = $this->container->getServer()->getMemCacheFactory();
if ($cache->isAvailable()) {
$this->memCache = $cache->create('ojsxc');
} else {
die('No memcache available'); // TODO
}
$this->memLock = new MemLock(
'john',
$this->memCache
);
$this->memLock->setLock();
$this->assertTrue($this->memLock->stillLocked());
$result = $this->fetchLock();
$this->assertEquals('4', $result);
global $time;
$time = 5;
$this->memLock2 = new MemLock(
'john',
$this->memCache
); // simulate new lock/request
$this->memLock2->setLock();
$this->assertFalse($this->memLock->stillLocked());
$this->assertTrue($this->memLock2->stillLocked());
$result = $this->fetchLock();
$this->assertEquals('5', $result);
}
private function fetchLock() {
return $this->memCache->get('-john-ojxsc-lock');
}
}
|