public function testPropagateEtag() { $storage = new Temporary(array()); $mount = new MountPoint($storage, ''); Filesystem::getMountManager()->addMount($mount); $cache = $storage->getCache(); $storage->mkdir('folder'); $storage->file_put_contents('folder/bar.txt', 'qwerty'); $storage->touch('folder/bar.txt', time() - 200); $scanner = new TestScanner('', \OC::$server->getDatabaseConnection(), \OC::$server->getLogger()); $scanner->addMount($mount); $scanner->scan(''); $this->assertTrue($cache->inCache('folder/bar.txt')); $oldRoot = $cache->get(''); $storage->file_put_contents('folder/bar.txt', 'qwerty'); $scanner->scan(''); $newRoot = $cache->get(''); $this->assertNotEquals($oldRoot->getEtag(), $newRoot->getEtag()); }
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 MountPoint($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('', \OC::$server->getDatabaseConnection()); $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('storage_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('storage_mtime' => time() - 70)); $storage->file_put_contents('foo.txt', 'asdasd'); $scanner->scan(''); $newInfo = $cache->get(''); $this->assertNotEquals($oldInfo['etag'], $newInfo['etag']); }
public function testReuseExistingFile() { $storage = new Temporary(array()); $mount = new MountPoint($storage, ''); 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('', \OC::$server->getDatabaseConnection(), \OC::$server->getLogger()); $scanner->addMount($mount); $scanner->scan(''); $this->assertTrue($cache->inCache('folder/bar.txt')); $old = $cache->get('folder/bar.txt'); $scanner->scan(''); $new = $cache->get('folder/bar.txt'); $this->assertEquals($old, $new); }