コード例 #1
0
 def testClearUnknownUser(self):
     """
     L{RecentUserActivityCache.clear} is a no-op if no data exists for the
     specified L{User}.
     """
     cache = RecentObjectActivityCache()
     cache.clear([u'username'])
     result = cache.get(u'username')
     self.assertEqual({}, result.results)
     self.assertEqual([u'username'], result.uncachedValues)
コード例 #2
0
 def testClearUnknownUser(self):
     """
     L{RecentUserActivityCache.clear} is a no-op if no data exists for the
     specified L{User}.
     """
     cache = RecentObjectActivityCache()
     cache.clear([u'username'])
     result = cache.get(u'username')
     self.assertEqual({}, result.results)
     self.assertEqual([u'username'], result.uncachedValues)
コード例 #3
0
 def testClearUnknownObjectID(self):
     """
     L{RecentObjectActivityCache.clear} is a no-op if no data exists for
     the specified object ID.
     """
     objectID = uuid4()
     cache = RecentObjectActivityCache()
     cache.clear([objectID])
     result = cache.get(objectID)
     self.assertEqual({}, result.results)
     self.assertEqual([objectID], result.uncachedValues)
コード例 #4
0
 def testClearUnknownObjectID(self):
     """
     L{RecentObjectActivityCache.clear} is a no-op if no data exists for
     the specified object ID.
     """
     objectID = uuid4()
     cache = RecentObjectActivityCache()
     cache.clear([objectID])
     result = cache.get(objectID)
     self.assertEqual({}, result.results)
     self.assertEqual([objectID], result.uncachedValues)
コード例 #5
0
ファイル: test_value.py プロジェクト: xanixon/fluiddb
 def testDeleteInvalidatesRecentObjectActivity(self):
     """
     L{CachingTagValueAPI.delete} invalidates cache recent activity for the
     object IDs that have been modified.
     """
     objectID = uuid4()
     CachingTagAPI(self.user).create([(u'username/tag', u'A tag')])
     cache = RecentObjectActivityCache()
     cache.save(objectID, [(u'username/tag', objectID, u'about-value',
                            u'tag-value', u'username', datetime.utcnow())])
     self.tagValues.delete([(objectID, u'username/tag')])
     result = cache.get(objectID)
     self.assertEqual({}, result.results)
     self.assertEqual([objectID], result.uncachedValues)
コード例 #6
0
 def testGetReturnsUncachedValues(self):
     """
     L{RecentObjectActivityCache.get} returns values not found in the cache
     in the C{uncachedValues} field of the L{CacheResult} object.
     """
     objectID = uuid4()
     result = RecentObjectActivityCache().get(objectID)
     self.assertEqual([objectID], result.uncachedValues)
     self.assertEqual({}, result.results)
コード例 #7
0
 def delete(self, values):
     """See L{TagValueAPI.delete}."""
     if isgenerator(values):
         values = list(values)
     result = self._api.delete(values)
     objectIDs = [objectID for objectID, path in values]
     RecentObjectActivityCache().clear(objectIDs)
     RecentUserActivityCache().clear([self._user.username])
     return result
コード例 #8
0
 def testSaveSetsExpirationTimeout(self):
     """
     L{RecentObjectActivityCache.save} stores a result in the cache with
     the configured expiration timeout.
     """
     objectID = uuid4()
     RecentObjectActivityCache().save(
         objectID, [(u'user/tag', objectID, u'about-value', u'tag-value',
                     u'user', datetime.utcnow())])
     expectedTimeout = self.config.getint('cache', 'expire-timeout')
     ttl = self.cache.ttl('recentactivity:object:' + str(objectID))
     self.assertNotIdentical(None, ttl)
     self.assertAlmostEqual(expectedTimeout, ttl)
コード例 #9
0
ファイル: test_tag.py プロジェクト: xanixon/fluiddb
 def testDeleteInvalidatesCachedRecentObjectActivity(self):
     """
     L{CachingTagAPI.delete} invalidates recent activity for objects that
     had a L{TagValue} associated with the removed L{Tag}.
     """
     objectID = uuid4()
     self.tags.create([(u'username/tag', u'A tag')])
     CachingTagValueAPI(self.user).set({objectID: {u'username/tag': 42}})
     CachingRecentActivityAPI().getForObjects([objectID])
     self.tags.delete([u'username/tag'])
     result = RecentObjectActivityCache().get(objectID)
     self.assertEqual({}, result.results)
     self.assertEqual([objectID], result.uncachedValues)
