예제 #1
0
 def test_blob_set_chunks(self):
   """Test blob_set() chunks"""
   # set cache which will be split to 3 chunks (5+5+1 bytes)
   memcache.blob_set(self.memcache_client, "a", "01234567890")
   self.assertEqual(self.memcache_client.get("a:0"), "01234")
   self.assertEqual(self.memcache_client.get("a:5"), "56789")
   self.assertEqual(self.memcache_client.get("a:10"), "0")
예제 #2
0
 def test_blob_set_in_namespace(self):
   """Test blob set/get operation in namespace"""
   # set cache which will be split to 3 chunks (5+5+1 bytes)
   memcache.blob_set(self.memcache_client, "a", "01234567890", namespace="n")
   result = memcache.blob_get(self.memcache_client, "a", namespace="n")
   self.assertEqual(result, "01234567890")
   self.assertEqual(self.memcache_client.get("a", namespace="n"),
                    ["a:0", "a:5", "a:10"])
   self.assertEqual(self.memcache_client.get("a:0", namespace="n"), "01234")
예제 #3
0
  def test_update(self):
    """Test blob set/set operation"""
    # set cache which will be split to 3 chunks (5+5+1 bytes)
    memcache.blob_set(self.memcache_client, "a", "01234567890")
    # set cache with 2 chunks (5+2 bytes)
    memcache.blob_set(self.memcache_client, "a", "abcdefg")

    result = memcache.blob_get(self.memcache_client, "a")
    self.assertEqual(result, "abcdefg")
예제 #4
0
  def test_delete_on_blob_set(self):
    """Test blob set remove old chunks"""
    # set cache which will be split to 3 chunks (5+5+1 bytes)
    memcache.blob_set(self.memcache_client, "a", "01234567890")
    # set cache with 2 chunks (5+2 bytes)
    memcache.blob_set(self.memcache_client, "a", "abcdefg")

    # ensure that chunk #3 was removed
    self.assertIsNone(self.memcache_client.get("a:10"))
예제 #5
0
  def test_blob_set_get(self):
    """Test blob set/get operation"""
    # set cache which will be split to 3 chunks (5+5+1 bytes)
    data = "01234567890"

    memcache.blob_set(self.memcache_client, "a", data)
    result = memcache.blob_get(self.memcache_client, "a")

    self.assertEqual(result, data)
예제 #6
0
  def test_update_namespace(self):
    """Test blob_set() removes chunks from correct namespace"""
    # set cache which will be split to 3 chunks (5+5+1 bytes)
    memcache.blob_set(self.memcache_client, "a", "01234567890", namespace="n")
    # set cache with 2 chunks (5+2 bytes), which must remove previous chunks
    memcache.blob_set(self.memcache_client, "a", "abcdefg", namespace="n")

    result = memcache.blob_get(self.memcache_client, "a:10", namespace="n")
    # Ensure that chunk are removed from correct namespace
    self.assertIsNone(result)
예제 #7
0
 def test_big_value_saving(self):
     """Test storing in memcache huge chunk of data."""
     # Create a structure with a lot of data. It should take more than 1 Mb.
     data = {"a": {"b": ["test" * 10 for _ in range(10**6)]}}
     self.assertTrue(memcache.blob_set(self.memcache_client, "data", data))
     self.assertGreater(self.memcache_client.get_stats().get("bytes"),
                        memcache.MEMCACHE_MAX_ITEM_SIZE)
     self.assertEqual(data, memcache.blob_get(self.memcache_client, "data"))
예제 #8
0
 def test_big_value_saving(self):
   """Test storing in memcache huge chunk of data."""
   # Create a structure with a lot of data. It should take more than 1 Mb.
   data = {"a": {"b": ["test" * 10 for _ in range(10 ** 6)]}}
   self.assertTrue(memcache.blob_set(self.memcache_client, "data", data))
   self.assertGreater(
       self.memcache_client.get_stats().get("bytes"),
       memcache.MEMCACHE_MAX_ITEM_SIZE
   )
   self.assertEqual(
       data,
       memcache.blob_get(self.memcache_client, "data")
   )
예제 #9
0
def store_results_into_memcache(permissions, cache, key):
    """Load personal context for user

  This function must only be called if memcahe is enabled

  Args:
      permissions (dict): dict where the permissions will be stored
      cache (cache_manager): Cache manager that should be used for storing
                             permissions
      key (string): key of under which permissions should be stored
  Returns:
      None
  """

    cached_keys_set = cache.get('permissions:list') or set()
    if key in cached_keys_set and \
       not memcache.blob_set(
           cache,
           key,
           permissions,
           exp_time=PERMISSION_CACHE_TIMEOUT,
       ):
        logger.error("Failed to set permissions data into memcache")
예제 #10
0
def store_results_into_memcache(permissions, cache, key):
  """Load personal context for user

  This function must only be called if memcahe is enabled

  Args:
      permissions (dict): dict where the permissions will be stored
      cache (cache_manager): Cache manager that should be used for storing
                             permissions
      key (string): key of under which permissions should be stored
  Returns:
      None
  """

  cached_keys_set = cache.get('permissions:list') or set()
  if key in cached_keys_set and \
     not memcache.blob_set(
         cache,
         key,
         permissions,
         exp_time=PERMISSION_CACHE_TIMEOUT,
     ):
    logger.error("Failed to set permissions data into memcache")
예제 #11
0
 def test_blob_set(self):
   """Test blob_set()"""
   # set cache which will be split to 3 chunks (5+5+1 bytes)
   memcache.blob_set(self.memcache_client, "a", "01234567890")
   keys = memcache.blob_get_chunk_keys(self.memcache_client, "a")
   self.assertEqual(keys, ["a:0", "a:5", "a:10"])