mò Sã¸Ec@s‚dZdklZdklZdkZdklZdefd„ƒYZdefd„ƒYZ d fd „ƒYZ d „Z dS( s.Test behavior of Connection plus cPickleCache.(sdoctest(s PersistentN(sdatabaseFromStringtRecalcitrantObjectcBs2tZdZdZd„Zd„ZeeƒZRS(s1A Persistent object that will not become a ghost.icCs|iid7_dS(Ni(tselft __class__t deactivations(R((t4/data/zmath/zope/lib/python/ZODB/tests/test_cache.pyt _p_deactivatescCs d|_dS(Ni(tclsR(R((Rtinits(t__name__t __module__t__doc__RRRt classmethod(((RRs   t RegularObjectcBs;tZdZdZd„Zd„Zd„ZeeƒZRS(NicCs)|iid7_tt|ƒiƒdS(Ni(RRRtsuperR R(R((RR(scCs)|iid7_tt|ƒiƒdS(Ni(RRt invalidationsR R t _p_invalidate(R((RR,scCsd|_d|_dS(Ni(RRR(R((RR0s (RR RRRRRR (((RR #s    t CacheTestscBs#tZd„Zd„Zd„ZRS(NcCsdS(sÉTest basic cache methods. Let's start with a clean transaction >>> transaction.abort() >>> RegularObject.init() >>> db = databaseFromString("\n" ... "cache-size 4\n" ... "\n" ... "") >>> cn = db.open() >>> r = cn.root() >>> L = [] >>> for i in range(5): ... o = RegularObject() ... L.append(o) ... r[i] = o >>> transaction.commit() After committing a transaction and calling cacheGC(), there should be cache-size (4) objects in the cache. One of the RegularObjects was deactivated. >>> cn._cache.ringlen() 4 >>> RegularObject.deactivations 1 If we explicitly activate the objects again, the ringlen should go back up to 5. >>> for o in L: ... o._p_activate() >>> cn._cache.ringlen() 5 >>> cn.cacheGC() >>> cn._cache.ringlen() 4 >>> RegularObject.deactivations 2 >>> cn.cacheMinimize() >>> cn._cache.ringlen() 0 >>> RegularObject.deactivations 6 If we activate all the objects again and mark one as modified, then the one object should not be deactivated even by a minimize. >>> for o in L: ... o._p_activate() >>> o.attr = 1 >>> cn._cache.ringlen() 5 >>> cn.cacheMinimize() >>> cn._cache.ringlen() 1 >>> RegularObject.deactivations 10 Clean up >>> transaction.abort() N((R((Rt test_cache8sEcCsdS(sÍTest that a cacheGC() call will return. It's possible for a particular object to ignore the _p_deactivate() call. We want to check several things in this case. The cache should called the real _p_deactivate() method not the one provided by Persistent. The cacheGC() call should also return when it's looked at each item, regardless of whether it became a ghost. >>> RecalcitrantObject.init() >>> db = databaseFromString("\n" ... "cache-size 4\n" ... "\n" ... "") >>> cn = db.open() >>> r = cn.root() >>> L = [] >>> for i in range(5): ... o = RecalcitrantObject() ... L.append(o) ... r[i] = o >>> transaction.commit() >>> [o._p_state for o in L] [0, 0, 0, 0, 0] The Connection calls cacheGC() after it commits a transaction. Since the cache will now have more objects that it's target size, it will call _p_deactivate() on each RecalcitrantObject. >>> RecalcitrantObject.deactivations 5 >>> [o._p_state for o in L] [0, 0, 0, 0, 0] An explicit call to cacheGC() has the same effect. >>> cn.cacheGC() >>> RecalcitrantObject.deactivations 10 >>> [o._p_state for o in L] [0, 0, 0, 0, 0] N((R((Rttest_cache_gc_recalcitrants*cCsdS(sãTest that the cache handles transaction abort correctly. >>> RegularObject.init() >>> db = databaseFromString("\n" ... "cache-size 4\n" ... "\n" ... "") >>> cn = db.open() >>> r = cn.root() >>> L = [] >>> for i in range(5): ... o = RegularObject() ... L.append(o) ... r[i] = o >>> transaction.commit() >>> RegularObject.deactivations 1 Modify three of the objects and verify that they are deactivated when the transaction aborts. >>> for i in range(0, 5, 2): ... L[i].attr = i >>> [L[i]._p_state for i in range(0, 5, 2)] [1, 1, 1] >>> cn._cache.ringlen() 5 >>> transaction.abort() >>> cn._cache.ringlen() 2 >>> RegularObject.deactivations 4 N((R((Rttest_cache_on_abort«s"(RR RRR(((RR6s G ,cCs tiƒS(N(tdoctestt DocTestSuite(((Rt test_suiteÐs( R t zope.testingRt persistentt Persistentt transactiont ZODB.configtdatabaseFromStringRR RR(RR RRRRRR((Rt?s     š