[Zodb-checkins] CVS: ZODB3/bsddb3Storage/bsddb3Storage/tests - test_whitebox.py:1.1.2.1

Barry Warsaw barry@wooz.org
Tue, 10 Sep 2002 16:57:14 -0400


Update of /cvs-repository/ZODB3/bsddb3Storage/bsddb3Storage/tests
In directory cvs.zope.org:/tmp/cvs-serv12800/bsddb3Storage/bsddb3Storage/tests

Added Files:
      Tag: bdb-nolocks
	test_whitebox.py 
Log Message:
White box tests for various Berkeley based storages.


=== Added File ZODB3/bsddb3Storage/bsddb3Storage/tests/test_whitebox.py ===
##############################################################################
#
# Copyright (c) 2001, 2002 Zope Corporation and Contributors.
# All Rights Reserved.
#
# This software is subject to the provisions of the Zope Public License,
# Version 2.0 (ZPL).  A copy of the ZPL should accompany this distribution.
# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
# FOR A PARTICULAR PURPOSE
#
##############################################################################

# Whitebox testing of storage implementation details.

import unittest

from ZODB.utils import U64
from ZODB.tests.StorageTestBase import zodb_unpickle
from bsddb3Storage.Minimal import Minimal
from bsddb3Storage.tests.BerkeleyTestBase import BerkeleyTestBase



class WhiteboxMinimal(BerkeleyTestBase):
    ConcreteStorage = Minimal

    def checkTableConsistencyAfterCommit(self):
        unless = self.failIf
        eq = self.assertEqual
        oid = self._storage.new_oid()
        revid1 = self._dostore(oid, data=11)
        revid2 = self._dostore(oid, revid=revid1, data=12)
        revid3 = self._dostore(oid, revid=revid2, data=13)
        # First off, there should be no entries in the pending table
        unless(self._storage._pending.keys())
        # Also, there should be no entries in the oids table
        unless(self._storage._oids.keys())
        # Now, there should be exactly one oid in the serials table, and
        # exactly one record for that oid in the table too.
        oids = {}
        c = self._storage._serials.cursor()
        try:
            rec = c.first()
            while rec:
                oid, serial = rec
                oids.setdefault(oid, []).append(serial)
                rec = c.next()
        finally:
            c.close()
        eq(len(oids), 1)
        eq(len(oids[oids.keys()[0]]), 1)
        # Same deal for the pickles table.  There should be only one entry in
        # this table, and the oid + serial should be consistent with what's in
        # the serials table.
        pickles = {}
        c = self._storage._pickles.cursor()
        try:
            rec = c.first()
            while rec:
                key, pickle = rec
                oid = key[:8]
                serial = key[8:]
                pickles.setdefault(oid, []).append((serial, pickle))
                rec = c.next()
        finally:
            c.close()
        eq(len(pickles), 1)
        eq(len(pickles[pickles.keys()[0]]), 1)
        eq(oids.keys()[0], pickles.keys()[0])
        eq(oids[oids.keys()[0]][0], pickles[pickles.keys()[0]][0][0])
        obj = zodb_unpickle(pickles[pickles.keys()[0]][0][1])
        eq(obj.value, 13)
        # Now verify the refcounts table, which should be empty because the
        # stored object isn't referenced by any other objects.
        eq(len(self._storage._refcounts.keys()), 0)



def test_suite():
    suite = unittest.TestSuite()
    suite.addTest(unittest.makeSuite(WhiteboxMinimal, 'check'))
    return suite



if __name__ == '__main__':
    unittest.main(defaultTest='test_suite')