diff options
author | kalman@chromium.org <kalman@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-04-24 08:00:54 +0000 |
---|---|---|
committer | kalman@chromium.org <kalman@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-04-24 08:00:54 +0000 |
commit | 8a6268d9f7ef89a2a082024f92402f23d1819094 (patch) | |
tree | 3d7ff734514d64b88c0f41e12fa4947e210bf545 /chrome/common/extensions | |
parent | ac0c76228c92cbb338f17c1268fbfc801b11d73c (diff) | |
download | chromium_src-8a6268d9f7ef89a2a082024f92402f23d1819094.zip chromium_src-8a6268d9f7ef89a2a082024f92402f23d1819094.tar.gz chromium_src-8a6268d9f7ef89a2a082024f92402f23d1819094.tar.bz2 |
Devserver: Re-create the online ServerInstances each time and tweak the way
that CacheChainObjectStore works so that crons and preview.py actually check
svn/local filesystems each time they run, rather than just the first time.
BUG=226625
NOTRY=true
Review URL: https://chromiumcodereview.appspot.com/14378003
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@196087 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/common/extensions')
7 files changed, 62 insertions, 18 deletions
diff --git a/chrome/common/extensions/docs/server2/app.yaml b/chrome/common/extensions/docs/server2/app.yaml index ee273fb..89a5442 100644 --- a/chrome/common/extensions/docs/server2/app.yaml +++ b/chrome/common/extensions/docs/server2/app.yaml @@ -1,5 +1,5 @@ application: chrome-apps-doc -version: 2-0-21 +version: 2-0-22 runtime: python27 api_version: 1 threadsafe: false diff --git a/chrome/common/extensions/docs/server2/cache_chain_object_store.py b/chrome/common/extensions/docs/server2/cache_chain_object_store.py index cb4034f..5f0a379 100644 --- a/chrome/common/extensions/docs/server2/cache_chain_object_store.py +++ b/chrome/common/extensions/docs/server2/cache_chain_object_store.py @@ -63,12 +63,17 @@ class CacheChainObjectStore(ObjectStore): The rules for the object store chain are: - When setting (or deleting) items, all object stores in the hierarcy will have that item set. - - When getting items, each object store is tried in order. The first object - store to find the item will trickle back up, setting it on all object - stores higher in the hierarchy. + - When getting items, the behaviour depends on |start_empty|. + - If false, each object store is tried in order. The first object + store to find the item will trickle back up, setting it on all object + stores higher in the hierarchy. + - If true, only the first in-memory cache is checked, as though the store + had been initialized with no content as opposed to the union of its + delegate stores. ''' - def __init__(self, object_stores): + def __init__(self, object_stores, start_empty=False): self._object_stores = object_stores + self._start_empty = start_empty self._cache = {} def SetMulti(self, mapping): @@ -83,7 +88,7 @@ class CacheChainObjectStore(ObjectStore): if key in self._cache: cached_items[key] = self._cache.get(key) missing_keys.remove(key) - if len(missing_keys) == 0: + if len(missing_keys) == 0 or self._start_empty: return Future(value=cached_items) object_store_futures = [(object_store, object_store.GetMulti(missing_keys)) for object_store in self._object_stores] diff --git a/chrome/common/extensions/docs/server2/cache_chain_object_store_test.py b/chrome/common/extensions/docs/server2/cache_chain_object_store_test.py index a2fa224..051d560 100755 --- a/chrome/common/extensions/docs/server2/cache_chain_object_store_test.py +++ b/chrome/common/extensions/docs/server2/cache_chain_object_store_test.py @@ -142,6 +142,10 @@ class CacheChainObjectStoreTest(unittest.TestCase): self.assertTrue(*self._first.CheckAndReset()) self.assertTrue(*self._second.CheckAndReset()) self.assertTrue(*self._third.CheckAndReset()) + # Should have the new content. + self.assertEqual('hello', self._first.Get('hello.html').Get()) + self.assertEqual('hello', self._second.Get('hello.html').Get()) + self.assertEqual('hello', self._third.Get('hello.html').Get()) def testDel(self): # Cache it. @@ -158,5 +162,23 @@ class CacheChainObjectStoreTest(unittest.TestCase): self.assertTrue(*self._second.CheckAndReset(get_count=1)) self.assertTrue(*self._third.CheckAndReset(get_count=1)) + def testStartEmpty(self): + store = CacheChainObjectStore((self._first, self._second, self._third), + start_empty=True) + # Won't query delegate file systems because it starts empty. + self.assertEqual(None, store.Get('storage.html').Get()) + self.assertTrue(*self._first.CheckAndReset()) + self.assertTrue(*self._second.CheckAndReset()) + self.assertTrue(*self._third.CheckAndReset()) + # Setting values will set on all delegates, though. + store.Set('storage.html', 'new content') + self.assertEqual('new content', store.Get('storage.html').Get()) + self.assertTrue(*self._first.CheckAndReset(set_count=1)) + self.assertTrue(*self._second.CheckAndReset(set_count=1)) + self.assertTrue(*self._third.CheckAndReset(set_count=1)) + self.assertEqual('new content', self._first.Get('storage.html').Get()) + self.assertEqual('new content', self._second.Get('storage.html').Get()) + self.assertEqual('new content', self._third.Get('storage.html').Get()) + if __name__ == '__main__': unittest.main() diff --git a/chrome/common/extensions/docs/server2/handler.py b/chrome/common/extensions/docs/server2/handler.py index 13f877f..f025737 100644 --- a/chrome/common/extensions/docs/server2/handler.py +++ b/chrome/common/extensions/docs/server2/handler.py @@ -57,7 +57,7 @@ class Handler(webapp.RequestHandler): real_path = 'extensions/index.html' constructor = ( - ServerInstance.GetOrCreateOnline if Handler.ALWAYS_ONLINE else + ServerInstance.CreateOnline if Handler.ALWAYS_ONLINE else ServerInstance.GetOrCreateOffline) server_instance = constructor(channel_name) @@ -94,7 +94,7 @@ class Handler(webapp.RequestHandler): channel = path.split('/')[-1] logging.info('cron/%s: starting' % channel) - server_instance = ServerInstance.GetOrCreateOnline(channel) + server_instance = ServerInstance.CreateOnline(channel) def run_cron_for_dir(d, path_prefix=''): success = True diff --git a/chrome/common/extensions/docs/server2/object_store_creator.py b/chrome/common/extensions/docs/server2/object_store_creator.py index 1911143..3d7bbd3 100644 --- a/chrome/common/extensions/docs/server2/object_store_creator.py +++ b/chrome/common/extensions/docs/server2/object_store_creator.py @@ -8,17 +8,23 @@ from persistent_object_store import PersistentObjectStore class ObjectStoreCreator(object): class Factory(object): - '''Creates ObjectStoreCreators (yes seriously) bound to an SVN branch. + '''Parameters: + - |branch| The branch to create object stores for. This becomes part of the + namespace for the object stores that are created. + - |start_empty| Whether the caching object store that gets created should + start empty, or start with the content of its delegate object stores. ''' - def __init__(self, app_version, branch): + def __init__(self, app_version, branch, start_empty=False): self._app_version = app_version self._branch = branch + self._start_empty = start_empty def Create(self, cls, store_type=None): return ObjectStoreCreator(cls, self._app_version, self._branch, - store_type=store_type) + store_type=store_type, + start_empty=self._start_empty) class SharedFactory(object): '''A |Factory| for creating object stores shared across branches. @@ -38,7 +44,12 @@ class ObjectStoreCreator(object): def Create(self, cls, store_type=None): return self._factory.Create(cls, store_type=store_type) - def __init__(self, cls, app_version, branch, store_type=None): + def __init__(self, + cls, + app_version, + branch, + store_type=None, + start_empty=False): '''Creates stores with a top-level namespace given by the name of |cls| combined with |branch|. Set an explicit |store_type| if necessary for tests. @@ -50,6 +61,7 @@ class ObjectStoreCreator(object): assert not cls.__name__[0].islower() # guard against non-class types self._name = '%s/%s@%s' % (app_version, cls.__name__, branch) self._store_type = store_type + self._start_empty = start_empty def Create(self, category=None): '''Creates a new object store with the top namespace given in the @@ -62,5 +74,6 @@ class ObjectStoreCreator(object): namespace = '%s/%s' % (namespace, category) if self._store_type is not None: return self._store_type(namespace) - return CacheChainObjectStore((MemcacheObjectStore(namespace), - PersistentObjectStore(namespace))) + return CacheChainObjectStore( + (MemcacheObjectStore(namespace), PersistentObjectStore(namespace)), + start_empty=self._start_empty) diff --git a/chrome/common/extensions/docs/server2/server_instance.py b/chrome/common/extensions/docs/server2/server_instance.py index b2b059e..4b13427 100644 --- a/chrome/common/extensions/docs/server2/server_instance.py +++ b/chrome/common/extensions/docs/server2/server_instance.py @@ -68,8 +68,7 @@ class ServerInstance(object): ServerInstance._GetOrCreateGithubFileSystem()) @staticmethod - @memoize - def GetOrCreateOnline(channel): + def CreateOnline(channel): '''Creates/creates an online server instance, meaning that both local and subversion/github resources are queried. ''' @@ -90,7 +89,8 @@ class ServerInstance(object): url_constants.VIEWVC_URL) object_store_creator_factory = ObjectStoreCreator.Factory(GetAppVersion(), - branch) + branch, + start_empty=True) svn_file_system = CachingFileSystem( SubversionFileSystem(AppEngineUrlFetcher(svn_url), diff --git a/chrome/common/extensions/docs/server2/subversion_file_system.py b/chrome/common/extensions/docs/server2/subversion_file_system.py index 9592e2b..2d9db99c 100644 --- a/chrome/common/extensions/docs/server2/subversion_file_system.py +++ b/chrome/common/extensions/docs/server2/subversion_file_system.py @@ -26,7 +26,11 @@ class _AsyncFetchFuture(object): def Get(self): for path, future in self._fetches: - result = future.Get() + try: + result = future.Get() + except Exception as e: + raise FileNotFoundError( + 'Error when fetching %s for Get: %s' % (path, e)) if result.status_code == 404: raise FileNotFoundError('Got 404 when fetching %s for Get' % path) elif path.endswith('/'): |