Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 #!/usr/bin/env python | 1 #!/usr/bin/env python |
| 2 # Copyright (c) 2012 The Chromium Authors. All rights reserved. | 2 # Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| 3 # Use of this source code is governed by a BSD-style license that can be | 3 # Use of this source code is governed by a BSD-style license that can be |
| 4 # found in the LICENSE file. | 4 # found in the LICENSE file. |
| 5 | 5 |
| 6 import os | 6 import os |
| 7 import sys | 7 import sys |
| 8 import unittest | 8 import unittest |
| 9 | 9 |
| 10 from caching_file_system import CachingFileSystem | 10 from caching_file_system import CachingFileSystem |
| 11 from extensions_paths import SERVER2 | 11 from extensions_paths import SERVER2 |
| 12 from file_system import StatInfo | 12 from file_system import FileNotFoundError, StatInfo |
| 13 from local_file_system import LocalFileSystem | 13 from local_file_system import LocalFileSystem |
| 14 from mock_file_system import MockFileSystem | 14 from mock_file_system import MockFileSystem |
| 15 from object_store_creator import ObjectStoreCreator | 15 from object_store_creator import ObjectStoreCreator |
| 16 from test_file_system import TestFileSystem | 16 from test_file_system import TestFileSystem |
| 17 from test_object_store import TestObjectStore | 17 from test_object_store import TestObjectStore |
| 18 | 18 |
| 19 | 19 |
| 20 def _CreateLocalFs(): | 20 def _CreateLocalFs(): |
| 21 return LocalFileSystem.Create(SERVER2, 'test_data', 'file_system/') | 21 return LocalFileSystem.Create(SERVER2, 'test_data', 'file_system/') |
| 22 | 22 |
| (...skipping 129 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 152 file_system = create_empty_caching_fs() | 152 file_system = create_empty_caching_fs() |
| 153 file_system._stat_object_store.Del('bob/bob0') | 153 file_system._stat_object_store.Del('bob/bob0') |
| 154 future = file_system.ReadSingle('bob/bob0') | 154 future = file_system.ReadSingle('bob/bob0') |
| 155 self.assertTrue(*mock_fs.CheckAndReset(read_count=1)) | 155 self.assertTrue(*mock_fs.CheckAndReset(read_count=1)) |
| 156 self.assertEqual('bob/bob0 contents', future.Get()) | 156 self.assertEqual('bob/bob0 contents', future.Get()) |
| 157 self.assertTrue(*mock_fs.CheckAndReset(read_resolve_count=1, stat_count=1)) | 157 self.assertTrue(*mock_fs.CheckAndReset(read_resolve_count=1, stat_count=1)) |
| 158 self.assertEqual('bob/bob0 contents', | 158 self.assertEqual('bob/bob0 contents', |
| 159 file_system.ReadSingle('bob/bob0').Get()) | 159 file_system.ReadSingle('bob/bob0').Get()) |
| 160 self.assertTrue(*mock_fs.CheckAndReset()) | 160 self.assertTrue(*mock_fs.CheckAndReset()) |
| 161 | 161 |
| 162 file_system = create_empty_caching_fs() | |
| 163 future = file_system.ReadSingle('bob/no_file', skip_not_found=True) | |
| 164 self.assertTrue(*mock_fs.CheckAndReset(read_count=1)) | |
| 165 self.assertEqual(None, future.Get()) | |
| 166 self.assertTrue(*mock_fs.CheckAndReset(read_resolve_count=1, stat_count=1)) | |
| 167 future = file_system.ReadSingle('bob/no_file', skip_not_found=True) | |
| 168 # There shouldn't be another read/stat from the file system; | |
| 169 # we know the file is not there. | |
| 170 self.assertTrue(*mock_fs.CheckAndReset()) | |
| 171 future = file_system.ReadSingle('bob/no_file') | |
| 172 # Even though we cached information about non-existent files, | |
| 173 # trying to read one without specifiying skip_not_found should | |
| 174 # still raise an error. | |
| 175 self.assertRaises(FileNotFoundError, future.Get) | |
|
not at google - send to devlin
2014/08/26 20:59:34
Nice tests. Is it possible to extend the test to c
ahernandez
2014/08/27 18:54:38
I'm not sure I can do that, because Stat updates a
not at google - send to devlin
2014/08/27 19:22:13
Isn't this line 107 kinda?
ahernandez
2014/08/27 19:29:00
That does increment the stat, but the stat_cache d
not at google - send to devlin
2014/08/27 19:32:49
Ah yes I think you're right, those tests are ... p
| |
| 176 | |
| 162 def testCachedStat(self): | 177 def testCachedStat(self): |
| 163 test_fs = TestFileSystem({ | 178 test_fs = TestFileSystem({ |
| 164 'bob': { | 179 'bob': { |
| 165 'bob0': 'bob/bob0 contents', | 180 'bob0': 'bob/bob0 contents', |
| 166 'bob1': 'bob/bob1 contents' | 181 'bob1': 'bob/bob1 contents' |
| 167 } | 182 } |
| 168 }) | 183 }) |
| 169 mock_fs = MockFileSystem(test_fs) | 184 mock_fs = MockFileSystem(test_fs) |
| 170 | 185 |
| 171 file_system = self._CreateCachingFileSystem(mock_fs, start_empty=False) | 186 file_system = self._CreateCachingFileSystem(mock_fs, start_empty=False) |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 212 self.assertEqual(StatInfo(stat), file_system.Stat('bob/bob0')) | 227 self.assertEqual(StatInfo(stat), file_system.Stat('bob/bob0')) |
| 213 self.assertEqual(StatInfo(stat), file_system.Stat('bob/bob0')) | 228 self.assertEqual(StatInfo(stat), file_system.Stat('bob/bob0')) |
| 214 self.assertTrue(*mock_fs.CheckAndReset()) | 229 self.assertTrue(*mock_fs.CheckAndReset()) |
| 215 run() | 230 run() |
| 216 run() | 231 run() |
| 217 | 232 |
| 218 run_expecting_stat('0') | 233 run_expecting_stat('0') |
| 219 test_fs.IncrementStat() | 234 test_fs.IncrementStat() |
| 220 run_expecting_stat('1') | 235 run_expecting_stat('1') |
| 221 | 236 |
| 222 def testSkipNotFound(self): | 237 def testSkipNotFound(self): |
|
ahernandez
2014/08/26 20:08:37
This test wasn't even running before because of im
not at google - send to devlin
2014/08/26 20:59:34
Oh man :\ good catch.
| |
| 223 caching_fs = self._CreateCachingFileSystem(TestFileSystem({ | 238 caching_fs = self._CreateCachingFileSystem(TestFileSystem({ |
| 224 'bob': { | 239 'bob': { |
| 225 'bob0': 'bob/bob0 contents', | 240 'bob0': 'bob/bob0 contents', |
| 226 'bob1': 'bob/bob1 contents' | 241 'bob1': 'bob/bob1 contents' |
| 227 } | 242 } |
| 228 })) | 243 })) |
| 229 def read_skip_not_found(paths): | 244 def read_skip_not_found(paths): |
| 230 return caching_fs.Read(paths, skip_not_found=True).Get() | 245 return caching_fs.Read(paths, skip_not_found=True).Get() |
| 231 self.assertEqual({}, read_skip_not_found(('grub',))) | 246 self.assertEqual({}, read_skip_not_found(('grub',))) |
| 232 self.assertEqual({}, read_skip_not_found(('bob/bob2',))) | 247 self.assertEqual({}, read_skip_not_found(('bob/bob2',))) |
| 233 self.assertEqual({ | 248 self.assertEqual({ |
| 234 'bob/bob0': 'bob/bob0 contents', | 249 'bob/bob0': 'bob/bob0 contents', |
| 235 }, read_skip_not_found(('bob/bob0', 'bob/bob2'))) | 250 }, read_skip_not_found(('bob/bob0', 'bob/bob2'))) |
| 236 | 251 |
| 237 | 252 |
| 238 if __name__ == '__main__': | 253 if __name__ == '__main__': |
| 239 unittest.main() | 254 unittest.main() |
| OLD | NEW |