Пример #1
0
    def test_generation_increment_race(self, cache):
        """
        If two caching wrappers try to increment the same nonexistent
        generation key at the same time, it should end up at 2, not 1.

        """
        from ccui.core.cache import CachingHttpWrapper

        wrapper = CachingHttpWrapper("wrapped", ["perms"], ["BucketName"])

        # Simulate a second wrapper having won the race between failed incr and
        # add by setting up the incr method to raise ValueError on first call
        # and return 2 on second call, and the add method to return False (not
        # added).
        cache.add.return_value = False

        def _incr(key, called=[]):
            # intentionally using mutable default as collector
            if called:
                return 2
            called.append(True)
            raise ValueError("Key %r not found" % key)

        cache.incr.side_effect = _incr

        self.assertEqual(wrapper._next_generation("BucketName"), 2)
Пример #2
0
    def test_generation_increment_success(self, cache):
        from ccui.core.cache import CachingHttpWrapper

        wrapper = CachingHttpWrapper("wrapped", ["perms"], ["BucketName"])

        cache.incr.return_value = 3

        self.assertEqual(wrapper._next_generation("BucketName"), 3)
Пример #3
0
    def test_generation_increment_success(self, cache):
        from ccui.core.cache import CachingHttpWrapper

        wrapper = CachingHttpWrapper("wrapped", ["perms"], ["BucketName"])

        cache.incr.return_value = 3

        self.assertEqual(wrapper._next_generation("BucketName"), 3)
Пример #4
0
    def make_request(self, **kwargs):
        from ccui.core.cache import CachingHttpWrapper

        res = Mock(["status"])
        res.status = kwargs.pop("response_status", httplib.OK)
        content = kwargs.pop("response_content", "content")
        permissions = kwargs.pop("permissions", [])
        buckets = kwargs.pop("cache_buckets", ["BucketName"])
        dependent_buckets = kwargs.pop("cache_dependent_buckets", [])
        with patch("ccui.core.api.Http") as http:
            http.request.return_value = (res, content)
            return CachingHttpWrapper(http, permissions, buckets,
                                      dependent_buckets).request(**kwargs)
Пример #5
0
    def test_generation_increment_race(self, cache):
        """
        If two caching wrappers try to increment the same nonexistent
        generation key at the same time, it should end up at 2, not 1.

        """
        from ccui.core.cache import CachingHttpWrapper

        wrapper = CachingHttpWrapper("wrapped", ["perms"], ["BucketName"])

        # Simulate a second wrapper having won the race between failed incr and
        # add by setting up the incr method to raise ValueError on first call
        # and return 2 on second call, and the add method to return False (not
        # added).
        cache.add.return_value = False
        def _incr(key, called=[]):
            # intentionally using mutable default as collector
            if called:
                return 2
            called.append(True)
            raise ValueError("Key %r not found" % key)
        cache.incr.side_effect = _incr

        self.assertEqual(wrapper._next_generation("BucketName"), 2)