| 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'))
|
|
|