summaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorVincent Petry <pvince81@owncloud.com>2016-06-10 17:45:52 +0200
committerGitHub <noreply@github.com>2016-06-10 17:45:52 +0200
commit52a0c939ab8674857bbfe9a9fb0ee7308eee960e (patch)
tree8e49d951042f62b1875f43011d0f45652916335b /tests
parent21de838b857e8400b838e2d67a1de3cd40c7aa2d (diff)
parentfce19d22d93d8c36066f5fe67efb86bf257a37c7 (diff)
downloadnextcloud-server-52a0c939ab8674857bbfe9a9fb0ee7308eee960e.tar.gz
nextcloud-server-52a0c939ab8674857bbfe9a9fb0ee7308eee960e.zip
Merge pull request #24863 from owncloud/propagator-batching
Propagator batching for the file scanner
Diffstat (limited to 'tests')
-rw-r--r--tests/lib/Files/Cache/PropagatorTest.php125
1 files changed, 125 insertions, 0 deletions
diff --git a/tests/lib/Files/Cache/PropagatorTest.php b/tests/lib/Files/Cache/PropagatorTest.php
new file mode 100644
index 00000000000..402b29c8c3e
--- /dev/null
+++ b/tests/lib/Files/Cache/PropagatorTest.php
@@ -0,0 +1,125 @@
+<?php
+/**
+ * Copyright (c) 2012 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\Storage\Temporary;
+use OCP\Files\Cache\ICacheEntry;
+use OCP\Files\Storage\IStorage;
+use Test\TestCase;
+
+/**
+ * @group DB
+ */
+class PropagatorTest extends TestCase {
+ /** @var IStorage */
+ private $storage;
+
+ public function setUp() {
+ parent::setUp();
+ $this->storage = new Temporary();
+ $this->storage->mkdir('foo/bar');
+ $this->storage->file_put_contents('foo/bar/file.txt', 'bar');
+ $this->storage->getScanner()->scan('');
+ }
+
+ /**
+ * @param $paths
+ * @return ICacheEntry[]
+ */
+ private function getFileInfos($paths) {
+ $values = array_map(function ($path) {
+ return $this->storage->getCache()->get($path);
+ }, $paths);
+ return array_combine($paths, $values);
+ }
+
+ public function testEtagPropagation() {
+ $paths = ['', 'foo', 'foo/bar'];
+ $oldInfos = $this->getFileInfos($paths);
+ $this->storage->getPropagator()->propagateChange('foo/bar/file.txt', time());
+ $newInfos = $this->getFileInfos($paths);
+
+ foreach ($oldInfos as $i => $oldInfo) {
+ $this->assertNotEquals($oldInfo->getEtag(), $newInfos[$i]->getEtag());
+ }
+ }
+
+ public function testTimePropagation() {
+ $paths = ['', 'foo', 'foo/bar'];
+ $oldTime = time() - 200;
+ $targetTime = time() - 100;
+ $now = time();
+ $cache = $this->storage->getCache();
+ $cache->put('', ['mtime' => $now]);
+ $cache->put('foo', ['mtime' => $now]);
+ $cache->put('foo/bar', ['mtime' => $oldTime]);
+ $cache->put('foo/bar/file.txt', ['mtime' => $oldTime]);
+ $this->storage->getPropagator()->propagateChange('foo/bar/file.txt', $targetTime);
+ $newInfos = $this->getFileInfos($paths);
+
+ $this->assertEquals($targetTime, $newInfos['foo/bar']->getMTime());
+
+ // dont lower mtimes
+ $this->assertEquals($now, $newInfos['foo']->getMTime());
+ $this->assertEquals($now, $newInfos['']->getMTime());
+ }
+
+ public function testSizePropagation() {
+ $paths = ['', 'foo', 'foo/bar'];
+ $oldInfos = $this->getFileInfos($paths);
+ $this->storage->getPropagator()->propagateChange('foo/bar/file.txt', time(), 10);
+ $newInfos = $this->getFileInfos($paths);
+
+ foreach ($oldInfos as $i => $oldInfo) {
+ $this->assertEquals($oldInfo->getSize() + 10, $newInfos[$i]->getSize());
+ }
+ }
+
+ public function testBatchedPropagation() {
+ $this->storage->mkdir('foo/baz');
+ $this->storage->mkdir('asd');
+ $this->storage->file_put_contents('asd/file.txt', 'bar');
+ $this->storage->file_put_contents('foo/baz/file.txt', 'bar');
+ $this->storage->getScanner()->scan('');
+
+ $paths = ['', 'foo', 'foo/bar', 'asd', 'foo/baz'];
+
+ $oldInfos = $this->getFileInfos($paths);
+ $propagator = $this->storage->getPropagator();
+
+ $propagator->beginBatch();
+ $propagator->propagateChange('asd/file.txt', time(), 10);
+ $propagator->propagateChange('foo/bar/file.txt', time(), 2);
+
+ $newInfos = $this->getFileInfos($paths);
+
+ // no changes until we finish the batch
+ foreach ($oldInfos as $i => $oldInfo) {
+ $this->assertEquals($oldInfo->getSize(), $newInfos[$i]->getSize());
+ $this->assertEquals($oldInfo->getEtag(), $newInfos[$i]->getEtag());
+ $this->assertEquals($oldInfo->getMTime(), $newInfos[$i]->getMTime());
+ }
+
+ $propagator->commitBatch();
+
+ $newInfos = $this->getFileInfos($paths);
+
+ foreach ($oldInfos as $i => $oldInfo) {
+ if ($oldInfo->getPath() !== 'foo/baz') {
+ $this->assertNotEquals($oldInfo->getEtag(), $newInfos[$i]->getEtag());
+ }
+ }
+
+ $this->assertEquals($oldInfos['']->getSize() + 12, $newInfos['']->getSize());
+ $this->assertEquals($oldInfos['asd']->getSize() + 10, $newInfos['asd']->getSize());
+ $this->assertEquals($oldInfos['foo']->getSize() + 2, $newInfos['foo']->getSize());
+ $this->assertEquals($oldInfos['foo/bar']->getSize() + 2, $newInfos['foo/bar']->getSize());
+ $this->assertEquals($oldInfos['foo/baz']->getSize(), $newInfos['foo/baz']->getSize());
+ }
+}