[ZODB-Dev] ZODB4 and DemoStorage
Barry Warsaw
barry@zope.com
08 Apr 2003 10:37:44 -0400
On Tue, 2003-04-08 at 06:10, Marius Gedminas wrote:
> I'm trying to build a functional testing framework based on DemoStorage.
> The docstring in demo.py suggests this is an intended use case:
Yes. The other use case is fronting a read-only storage, say on a
CDROM.
> Here's how I am trying to do it:
>
> from zodb.db import DB
> from zodb.storage.mapping import MappingStorage
> from zodb.storage.demo import DemoStorage
>
> base_storage = MappingStorage("Base")
> # maybe MemoryFullStorage would be a better choice?
MappingStorage is more like a MemoryMinimalStorage; neither supports
undo or versions. MemoryFullStorage as its name implies, supports the
full storage interface.
> db = DB(base_storage)
> ... bootstrap the DB (create root folder and essential services) ...
> db.close()
>
> ... and for each functional test case do:
>
> demo_storage = DemoStorage("Demo", base_storage)
> db = DB(demo_storage)
> ... do things with db ...
> db.close()
>
> I have some reservations about it. Closing the DB also closes the
> storage,
Looking at the code, that's all db.close() does!
> and I am not sure you just pass the same storage to a new DB
> instance as if nothing had happened.
Well, what if you just threw away the DB object without closing it? I'm
not 100% sure this is kosher, but it would be interesting to try. :)
> BTW there's a bug in DemoStorage: newObjectId() returns oids that are
> already in use by self._back. DemoStorage.__init__ should set self._oid
> to the last oid used by self._back. I haven't found a public interface
> method to do that (calling self._back.newObjectId() won't work if
> self._back is read-only), so I think IStorage needs a new method,
> lastObjectId().
Probably so. It can't call newObjectId() on the backing storage because
that method will raise an exception on a read-only storage.
I'll add a unit test for this case. Please let me know if you find any
other problems with either the memory storages or demo storage. There's
a definite dearth of tests for the demo storage.
-Barry