Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(58)

Side by Side Diff: chrome/common/extensions/docs/server2/memcache_file_system_test.py

Issue 10834329: Extension docs server: many changes to bring down the latency of the server, (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 8 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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 unittest 7 import unittest
8 8
9 import appengine_memcache as memcache 9 import appengine_memcache as memcache
10 from appengine_memcache import AppEngineMemcache 10 from appengine_memcache import AppEngineMemcache
11 from file_system import FileSystem 11 from file_system import FileSystem, StatInfo
12 from future import Future 12 from future import Future
13 from local_file_system import LocalFileSystem 13 from local_file_system import LocalFileSystem
14 from memcache_file_system import MemcacheFileSystem 14 from memcache_file_system import MemcacheFileSystem
15 15
16 class _FakeFileSystem(FileSystem): 16 class _FakeFileSystem(FileSystem):
17 def __init__(self): 17 def __init__(self):
18 self.stat_value = 0 18 self.stat_value = 0
19 self._stat_count = 0 19 self._stat_count = 0
20 self._read_count = 0 20 self._read_count = 0
21 21
22 def CheckAndReset(self, read_count=0, stat_count=0): 22 def CheckAndReset(self, read_count=0, stat_count=0):
23 try: 23 try:
24 return (self._read_count == read_count and 24 return (self._read_count == read_count and
25 self._stat_count == stat_count) 25 self._stat_count == stat_count)
26 finally: 26 finally:
27 self._read_count = 0 27 self._read_count = 0
28 self._stat_count = 0 28 self._stat_count = 0
29 29
30 def Stat(self, path): 30 def Stat(self, path):
31 self._stat_count += 1 31 self._stat_count += 1
32 return self.StatInfo( 32 return StatInfo(
33 self.stat_value, 33 self.stat_value,
34 dict((path + str(i), self.stat_value) for i in range(5))) 34 dict((path + str(i), self.stat_value) for i in range(5)))
35 35
36 def Read(self, paths, binary=False): 36 def Read(self, paths, binary=False):
37 self._read_count += 1 37 self._read_count += 1
38 return Future(value=dict((path, path) for path in paths)) 38 return Future(value=dict((path, path) for path in paths))
39 39
40 class MemcacheFileSystemTest(unittest.TestCase): 40 class MemcacheFileSystemTest(unittest.TestCase):
41 def setUp(self): 41 def setUp(self):
42 self._memcache = AppEngineMemcache('') 42 self._memcache = AppEngineMemcache('')
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after
118 self.assertTrue(fake_fs.CheckAndReset()) 118 self.assertTrue(fake_fs.CheckAndReset())
119 119
120 self._DeleteStatCacheItem('bob/bob0') 120 self._DeleteStatCacheItem('bob/bob0')
121 self.assertEqual('bob/bob0', file_system.ReadSingle('bob/bob0')) 121 self.assertEqual('bob/bob0', file_system.ReadSingle('bob/bob0'))
122 self.assertTrue(fake_fs.CheckAndReset(stat_count=1)) 122 self.assertTrue(fake_fs.CheckAndReset(stat_count=1))
123 self.assertEqual('bob/bob0', file_system.ReadSingle('bob/bob0')) 123 self.assertEqual('bob/bob0', file_system.ReadSingle('bob/bob0'))
124 self.assertTrue(fake_fs.CheckAndReset()) 124 self.assertTrue(fake_fs.CheckAndReset())
125 125
126 if __name__ == '__main__': 126 if __name__ == '__main__':
127 unittest.main() 127 unittest.main()
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698