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

Side by Side 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: 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 unified diff | Download patch
OLDNEW
(Empty)
1
wrengr 2016/12/06 21:52:57 missing copyright header
Sharu Jiang 2016/12/06 23:58:17 Done.
2 import pickle
3 import zlib
4
5 from google.appengine.api import memcache
6
7 from testing_utils import testing
8
9 from gae_libs import caches
10
11
12 class CachesTest(testing.AppengineTestCase):
13
14 def testPickledMemCache(self):
15 """Tests using app engine ``memcache`` to cache data."""
16 cache = caches.PickledMemCache()
17 cache.Set('a', 'd')
18 self.assertEquals('d', cache.Get('a'))
19
20 def _MockPickleAndZlib(self):
21 def Func(string, *_, **__):
22 return string
23 self.mock(pickle, 'dumps', Func)
24 self.mock(pickle, 'loads', Func)
25 self.mock(zlib, 'compress', Func)
26 self.mock(zlib, 'decompress', Func)
27
28 def testCachingSmallDataInCompressedMemCache(self):
29 """Tests if ``CompressedMemCache`` cache small data (1KB) successfully."""
wrengr 2016/12/06 21:52:57 "cache" -> "caches"
Sharu Jiang 2016/12/06 23:58:17 Done.
30 self._MockPickleAndZlib()
31 cache = caches.CompressedMemCache()
32 data = 'A' * 1024 # A string of size 1KB.
33 cache.Set('a', data)
34 self.assertEquals(data, cache.Get('a'))
35
36 def testCachingLargeDataInCompressedMemCache(self):
37 """App engine memcache can only cache data < 1MB at one time, so data > 1MB
wrengr 2016/12/06 21:52:57 single-line docstring before the longer explanatio
Sharu Jiang 2016/12/06 23:58:17 Done.
38 will be split into sub-piece and stored separately. Tests if LargData are
39 cached successfully."""
40 self._MockPickleAndZlib()
41 cache = caches.CompressedMemCache()
42 data = 'A' * (1024 * 1024 * 2) # A string of size 2MB.
43 cache.Set('a', data)
44 self.assertEquals(data, cache.Get('a'))
45
46 def testMissingSubPieceOfLargeDataInCompressedMemCache(self):
47 """Tests ``CompressedMemCache`` return None when the data is broken."""
wrengr 2016/12/06 21:52:57 -> "Tests that ``CompressedMemCache`` returns None
Sharu Jiang 2016/12/06 23:58:17 Done.
48 self._MockPickleAndZlib()
49 cache = caches.CompressedMemCache()
50 data = 'A' * (1024 * 1024 * 2) # A string of size 2MB.
51 cache.Set('a', data)
52 memcache.delete('a-0')
53 self.assertEquals(None, cache.Get('a'))
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698