コード例 #10
0
 def testClear(self):
     """
     L{RecentUserActivityCache.clear} removes the cached recent activity
     for the specified L{User}.
     """
     cache = RecentObjectActivityCache()
     cache.save(u'user', [(u'user/tag', u'user', u'about-value',
                           u'tag-value', u'user', datetime.utcnow())])
     cache.clear([u'user'])
     result = cache.get(u'user')
     self.assertEqual({}, result.results)
     self.assertEqual([u'user'], result.uncachedValues)
コード例 #11
0
 def testSaveStoresRecentActivityInTheCache(self):
     """
     L{RecentObjectActivityCache.save} stores recent activity in the cache.
     """
     now = datetime.utcnow()
     objectID = uuid4()
     RecentObjectActivityCache().save(objectID, [
         (u'user/tag', objectID, u'about-value', u'tag-value', u'user', now)
     ])
     self.assertEqual([[
         u'user/tag',
         str(objectID), u'about-value', u'tag-value', u'user',
         now.isoformat()
     ]], loads(self.cache.get('recentactivity:object:' + str(objectID))))
コード例 #12
0
 def testClear(self):
     """
     L{RecentObjectActivityCache.clear} removes the cached recent activity
     for the specified object ID.
     """
     objectID = uuid4()
     cache = RecentObjectActivityCache()
     cache.save(objectID, [(u'user/tag', objectID, u'about-value',
                            u'tag-value', u'user', datetime.utcnow())])
     cache.clear([objectID])
     result = cache.get(objectID)
     self.assertEqual({}, result.results)
     self.assertEqual([objectID], result.uncachedValues)
コード例 #13
0
ファイル: tag.py プロジェクト: xanixon/fluiddb
    def delete(self, paths):
        """See L{TagAPI.delete}.

        Permissions for deleted L{Tag}s are removed from the cache.
        """
        if isgenerator(paths):
            paths = list(paths)
        # FIXME getObjectIDs is called twice--once here and once in
        # TagAPI.delete.  It would be better if we only did this once, not to
        # mention that this breaks encapsulation by bypassing the model layer
        # and accessing the data layer directly. -jkakar
        objectIDs = set(getObjectIDs(paths))
        RecentObjectActivityCache().clear(objectIDs)
        usernames = set([path.split('/')[0] for path in paths])
        RecentUserActivityCache().clear(usernames)
        PermissionCache().clearTagPermissions(paths)
        return self._api.delete(paths)
コード例 #14
0
 def testClear(self):
     """
     L{RecentUserActivityCache.clear} removes the cached recent activity
     for the specified L{User}.
     """
     cache = RecentObjectActivityCache()
     cache.save(u'user', [(u'user/tag', u'user', u'about-value',
                           u'tag-value', u'user', datetime.utcnow())])
     cache.clear([u'user'])
     result = cache.get(u'user')
     self.assertEqual({}, result.results)
     self.assertEqual([u'user'], result.uncachedValues)
コード例 #15
0
 def testClear(self):
     """
     L{RecentObjectActivityCache.clear} removes the cached recent activity
     for the specified object ID.
     """
     objectID = uuid4()
     cache = RecentObjectActivityCache()
     cache.save(objectID, [(u'user/tag', objectID, u'about-value',
                            u'tag-value', u'user', datetime.utcnow())])
     cache.clear([objectID])
     result = cache.get(objectID)
     self.assertEqual({}, result.results)
     self.assertEqual([objectID], result.uncachedValues)
コード例 #16
0
    def testGetReturnsRecentActivityFromCache(self):
        """
        L{RecentObjectActivityCache.get} returns the recent activity saved in
        the cache.
        """
        now = datetime.utcnow()
        objectID = uuid4()
        activity = [(u'user/tag', str(objectID), u'about-value', u'tag-value',
                     u'user', now.isoformat())]
        self.cache.set(u'recentactivity:object:' + str(objectID),
                       dumps(activity))

        result = RecentObjectActivityCache().get(objectID)
        self.assertEqual(
            {
                objectID: [(u'user/tag', objectID, u'about-value',
                            u'tag-value', u'user', now)]
            }, result.results)
        self.assertEqual([], result.uncachedValues)
コード例 #17
0
 def set(self, values):
     """See L{TagValueAPI.set}."""
     result = self._api.set(values)
     RecentObjectActivityCache().clear(values.keys())
     RecentUserActivityCache().clear([self._user.username])
     return result