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

Unified Diff: appengine/findit/gae_libs/test/caches_test.py

Issue 2557553002: [Culprit-Finder] Seperate gae related part in cache_decorator and gitile repository to gae_libs/ (Closed)
Patch Set: Fix nits. Created 4 years 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « appengine/findit/gae_libs/test/__init__.py ('k') | appengine/findit/handlers/crash/crash_handler.py » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: appengine/findit/gae_libs/test/caches_test.py
diff --git a/appengine/findit/gae_libs/test/caches_test.py b/appengine/findit/gae_libs/test/caches_test.py
new file mode 100644
index 0000000000000000000000000000000000000000..7fc02b8fe654cb25ef8793b1f2c74bc5e73ac62d
--- /dev/null
+++ b/appengine/findit/gae_libs/test/caches_test.py
@@ -0,0 +1,58 @@
+# Copyright 2016 The Chromium Authors. All rights reserved.
+# Use of this source code is governed by a BSD-style license that can be
+# found in the LICENSE file.
+
+import pickle
+import zlib
+
+from google.appengine.api import memcache
+
+from testing_utils import testing
+
+from gae_libs import caches
+
+
+class CachesTest(testing.AppengineTestCase):
+
+ def testPickledMemCache(self):
+ """Tests using app engine ``memcache`` to cache data."""
+ cache = caches.PickledMemCache()
+ cache.Set('a', 'd')
+ self.assertEquals('d', cache.Get('a'))
+
+ def _MockPickleAndZlib(self):
+ def Func(string, *_, **__):
+ return string
+ self.mock(pickle, 'dumps', Func)
+ self.mock(pickle, 'loads', Func)
+ self.mock(zlib, 'compress', Func)
+ self.mock(zlib, 'decompress', Func)
+
+ def testCachingSmallDataInCompressedMemCache(self):
+ """Tests if ``CompressedMemCache`` caches small data (1KB) successfully."""
+ self._MockPickleAndZlib()
+ cache = caches.CompressedMemCache()
+ data = 'A' * 1024 # A string of size 1KB.
+ cache.Set('a', data)
+ self.assertEquals(data, cache.Get('a'))
+
+ def testCachingLargeDataInCompressedMemCache(self):
+ """Tests if LargData are cached successfully.
+
+ App engine memcache can only cache data < 1MB at one time, so data > 1MB
+ will be split into sub-piece and stored separately.
+ """
+ self._MockPickleAndZlib()
+ cache = caches.CompressedMemCache()
+ data = 'A' * (1024 * 1024 * 2) # A string of size 2MB.
+ cache.Set('a', data)
+ self.assertEquals(data, cache.Get('a'))
+
+ def testMissingSubPieceOfLargeDataInCompressedMemCache(self):
+ """Tests ``CompressedMemCache`` returns None when the data is broken."""
+ self._MockPickleAndZlib()
+ cache = caches.CompressedMemCache()
+ data = 'A' * (1024 * 1024 * 2) # A string of size 2MB.
+ cache.Set('a', data)
+ memcache.delete('a-0')
+ self.assertEquals(None, cache.Get('a'))
« no previous file with comments | « appengine/findit/gae_libs/test/__init__.py ('k') | appengine/findit/handlers/crash/crash_handler.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698