def testListDir(self): file_system = MemcacheFileSystem(self._local_fs, self._object_store) expected = ['dir/'] for i in range(7): expected.append('file%d.html' % i) self._SetReadCacheItem('list/', expected, file_system.Stat('list/').version) self.assertEqual(expected, sorted(file_system.ReadSingle('list/'))) expected.remove('file0.html') self._SetReadCacheItem('list/', expected, file_system.Stat('list/').version) self.assertEqual(expected, sorted(file_system.ReadSingle('list/')))
class ExampleZipperTest(unittest.TestCase): def setUp(self): object_store = InMemoryObjectStore('') self._file_system = MemcacheFileSystem( LocalFileSystem(os.path.join(sys.path[0], 'test_data')), object_store) self._example_zipper = ExampleZipper( self._file_system, CompiledFileSystem.Factory(self._file_system, object_store), 'example_zipper') def testCreateZip(self): # Cache manifest.json as unicode and make sure ExampleZipper doesn't error. self._file_system.ReadSingle('example_zipper/basic/manifest.json') self.assertTrue(len(self._example_zipper.Create('basic')) > 0)
def testCaching(self): fake_fs = _FakeFileSystem() file_system = MemcacheFileSystem(fake_fs, self._object_store) self.assertEqual('bob/bob0', file_system.ReadSingle('bob/bob0')) self.assertTrue(fake_fs.CheckAndReset(read_count=1, stat_count=1)) # Resource has been cached, so test resource is not re-fetched. self.assertEqual('bob/bob0', file_system.ReadSingle('bob/bob0')) self.assertTrue(fake_fs.CheckAndReset()) # Test if the Stat version is the same the resource is not re-fetched. self._DeleteStatCacheItem('bob/bob0') self.assertEqual('bob/bob0', file_system.ReadSingle('bob/bob0')) self.assertTrue(fake_fs.CheckAndReset(stat_count=1)) # Test if there is a newer version, the resource is re-fetched. self._DeleteStatCacheItem('bob/bob0') fake_fs.stat_value += 1 self.assertEqual('bob/bob0', file_system.ReadSingle('bob/bob0')) self.assertTrue(fake_fs.CheckAndReset(read_count=1, stat_count=1)) # Test directory and subdirectory stats are cached. self._DeleteStatCacheItem('bob/bob0') self._DeleteReadCacheItem('bob/bob0') self._DeleteStatCacheItem('bob/bob1') self.assertEqual('bob/bob1', file_system.ReadSingle('bob/bob1')) self.assertEqual('bob/bob0', file_system.ReadSingle('bob/bob0')) self.assertTrue(fake_fs.CheckAndReset(read_count=2, stat_count=1)) self.assertEqual('bob/bob1', file_system.ReadSingle('bob/bob1')) self.assertTrue(fake_fs.CheckAndReset()) # Test a more recent parent directory doesn't force a refetch of children. self._DeleteReadCacheItem('bob/bob0') self._DeleteReadCacheItem('bob/bob1') self.assertEqual('bob/bob1', file_system.ReadSingle('bob/bob1')) self.assertEqual('bob/bob2', file_system.ReadSingle('bob/bob2')) self.assertEqual('bob/bob3', file_system.ReadSingle('bob/bob3')) self.assertTrue(fake_fs.CheckAndReset(read_count=3)) self._SetStatCacheItem('bob/', 10) self.assertEqual('bob/bob1', file_system.ReadSingle('bob/bob1')) self.assertEqual('bob/bob2', file_system.ReadSingle('bob/bob2')) self.assertEqual('bob/bob3', file_system.ReadSingle('bob/bob3')) self.assertTrue(fake_fs.CheckAndReset()) self._DeleteStatCacheItem('bob/bob0') self.assertEqual('bob/bob0', file_system.ReadSingle('bob/bob0')) self.assertTrue(fake_fs.CheckAndReset(read_count=1, stat_count=1)) self.assertEqual('bob/bob0', file_system.ReadSingle('bob/bob0')) self.assertTrue(fake_fs.CheckAndReset())