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

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