summaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorVincent Petry <pvince81@owncloud.com>2014-06-04 13:03:14 +0200
committerVincent Petry <pvince81@owncloud.com>2014-06-04 13:03:14 +0200
commitb5f0a179187bb3f10a939518c6eba72593c1f7a5 (patch)
treeb417ca982d89b125df05c4fd2cb5bcf692bbb291 /tests
parent5adb8f0a8a94b955fd031f8d8226e0cbffbfabb1 (diff)
parent3bcdad62fb18d08d18f6460e32ddd95021a958c9 (diff)
downloadnextcloud-server-b5f0a179187bb3f10a939518c6eba72593c1f7a5.tar.gz
nextcloud-server-b5f0a179187bb3f10a939518c6eba72593c1f7a5.zip
Merge pull request #8822 from owncloud/cache-change-propagator
[WIP] Improved propagation of cache changes
Diffstat (limited to 'tests')
-rw-r--r--tests/lib/files/cache/changepropagator.php72
-rw-r--r--tests/lib/files/cache/scanner.php8
-rw-r--r--tests/lib/files/utils/scanner.php64
-rw-r--r--tests/lib/files/view.php30
4 files changed, 153 insertions, 21 deletions
diff --git a/tests/lib/files/cache/changepropagator.php b/tests/lib/files/cache/changepropagator.php
new file mode 100644
index 00000000000..9beff27d50e
--- /dev/null
+++ b/tests/lib/files/cache/changepropagator.php
@@ -0,0 +1,72 @@
+<?php
+/**
+ * Copyright (c) 2014 Robin Appelman <icewind@owncloud.com>
+ * This file is licensed under the Affero General Public License version 3 or
+ * later.
+ * See the COPYING-README file.
+ */
+
+namespace Test\Files\Cache;
+
+use OC\Files\Filesystem;
+use OC\Files\Storage\Temporary;
+use OC\Files\View;
+
+class ChangePropagator extends \PHPUnit_Framework_TestCase {
+ /**
+ * @var \OC\Files\Cache\ChangePropagator
+ */
+ private $propagator;
+
+ /**
+ * @var \OC\Files\View
+ */
+ private $view;
+
+ public function setUp() {
+ $storage = new Temporary(array());
+ $root = '/' . uniqid();
+ Filesystem::mount($storage, array(), $root);
+ $this->view = new View($root);
+ $this->propagator = new \OC\Files\Cache\ChangePropagator($this->view);
+ }
+
+ public function testGetParentsSingle() {
+ $this->propagator->addChange('/foo/bar/asd');
+ $this->assertEquals(array('/', '/foo', '/foo/bar'), $this->propagator->getAllParents());
+ }
+
+ public function testGetParentsMultiple() {
+ $this->propagator->addChange('/foo/bar/asd');
+ $this->propagator->addChange('/foo/qwerty');
+ $this->propagator->addChange('/foo/asd/bar');
+ $this->assertEquals(array('/', '/foo', '/foo/bar', '/foo/asd'), $this->propagator->getAllParents());
+ }
+
+ public function testSinglePropagate() {
+ $this->view->mkdir('/foo');
+ $this->view->mkdir('/foo/bar');
+ $this->view->file_put_contents('/foo/bar/sad.txt', 'qwerty');
+
+ $oldInfo1 = $this->view->getFileInfo('/');
+ $oldInfo2 = $this->view->getFileInfo('/foo');
+ $oldInfo3 = $this->view->getFileInfo('/foo/bar');
+
+ $time = time() + 50;
+
+ $this->propagator->addChange('/foo/bar/sad.txt');
+ $this->propagator->propagateChanges($time);
+
+ $newInfo1 = $this->view->getFileInfo('/');
+ $newInfo2 = $this->view->getFileInfo('/foo');
+ $newInfo3 = $this->view->getFileInfo('/foo/bar');
+
+ $this->assertEquals($newInfo1->getMTime(), $time);
+ $this->assertEquals($newInfo2->getMTime(), $time);
+ $this->assertEquals($newInfo3->getMTime(), $time);
+
+ $this->assertNotEquals($oldInfo1->getEtag(), $newInfo1->getEtag());
+ $this->assertNotEquals($oldInfo2->getEtag(), $newInfo2->getEtag());
+ $this->assertNotEquals($oldInfo3->getEtag(), $newInfo3->getEtag());
+ }
+}
diff --git a/tests/lib/files/cache/scanner.php b/tests/lib/files/cache/scanner.php
index fb06f2dff3d..56c7b65bb08 100644
--- a/tests/lib/files/cache/scanner.php
+++ b/tests/lib/files/cache/scanner.php
@@ -234,13 +234,5 @@ class Scanner extends \PHPUnit_Framework_TestCase {
$newData0 = $this->cache->get('folder/bar.txt');
$this->assertInternalType('string', $newData0['etag']);
$this->assertNotEmpty($newData0['etag']);
-
- $newData1 = $this->cache->get('folder');
- $this->assertInternalType('string', $newData1['etag']);
- $this->assertNotSame($data1['etag'], $newData1['etag']);
-
- $newData2 = $this->cache->get('');
- $this->assertInternalType('string', $newData2['etag']);
- $this->assertNotSame($data2['etag'], $newData2['etag']);
}
}
diff --git a/tests/lib/files/utils/scanner.php b/tests/lib/files/utils/scanner.php
index a021d215ae5..159a2a48677 100644
--- a/tests/lib/files/utils/scanner.php
+++ b/tests/lib/files/utils/scanner.php
@@ -8,6 +8,7 @@
namespace Test\Files\Utils;
+use OC\Files\Filesystem;
use OC\Files\Mount\Mount;
use OC\Files\Storage\Temporary;
@@ -27,12 +28,21 @@ class TestScanner extends \OC\Files\Utils\Scanner {
protected function getMounts($dir) {
return $this->mounts;
}
+
+ public function getPropagator() {
+ return $this->propagator;
+ }
+
+ public function setPropagator($propagator) {
+ $this->propagator = $propagator;
+ }
}
class Scanner extends \PHPUnit_Framework_TestCase {
public function testReuseExistingRoot() {
$storage = new Temporary(array());
$mount = new Mount($storage, '');
+ Filesystem::getMountManager()->addMount($mount);
$cache = $storage->getCache();
$storage->mkdir('folder');
@@ -54,6 +64,7 @@ class Scanner extends \PHPUnit_Framework_TestCase {
public function testReuseExistingFile() {
$storage = new Temporary(array());
$mount = new Mount($storage, '');
+ Filesystem::getMountManager()->addMount($mount);
$cache = $storage->getCache();
$storage->mkdir('folder');
@@ -71,4 +82,57 @@ class Scanner extends \PHPUnit_Framework_TestCase {
$new = $cache->get('folder/bar.txt');
$this->assertEquals($old, $new);
}
+
+ public function testChangePropagator() {
+ /**
+ * @var \OC\Files\Cache\ChangePropagator $propagator
+ */
+ $propagator = $this->getMock('\OC\Files\Cache\ChangePropagator', array('propagateChanges'), array(), '', false);
+
+ $storage = new Temporary(array());
+ $mount = new Mount($storage, '/foo');
+ Filesystem::getMountManager()->addMount($mount);
+ $cache = $storage->getCache();
+
+ $storage->mkdir('folder');
+ $storage->file_put_contents('foo.txt', 'qwerty');
+ $storage->file_put_contents('folder/bar.txt', 'qwerty');
+
+ $scanner = new TestScanner('');
+ $originalPropagator = $scanner->getPropagator();
+ $scanner->setPropagator($propagator);
+ $scanner->addMount($mount);
+
+ $scanner->scan('');
+
+ $changes = $propagator->getChanges();
+ $parents = $propagator->getAllParents();
+ sort($changes);
+ sort($parents);
+ $this->assertEquals(array('/foo', '/foo/folder', '/foo/folder/bar.txt', '/foo/foo.txt'), $changes);
+ $this->assertEquals(array('/', '/foo', '/foo/folder'), $parents);
+
+ $cache->put('foo.txt', array('mtime' => time() - 50));
+
+ $propagator = $this->getMock('\OC\Files\Cache\ChangePropagator', array('propagateChanges'), array(), '', false);
+ $scanner->setPropagator($propagator);
+ $storage->file_put_contents('foo.txt', 'asdasd');
+
+ $scanner->scan('');
+
+ $changes = $propagator->getChanges();
+ $parents = $propagator->getAllParents();
+ $this->assertEquals(array('/foo/foo.txt'), $changes);
+ $this->assertEquals(array('/', '/foo'), $parents);
+
+ $scanner->setPropagator($originalPropagator);
+
+ $oldInfo = $cache->get('');
+ $cache->put('foo.txt', array('mtime' => time() - 70));
+ $storage->file_put_contents('foo.txt', 'asdasd');
+
+ $scanner->scan('');
+ $newInfo = $cache->get('');
+ $this->assertNotEquals($oldInfo['etag'], $newInfo['etag']);
+ }
}
diff --git a/tests/lib/files/view.php b/tests/lib/files/view.php
index b5e4d792350..1d8e729fb7b 100644
--- a/tests/lib/files/view.php
+++ b/tests/lib/files/view.php
@@ -52,14 +52,18 @@ class View extends \PHPUnit_Framework_TestCase {
$storage1 = $this->getTestStorage();
$storage2 = $this->getTestStorage();
$storage3 = $this->getTestStorage();
- \OC\Files\Filesystem::mount($storage1, array(), '/');
- \OC\Files\Filesystem::mount($storage2, array(), '/substorage');
- \OC\Files\Filesystem::mount($storage3, array(), '/folder/anotherstorage');
+ $root = '/' . uniqid();
+ \OC\Files\Filesystem::mount($storage1, array(), $root . '/');
+ \OC\Files\Filesystem::mount($storage2, array(), $root . '/substorage');
+ \OC\Files\Filesystem::mount($storage3, array(), $root . '/folder/anotherstorage');
$textSize = strlen("dummy file data\n");
$imageSize = filesize(\OC::$SERVERROOT . '/core/img/logo.png');
$storageSize = $textSize * 2 + $imageSize;
- $rootView = new \OC\Files\View('');
+ $storageInfo = $storage3->getCache()->get('');
+ $this->assertEquals($storageSize, $storageInfo['size']);
+
+ $rootView = new \OC\Files\View($root);
$cachedData = $rootView->getFileInfo('/foo.txt');
$this->assertEquals($textSize, $cachedData['size']);
@@ -110,7 +114,7 @@ class View extends \PHPUnit_Framework_TestCase {
$this->assertEquals('foo.png', $folderData[1]['name']);
$this->assertEquals('foo.txt', $folderData[2]['name']);
- $folderView = new \OC\Files\View('/folder');
+ $folderView = new \OC\Files\View($root . '/folder');
$this->assertEquals($rootView->getFileInfo('/folder'), $folderView->getFileInfo('/'));
$cachedData = $rootView->getFileInfo('/foo.txt');
@@ -580,9 +584,9 @@ class View extends \PHPUnit_Framework_TestCase {
$longPath = '';
// 4000 is the maximum path length in file_cache.path
$folderName = 'abcdefghijklmnopqrstuvwxyz012345678901234567890123456789';
- $depth = (4000/57);
- foreach (range(0, $depth-1) as $i) {
- $longPath .= '/'.$folderName;
+ $depth = (4000 / 57);
+ foreach (range(0, $depth - 1) as $i) {
+ $longPath .= '/' . $folderName;
$result = $rootView->mkdir($longPath);
$this->assertTrue($result, "mkdir failed on $i - path length: " . strlen($longPath));
@@ -598,7 +602,7 @@ class View extends \PHPUnit_Framework_TestCase {
$scanner->scan('');
$longPath = $folderName;
- foreach (range(0, $depth-1) as $i) {
+ foreach (range(0, $depth - 1) as $i) {
$cachedFolder = $cache->get($longPath);
$this->assertTrue(is_array($cachedFolder), "No cache entry for folder at $i");
$this->assertEquals($folderName, $cachedFolder['name'], "Wrong cache entry for folder at $i");
@@ -652,14 +656,14 @@ class View extends \PHPUnit_Framework_TestCase {
* @dataProvider tooLongPathDataProvider
* @expectedException \OCP\Files\InvalidPathException
*/
- public function testTooLongPath($operation, $param0 = NULL) {
+ public function testTooLongPath($operation, $param0 = null) {
$longPath = '';
// 4000 is the maximum path length in file_cache.path
$folderName = 'abcdefghijklmnopqrstuvwxyz012345678901234567890123456789';
- $depth = (4000/57);
- foreach (range(0, $depth+1) as $i) {
- $longPath .= '/'.$folderName;
+ $depth = (4000 / 57);
+ foreach (range(0, $depth + 1) as $i) {
+ $longPath .= '/' . $folderName;
}
$storage = new \OC\Files\Storage\Temporary(array());