Commit aa195678 authored by Jeremy Hylton's avatar Jeremy Hylton

Merge changes from Zope-2_7-branch to the trunk.

parent b765fc5a
...@@ -207,13 +207,6 @@ then this command will install the new ZEO and ZODB: ...@@ -207,13 +207,6 @@ then this command will install the new ZEO and ZODB:
The install command should create a /home/zope/lib/python/ZEO directoy. The install command should create a /home/zope/lib/python/ZEO directoy.
Simple configuration
--------------------
mkzeoinst.py
Or, do it step-by-step.
Configuring server Configuring server
------------------ ------------------
...@@ -407,13 +400,9 @@ Running the ZEO server as a daemon ...@@ -407,13 +400,9 @@ Running the ZEO server as a daemon
In an operational setting, you will want to run the ZEO server a In an operational setting, you will want to run the ZEO server a
daemon process that is restarted when it dies. The zdaemon package daemon process that is restarted when it dies. The zdaemon package
provides two tools for running daemons: zdrun.py and zdctl.py. provides two tools for running daemons: zdrun.py and zdctl.py. The
The document "Using zdctl and zdrun to manage server processes" document "Using zdctl and zdrun to manage server processes"
explains how to use these scripts to manage daemons. (Doc/zdctl.txt) explains how to use these scripts to manage daemons.
XXX example of how to use zdrun
XXX mkzeoinst.py docs should probably go here
Rotating log files Rotating log files
~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~~~
...@@ -437,10 +426,6 @@ manages a ZEO servers password database. ...@@ -437,10 +426,6 @@ manages a ZEO servers password database.
Diagnosing problems Diagnosing problems
------------------- -------------------
How to use the debug logs.
Common gotchas.
If an exception occurs on the server, the server will log a traceback If an exception occurs on the server, the server will log a traceback
and send an exception to the client. The traceback on the client will and send an exception to the client. The traceback on the client will
show a ZEO protocol library as the source of the error. If you need show a ZEO protocol library as the source of the error. If you need
......
Client Cache Tracing ZEO Client Cache Tracing
==================== ========================
An important question for ZEO users is: how large should the ZEO An important question for ZEO users is: how large should the ZEO
client cache be? ZEO 2 (as of ZEO 2.0b2) has a new feature that lets client cache be? ZEO 2 (as of ZEO 2.0b2) has a new feature that lets
......
...@@ -16,8 +16,8 @@ class ChatSession(Persistent): ...@@ -16,8 +16,8 @@ class ChatSession(Persistent):
add_message(message) -- add a message to the channel add_message(message) -- add a message to the channel
new_messages() -- return new messages since the last call to new_messages() -- return new messages since the last call to
this method this method
""" """
def __init__(self, name): def __init__(self, name):
...@@ -27,15 +27,15 @@ class ChatSession(Persistent): ...@@ -27,15 +27,15 @@ class ChatSession(Persistent):
self.name = name self.name = name
# Internal attribute: _messages holds all the chat messages. # Internal attribute: _messages holds all the chat messages.
self._messages = BTree.BTree() self._messages = BTree.BTree()
def new_messages(self): def new_messages(self):
"Return new messages." "Return new messages."
# self._v_last_time is the time of the most recent message # self._v_last_time is the time of the most recent message
# returned to the user of this class. # returned to the user of this class.
if not hasattr(self, '_v_last_time'): if not hasattr(self, '_v_last_time'):
self._v_last_time = 0 self._v_last_time = 0
...@@ -48,7 +48,7 @@ class ChatSession(Persistent): ...@@ -48,7 +48,7 @@ class ChatSession(Persistent):
self._v_last_time = T2 self._v_last_time = T2
return new return new
def add_message(self, message): def add_message(self, message):
"""Add a message to the channel. """Add a message to the channel.
message -- text of the message to be added message -- text of the message to be added
...@@ -82,7 +82,7 @@ def get_chat_session(conn, channelname): ...@@ -82,7 +82,7 @@ def get_chat_session(conn, channelname):
print 'Creating chat_sessions B-tree' print 'Creating chat_sessions B-tree'
root['chat_sessions'] = BTree.BTree() root['chat_sessions'] = BTree.BTree()
get_transaction().commit() get_transaction().commit()
sessions = root['chat_sessions'] sessions = root['chat_sessions']
# Get a session object corresponding to the channel name, creating # Get a session object corresponding to the channel name, creating
...@@ -94,7 +94,7 @@ def get_chat_session(conn, channelname): ...@@ -94,7 +94,7 @@ def get_chat_session(conn, channelname):
session = sessions[ channelname ] session = sessions[ channelname ]
return session return session
if __name__ == '__main__': if __name__ == '__main__':
if len(sys.argv) != 2: if len(sys.argv) != 2:
...@@ -119,6 +119,5 @@ if __name__ == '__main__': ...@@ -119,6 +119,5 @@ if __name__ == '__main__':
print msg print msg
# Wait for a few seconds # Wait for a few seconds
pause = random.randint( 1, 4 ) pause = random.randint( 1, 4 )
time.sleep( pause ) time.sleep( pause )
...@@ -25,7 +25,4 @@ and less in others. ...@@ -25,7 +25,4 @@ and less in others.
\\ \\
\url{http://www.zope.org/Members/bwarsaw/ipc10-slides} \url{http://www.zope.org/Members/bwarsaw/ipc10-slides}
Download link for ZEO: \\
\url{http://www.zope.org/Products/ZEO/}
...@@ -9,36 +9,28 @@ ...@@ -9,36 +9,28 @@
\subsection{Installing ZODB} \subsection{Installing ZODB}
The ZODB forms part of Zope, but it's difficult and somewhat painful ZODB is packaged using the standard distutils tools.
to extract the bits from Zope needed to support just the ZODB.
Therefore I've assembled a distribution containing only the packages
required to use the ZODB and ZEO, so you can install it and start
programming right away.
To download the distribution, go to my ZODB page at
\url{http://www.amk.ca/zodb/}.
The distribution is still experimental, so don't be surprised if the
installation process runs into problems. Please inform me of any
difficulties you encounter.
\subsubsection{Requirements} \subsubsection{Requirements}
You will need Python 2.1 or higher. The code is packaged using You will need Python 2.2 or higher. Since the code is packaged using
Distutils. So it is simply a matter of untarring or unzipping the distutils, it is simply a matter of untarring or unzipping the release
release package, and then running \code{python setup.py install}. package, and then running \code{python setup.py install}.
You'll need a C compiler to build the packages, because there are You'll need a C compiler to build the packages, because there are
various C extension modules. At the moment no one is making Windows various C extension modules. Binary installers are provided for
binaries available, so you'll need a Windows development environment Windows users.
to build ZODB.
\subsubsection{Installing the Packages} \subsubsection{Installing the Packages}
Download the ZODB tarball containing all the packages for both ZODB Download the ZODB tarball containing all the packages for both ZODB
and ZEO from \url{http://www.zope.org/Products/StandaloneZODB}. See and ZEO from \url{http://www.zope.org/Products/ZODB3.2}. See
the \file{README.txt} file in the top level of the release directory the \file{README.txt} file in the top level of the release directory
for details on building, testing, and installing. for details on building, testing, and installing.
You can find information about ZODB and the most current releases in
the ZODB Wiki at \url{http://www.zope.org/Wikis/ZODB}.
\subsection{How ZODB Works} \subsection{How ZODB Works}
The ZODB is conceptually simple. Python classes subclass a The ZODB is conceptually simple. Python classes subclass a
...@@ -59,8 +51,10 @@ don't get corrupted by software or hardware crashes, and most database ...@@ -59,8 +51,10 @@ don't get corrupted by software or hardware crashes, and most database
software offers protection against such corruption by supporting four software offers protection against such corruption by supporting four
useful properties, Atomicity, Consistency, Isolation, and Durability. useful properties, Atomicity, Consistency, Isolation, and Durability.
In computer science jargon these four terms are collectively dubbed In computer science jargon these four terms are collectively dubbed
the ACID properties, forming an acronym from their names. The the ACID properties, forming an acronym from their names.
definitions of the ACID properties are:
The ZODB provides all of the ACID properties. Definitions of the
ACID properties are:
\begin{itemize} \begin{itemize}
...@@ -73,18 +67,13 @@ forgotten. That's bad, but it's better than having a ...@@ -73,18 +67,13 @@ forgotten. That's bad, but it's better than having a
partially-applied modification put the database into an inconsistent partially-applied modification put the database into an inconsistent
state. state.
\item[Consistency] means that the data cannot be placed into a \item[Consistency] means that each transaction executes a valid
logically invalid state; sanity checks can be written and enforced. transformation of the database state. Some databases, but not ZODB,
Usually this is done by defining a database schema, and requiring provide a variety of consistency checks in the database or language;
the data always matches the schema. There are two typical for example, a relational database constraint columns to be of
approaches to consistency. One is to enforce rules about the types particular types and can enforce relations across tables. Viewed more
of objects and attribute; for example, enforce that the generally, atomicity and isolation make it possible for applications
\code{order_number} attribute is always an integer, and not a to provide consistency.
string, tuple, or other object. Another is to guarantee consistency
across data structures; for example, that any object with an
\code{order_number} attribute must also appear in the
\code{orders_table} object. In general, atomicity and isolation make
it possible for applications to provide consistency.
\item[Isolation] means that two programs or threads running in two \item[Isolation] means that two programs or threads running in two
different transactions cannot see each other's changes until they different transactions cannot see each other's changes until they
...@@ -95,10 +84,6 @@ a subsequent crash will not cause any data to be lost or corrupted. ...@@ -95,10 +84,6 @@ a subsequent crash will not cause any data to be lost or corrupted.
\end{itemize} \end{itemize}
The ZODB provides 3 of the ACID properties. Only Consistency is not
supported; the ZODB has no notion of a database schema, and therefore
has no way of enforcing consistency with a schema.
\subsection{Opening a ZODB} \subsection{Opening a ZODB}
There are 3 main interfaces supplied by the ZODB: There are 3 main interfaces supplied by the ZODB:
...@@ -132,9 +117,9 @@ implement the \class{Storage} interface. ...@@ -132,9 +117,9 @@ implement the \class{Storage} interface.
\end{itemize} \end{itemize}
Preparing to use a ZODB requires 3 steps: you have to open the Preparing to use a ZODB requires 3 steps: you have to open the
\class{Storage}, then create a \class{DB} instance that uses the \class{Storage}, and then get \class{Storage}, then create a \class{DB} instance that uses the
a \class{Connection} from the \class{DB instance}. All this is only a few lines of \class{Storage}, and then get a \class{Connection} from the \class{DB
code: instance}. All this is only a few lines of code:
\begin{verbatim} \begin{verbatim}
from ZODB import FileStorage, DB from ZODB import FileStorage, DB
...@@ -189,7 +174,7 @@ retrieving a \class{User} object given the user's ID. First, we ...@@ -189,7 +174,7 @@ retrieving a \class{User} object given the user's ID. First, we
retrieve the primary root object of the ZODB using the \method{root()} retrieve the primary root object of the ZODB using the \method{root()}
method of the \class{Connection} instance. The root object behaves method of the \class{Connection} instance. The root object behaves
like a Python dictionary, so you can just add a new key/value pair for like a Python dictionary, so you can just add a new key/value pair for
your application's root object. We'll insert a \class{BTree} object your application's root object. We'll insert an \class{OOBTree} object
that will contain all the \class{User} objects. (The that will contain all the \class{User} objects. (The
\class{BTree} module is also included as part of Zope.) \class{BTree} module is also included as part of Zope.)
...@@ -199,8 +184,8 @@ dbroot = conn.root() ...@@ -199,8 +184,8 @@ dbroot = conn.root()
# Ensure that a 'userdb' key is present # Ensure that a 'userdb' key is present
# in the root # in the root
if not dbroot.has_key('userdb'): if not dbroot.has_key('userdb'):
import BTree from BTrees.OOBTree import OOBTree
dbroot['userdb'] = BTree.BTree() dbroot['userdb'] = OOBTree()
userdb = dbroot['userdb'] userdb = dbroot['userdb']
\end{verbatim} \end{verbatim}
...@@ -426,13 +411,11 @@ different class instances, then there's no longer any easy way to find ...@@ -426,13 +411,11 @@ different class instances, then there's no longer any easy way to find
them all, short of writing a generalized object traversal function them all, short of writing a generalized object traversal function
that would walk over every single object in a ZODB, checking each one that would walk over every single object in a ZODB, checking each one
to see if it's an instance of \class{User}. to see if it's an instance of \class{User}.
\footnote{XXX is there a convenience method for walking the object graph hiding
somewhere inside DC's code? Should there be a utility method for
doing this? Should I write one and include it in this section?}
Some OODBs support a feature called extents, which allow quickly Some OODBs support a feature called extents, which allow quickly
finding all the instances of a given class, no matter where they are finding all the instances of a given class, no matter where they are
in the object graph; unfortunately the ZODB doesn't offer extents as a in the object graph; unfortunately the ZODB doesn't offer extents as a
feature. feature.
XXX Rest of section not written yet: __getstate__/__setstate__ % XXX Rest of section not written yet: __getstate__/__setstate__
\documentclass{howto} \documentclass{howto}
\title{ZODB/ZEO Programming Guide} \title{ZODB/ZEO Programming Guide}
\release{0.1} \release{0.2}
\date{\today} \date{\today}
\author{A.M.\ Kuchling} \author{A.M.\ Kuchling}
...@@ -23,9 +23,6 @@ ...@@ -23,9 +23,6 @@
\input{prog-zodb} \input{prog-zodb}
\input{zeo} \input{zeo}
\input{transactions} \input{transactions}
%\input{storages}
%\input{indexing}
%\input{admin}
\input{modules} \input{modules}
\appendix \appendix
......
...@@ -33,7 +33,7 @@ class Base: ...@@ -33,7 +33,7 @@ class Base:
""" Tests common to all types: sets, buckets, and BTrees """ """ Tests common to all types: sets, buckets, and BTrees """
db = None db = None
def tearDown(self): def tearDown(self):
self.t = None self.t = None
del self.t del self.t
......
...@@ -25,7 +25,7 @@ register_loop_callback() to register interest. When the mainloop ...@@ -25,7 +25,7 @@ register_loop_callback() to register interest. When the mainloop
thread calls loop(), each registered callback will be called with the thread calls loop(), each registered callback will be called with the
socket map as its first argument. socket map as its first argument.
""" """
__version__ = '$Revision: 1.8 $'[11:-2] __version__ = '$Revision: 1.9 $'[11:-2]
import asyncore import asyncore
import select import select
...@@ -57,7 +57,17 @@ def register_loop_callback(callback, args=(), kw=None): ...@@ -57,7 +57,17 @@ def register_loop_callback(callback, args=(), kw=None):
_loop_callbacks.append((callback, args, kw)) _loop_callbacks.append((callback, args, kw))
finally: finally:
_loop_lock.release() _loop_lock.release()
def remove_loop_callback(callback):
"""Remove a callback function registered earlier.
This is useful if loop() was never called.
"""
for i in range(len(_loop_callbacks)):
if _loop_callbacks[i][0] == callback:
del _loop_callbacks[i]
return
def _start_loop(map): def _start_loop(map):
_loop_lock.acquire() _loop_lock.acquire()
try: try:
......
...@@ -13,7 +13,7 @@ ...@@ -13,7 +13,7 @@
############################################################################## ##############################################################################
"""Manage the asyncore mainloop in a multi-threaded app. """Manage the asyncore mainloop in a multi-threaded app.
$Id: __init__.py,v 1.6 2003/02/25 15:17:09 fdrake Exp $ $Id: __init__.py,v 1.7 2003/10/02 18:17:26 jeremy Exp $
""" """
from LoopCallback import register_loop_callback, loop from LoopCallback import register_loop_callback, loop, remove_loop_callback
...@@ -99,7 +99,7 @@ class ClientStorage(object): ...@@ -99,7 +99,7 @@ class ClientStorage(object):
name='', client=None, debug=0, var=None, name='', client=None, debug=0, var=None,
min_disconnect_poll=5, max_disconnect_poll=300, min_disconnect_poll=5, max_disconnect_poll=300,
wait_for_server_on_startup=None, # deprecated alias for wait wait_for_server_on_startup=None, # deprecated alias for wait
wait=None, # defaults to 1 wait=None, wait_timeout=None,
read_only=0, read_only_fallback=0, read_only=0, read_only_fallback=0,
username='', password='', realm=None): username='', password='', realm=None):
"""ClientStorage constructor. """ClientStorage constructor.
...@@ -152,6 +152,9 @@ class ClientStorage(object): ...@@ -152,6 +152,9 @@ class ClientStorage(object):
wait -- A flag indicating whether to wait until a connection wait -- A flag indicating whether to wait until a connection
with a server is made, defaulting to true. with a server is made, defaulting to true.
wait_timeout -- Maximum time to wait for a connection before
giving up. Only meaningful if wait is True.
read_only -- A flag indicating whether this should be a read_only -- A flag indicating whether this should be a
read-only storage, defaulting to false (i.e. writing is read-only storage, defaulting to false (i.e. writing is
allowed by default). allowed by default).
...@@ -302,7 +305,7 @@ class ClientStorage(object): ...@@ -302,7 +305,7 @@ class ClientStorage(object):
tmax=max_disconnect_poll) tmax=max_disconnect_poll)
if wait: if wait:
self._wait() self._wait(wait_timeout)
else: else:
# attempt_connect() will make an attempt that doesn't block # attempt_connect() will make an attempt that doesn't block
# "too long," for a very vague notion of too long. If that # "too long," for a very vague notion of too long. If that
...@@ -313,7 +316,9 @@ class ClientStorage(object): ...@@ -313,7 +316,9 @@ class ClientStorage(object):
if not self._ready.isSet(): if not self._ready.isSet():
self._cache.open() self._cache.open()
def _wait(self): def _wait(self, timeout=None):
if timeout is not None:
deadline = time.time() + timeout
# Wait for a connection to be established. # Wait for a connection to be established.
self._rpc_mgr.connect(sync=1) self._rpc_mgr.connect(sync=1)
# When a synchronous connect() call returns, there is # When a synchronous connect() call returns, there is
...@@ -326,6 +331,9 @@ class ClientStorage(object): ...@@ -326,6 +331,9 @@ class ClientStorage(object):
self._ready.wait(30) self._ready.wait(30)
if self._ready.isSet(): if self._ready.isSet():
break break
if timeout and time.time() > deadline:
log2(PROBLEM, "Timed out waiting for connection")
break
log2(INFO, "Waiting for cache verification to finish") log2(INFO, "Waiting for cache verification to finish")
else: else:
self._wait_sync() self._wait_sync()
...@@ -434,8 +442,10 @@ class ClientStorage(object): ...@@ -434,8 +442,10 @@ class ClientStorage(object):
auth = stub.getAuthProtocol() auth = stub.getAuthProtocol()
log2(INFO, "Server authentication protocol %r" % auth) log2(INFO, "Server authentication protocol %r" % auth)
if auth: if auth:
if self.doAuth(auth, stub): skey = self.doAuth(auth, stub)
if skey:
log2(INFO, "Client authentication successful") log2(INFO, "Client authentication successful")
conn.setSessionKey(skey)
else: else:
log2(ERROR, "Authentication failed") log2(ERROR, "Authentication failed")
raise AuthError, "Authentication failed" raise AuthError, "Authentication failed"
......
...@@ -42,3 +42,8 @@ class CommitLog: ...@@ -42,3 +42,8 @@ class CommitLog:
self.read = 1 self.read = 1
self.file.seek(0) self.file.seek(0)
return self.stores, cPickle.Unpickler(self.file) return self.stores, cPickle.Unpickler(self.file)
def close(self):
if self.file:
self.file.close()
self.file = None
...@@ -28,7 +28,7 @@ DATA = 3 ...@@ -28,7 +28,7 @@ DATA = 3
ERROR = 4 ERROR = 4
class DebugManagedServerConnection(ManagedServerConnection): class DebugManagedServerConnection(ManagedServerConnection):
def __init__(self, sock, addr, obj, mgr): def __init__(self, sock, addr, obj, mgr):
# mgr is the DebugServer instance # mgr is the DebugServer instance
self.mgr = mgr self.mgr = mgr
...@@ -67,7 +67,7 @@ class DebugServer(StorageServer): ...@@ -67,7 +67,7 @@ class DebugServer(StorageServer):
ZEOStorageClass = DebugZEOStorage ZEOStorageClass = DebugZEOStorage
ManagedServerConnectionClass = DebugManagerConnection ManagedServerConnectionClass = DebugManagerConnection
def __init__(self, *args, **kwargs): def __init__(self, *args, **kwargs):
StorageServer.__init__(*args, **kwargs) StorageServer.__init__(*args, **kwargs)
self._setup_record(kwargs["record"]) self._setup_record(kwargs["record"])
......
...@@ -32,9 +32,13 @@ class StorageServer: ...@@ -32,9 +32,13 @@ class StorageServer:
zrpc.connection.Connection class. zrpc.connection.Connection class.
""" """
self.rpc = rpc self.rpc = rpc
if self.rpc.peer_protocol_version == 'Z200': # Wait until we know what version the other side is using.
while rpc.peer_protocol_version is None:
rpc.pending()
if rpc.peer_protocol_version == 'Z200':
self.lastTransaction = lambda: None self.lastTransaction = lambda: None
self.getInvalidations = lambda tid: None self.getInvalidations = lambda tid: None
self.getAuthProtocol = lambda: None
def extensionMethod(self, name): def extensionMethod(self, name):
return ExtensionMethodWrapper(self.rpc, name).call return ExtensionMethodWrapper(self.rpc, name).call
...@@ -47,7 +51,7 @@ class StorageServer: ...@@ -47,7 +51,7 @@ class StorageServer:
def getAuthProtocol(self): def getAuthProtocol(self):
return self.rpc.call('getAuthProtocol') return self.rpc.call('getAuthProtocol')
def lastTransaction(self): def lastTransaction(self):
# Not in protocol version 2.0.0; see __init__() # Not in protocol version 2.0.0; see __init__()
return self.rpc.call('lastTransaction') return self.rpc.call('lastTransaction')
...@@ -150,6 +154,6 @@ class ExtensionMethodWrapper: ...@@ -150,6 +154,6 @@ class ExtensionMethodWrapper:
def __init__(self, rpc, name): def __init__(self, rpc, name):
self.rpc = rpc self.rpc = rpc
self.name = name self.name = name
def call(self, *a, **kwa): def call(self, *a, **kwa):
return self.rpc.call(self.name, *a, **kwa) return self.rpc.call(self.name, *a, **kwa)
...@@ -43,7 +43,7 @@ from ZODB.POSException import StorageError, StorageTransactionError ...@@ -43,7 +43,7 @@ from ZODB.POSException import StorageError, StorageTransactionError
from ZODB.POSException import TransactionError, ReadOnlyError, ConflictError from ZODB.POSException import TransactionError, ReadOnlyError, ConflictError
from ZODB.referencesf import referencesf from ZODB.referencesf import referencesf
from ZODB.Transaction import Transaction from ZODB.Transaction import Transaction
from ZODB.utils import u64 from ZODB.utils import u64, oid_repr
_label = "ZSS" # Default label used for logging. _label = "ZSS" # Default label used for logging.
...@@ -90,7 +90,7 @@ class ZEOStorage: ...@@ -90,7 +90,7 @@ class ZEOStorage:
self._extensions = {} self._extensions = {}
for func in self.extensions: for func in self.extensions:
self._extensions[func.func_name] = None self._extensions[func.func_name] = None
def finish_auth(self, authenticated): def finish_auth(self, authenticated):
if not self.auth_realm: if not self.auth_realm:
return 1 return 1
...@@ -99,7 +99,7 @@ class ZEOStorage: ...@@ -99,7 +99,7 @@ class ZEOStorage:
def set_database(self, database): def set_database(self, database):
self.database = database self.database = database
def notifyConnected(self, conn): def notifyConnected(self, conn):
self.connection = conn # For restart_other() below self.connection = conn # For restart_other() below
self.client = self.ClientStorageStubClass(conn) self.client = self.ClientStorageStubClass(conn)
...@@ -189,7 +189,7 @@ class ZEOStorage: ...@@ -189,7 +189,7 @@ class ZEOStorage:
if not protocol or protocol == 'none': if not protocol or protocol == 'none':
return None return None
return protocol return protocol
def register(self, storage_id, read_only): def register(self, storage_id, read_only):
"""Select the storage that this client will use """Select the storage that this client will use
...@@ -398,6 +398,7 @@ class ZEOStorage: ...@@ -398,6 +398,7 @@ class ZEOStorage:
def _clear_transaction(self): def _clear_transaction(self):
# Common code at end of tpc_finish() and tpc_abort() # Common code at end of tpc_finish() and tpc_abort()
self.transaction = None self.transaction = None
self.txnlog.close()
if self.locked: if self.locked:
self.locked = 0 self.locked = 0
self.timeout.end(self) self.timeout.end(self)
...@@ -483,6 +484,8 @@ class ZEOStorage: ...@@ -483,6 +484,8 @@ class ZEOStorage:
self.store_failed = 1 self.store_failed = 1
if isinstance(err, ConflictError): if isinstance(err, ConflictError):
self.stats.conflicts += 1 self.stats.conflicts += 1
self.log("conflict error oid=%s msg=%s" %
(oid_repr(oid), str(err)), zLOG.BLATHER)
if not isinstance(err, TransactionError): if not isinstance(err, TransactionError):
# Unexpected errors are logged and passed to the client # Unexpected errors are logged and passed to the client
exc_info = sys.exc_info() exc_info = sys.exc_info()
...@@ -506,6 +509,7 @@ class ZEOStorage: ...@@ -506,6 +509,7 @@ class ZEOStorage:
self.invalidated.append((oid, version)) self.invalidated.append((oid, version))
if newserial == ResolvedSerial: if newserial == ResolvedSerial:
self.stats.conflicts_resolved += 1 self.stats.conflicts_resolved += 1
self.log("conflict resolved oid=%s" % oid_repr(oid), zLOG.BLATHER)
self.serials.append((oid, newserial)) self.serials.append((oid, newserial))
return err is None return err is None
...@@ -680,7 +684,7 @@ class StorageServer: ...@@ -680,7 +684,7 @@ class StorageServer:
It should be in a format compatible with the authentication It should be in a format compatible with the authentication
protocol used; for instance, "sha" and "srp" require different protocol used; for instance, "sha" and "srp" require different
formats. formats.
Note that to implement an authentication protocol, a server Note that to implement an authentication protocol, a server
and client authentication mechanism must be implemented in a and client authentication mechanism must be implemented in a
auth_* module, which should be stored inside the "auth" auth_* module, which should be stored inside the "auth"
...@@ -728,7 +732,7 @@ class StorageServer: ...@@ -728,7 +732,7 @@ class StorageServer:
self.monitor = StatsServer(monitor_address, self.stats) self.monitor = StatsServer(monitor_address, self.stats)
else: else:
self.monitor = None self.monitor = None
def _setup_auth(self, protocol): def _setup_auth(self, protocol):
# Can't be done in global scope, because of cyclic references # Can't be done in global scope, because of cyclic references
from ZEO.auth import get_module from ZEO.auth import get_module
...@@ -739,9 +743,9 @@ class StorageServer: ...@@ -739,9 +743,9 @@ class StorageServer:
if not module: if not module:
log("%s: no such an auth protocol: %s" % (name, protocol)) log("%s: no such an auth protocol: %s" % (name, protocol))
return return
storage_class, client, db_class = module storage_class, client, db_class = module
if not storage_class or not issubclass(storage_class, ZEOStorage): if not storage_class or not issubclass(storage_class, ZEOStorage):
log(("%s: %s isn't a valid protocol, must have a StorageClass" % log(("%s: %s isn't a valid protocol, must have a StorageClass" %
(name, protocol))) (name, protocol)))
...@@ -750,7 +754,7 @@ class StorageServer: ...@@ -750,7 +754,7 @@ class StorageServer:
self.ZEOStorageClass = storage_class self.ZEOStorageClass = storage_class
log("%s: using auth protocol: %s" % (name, protocol)) log("%s: using auth protocol: %s" % (name, protocol))
# We create a Database instance here for use with the authenticator # We create a Database instance here for use with the authenticator
# modules. Having one instance allows it to be shared between multiple # modules. Having one instance allows it to be shared between multiple
# storages, avoiding the need to bloat each with a new authenticator # storages, avoiding the need to bloat each with a new authenticator
...@@ -762,7 +766,7 @@ class StorageServer: ...@@ -762,7 +766,7 @@ class StorageServer:
"does not match storage realm %r" "does not match storage realm %r"
% (self.database.realm, self.auth_realm)) % (self.database.realm, self.auth_realm))
def new_connection(self, sock, addr): def new_connection(self, sock, addr):
"""Internal: factory to create a new connection. """Internal: factory to create a new connection.
...@@ -776,7 +780,7 @@ class StorageServer: ...@@ -776,7 +780,7 @@ class StorageServer:
zstorage.set_database(self.database) zstorage.set_database(self.database)
else: else:
zstorage = self.ZEOStorageClass(self, self.read_only) zstorage = self.ZEOStorageClass(self, self.read_only)
c = self.ManagedServerConnectionClass(sock, addr, zstorage, self) c = self.ManagedServerConnectionClass(sock, addr, zstorage, self)
log("new connection %s: %s" % (addr, `c`)) log("new connection %s: %s" % (addr, `c`))
return c return c
...@@ -846,12 +850,12 @@ class StorageServer: ...@@ -846,12 +850,12 @@ class StorageServer:
if not self.invq: if not self.invq:
log("invq empty") log("invq empty")
return None, [] return None, []
earliest_tid = self.invq[0][0] earliest_tid = self.invq[0][0]
if earliest_tid > tid: if earliest_tid > tid:
log("tid to old for invq %s < %s" % (u64(tid), u64(earliest_tid))) log("tid to old for invq %s < %s" % (u64(tid), u64(earliest_tid)))
return None, [] return None, []
oids = {} oids = {}
for tid, L in self.invq: for tid, L in self.invq:
for key in L: for key in L:
...@@ -928,6 +932,7 @@ class TimeoutThread(threading.Thread): ...@@ -928,6 +932,7 @@ class TimeoutThread(threading.Thread):
self._cond.acquire() self._cond.acquire()
try: try:
assert self._client is not None assert self._client is not None
assert self._client is client
self._client = None self._client = None
self._deadline = None self._deadline = None
finally: finally:
...@@ -953,7 +958,6 @@ class TimeoutThread(threading.Thread): ...@@ -953,7 +958,6 @@ class TimeoutThread(threading.Thread):
self._trigger.pull_trigger(lambda: client.connection.close()) self._trigger.pull_trigger(lambda: client.connection.close())
else: else:
time.sleep(howlong) time.sleep(howlong)
self.trigger.close()
def run_in_thread(method, *args): def run_in_thread(method, *args):
t = SlowMethodThread(method, args) t = SlowMethodThread(method, args)
......
...@@ -15,10 +15,10 @@ ...@@ -15,10 +15,10 @@
See the file README.txt in this directory for an overview. See the file README.txt in this directory for an overview.
ZEO is now part of ZODB; ZODB's home on the web is ZEO is now part of ZODB; ZODB's home on the web is
http://www.zope.org/Wikis/ZODB http://www.zope.org/Wikis/ZODB
""" """
version = "2.1b2" version = "2.2c1"
...@@ -28,4 +28,3 @@ def register_module(name, storage_class, client, db): ...@@ -28,4 +28,3 @@ def register_module(name, storage_class, client, db):
if _auth_modules.has_key(name): if _auth_modules.has_key(name):
raise TypeError, "%s is already registred" % name raise TypeError, "%s is already registred" % name
_auth_modules[name] = storage_class, client, db _auth_modules[name] = storage_class, client, db
...@@ -61,7 +61,7 @@ def hexdigest(s): ...@@ -61,7 +61,7 @@ def hexdigest(s):
class DigestDatabase(Database): class DigestDatabase(Database):
def __init__(self, filename, realm=None): def __init__(self, filename, realm=None):
Database.__init__(self, filename, realm) Database.__init__(self, filename, realm)
# Initialize a key used to build the nonce for a challenge. # Initialize a key used to build the nonce for a challenge.
# We need one key for the lifetime of the server, so it # We need one key for the lifetime of the server, so it
# is convenient to store in on the database. # is convenient to store in on the database.
...@@ -134,7 +134,7 @@ class DigestClient(Client): ...@@ -134,7 +134,7 @@ class DigestClient(Client):
raise AuthError("expected realm %r, got realm %r" raise AuthError("expected realm %r, got realm %r"
% (_realm, realm)) % (_realm, realm))
h_up = hexdigest("%s:%s:%s" % (username, realm, password)) h_up = hexdigest("%s:%s:%s" % (username, realm, password))
resp_dig = hexdigest("%s:%s" % (h_up, challenge)) resp_dig = hexdigest("%s:%s" % (h_up, challenge))
result = self.stub.auth_response((username, challenge, resp_dig)) result = self.stub.auth_response((username, challenge, resp_dig))
if result: if result:
......
...@@ -34,19 +34,19 @@ def sort(L): ...@@ -34,19 +34,19 @@ def sort(L):
"""Sort a list in-place and return it.""" """Sort a list in-place and return it."""
L.sort() L.sort()
return L return L
class Database: class Database:
"""Abstracts a password database. """Abstracts a password database.
This class is used both in the authentication process (via This class is used both in the authentication process (via
get_password()) and by client scripts that manage the password get_password()) and by client scripts that manage the password
database file. database file.
The password file is a simple, colon-separated text file mapping The password file is a simple, colon-separated text file mapping
usernames to password hashes. The hashes are SHA hex digests usernames to password hashes. The hashes are SHA hex digests
produced from the password string. produced from the password string.
""" """
def __init__(self, filename, realm=None): def __init__(self, filename, realm=None):
"""Creates a new Database """Creates a new Database
...@@ -61,7 +61,7 @@ class Database: ...@@ -61,7 +61,7 @@ class Database:
self.filename = filename self.filename = filename
self.realm = realm self.realm = realm
self.load() self.load()
def save(self, fd=None): def save(self, fd=None):
filename = self.filename filename = self.filename
...@@ -72,7 +72,7 @@ class Database: ...@@ -72,7 +72,7 @@ class Database:
for username in sort(self._users.keys()): for username in sort(self._users.keys()):
print >> fd, "%s: %s" % (username, self._users[username]) print >> fd, "%s: %s" % (username, self._users[username])
def load(self): def load(self):
filename = self.filename filename = self.filename
if not filename: if not filename:
...@@ -80,7 +80,7 @@ class Database: ...@@ -80,7 +80,7 @@ class Database:
if not os.path.exists(filename): if not os.path.exists(filename):
return return
fd = open(filename) fd = open(filename)
L = fd.readlines() L = fd.readlines()
...@@ -90,7 +90,7 @@ class Database: ...@@ -90,7 +90,7 @@ class Database:
if L[0].startswith("realm "): if L[0].startswith("realm "):
line = L.pop(0).strip() line = L.pop(0).strip()
self.realm = line[len("realm "):] self.realm = line[len("realm "):]
for line in L: for line in L:
username, hash = line.strip().split(":", 1) username, hash = line.strip().split(":", 1)
self._users[username] = hash.strip() self._users[username] = hash.strip()
...@@ -103,10 +103,10 @@ class Database: ...@@ -103,10 +103,10 @@ class Database:
Callers must check for LookupError, which is raised in Callers must check for LookupError, which is raised in
the case of a non-existent user specified.""" the case of a non-existent user specified."""
if not self._users.has_key(username): if not self._users.has_key(username):
raise LookupError, "No such user: %s" % username raise LookupError, "No such user: %s" % username
return self._users[username] return self._users[username]
def hash(self, s): def hash(self, s):
return sha.new(s).hexdigest() return sha.new(s).hexdigest()
...@@ -116,7 +116,7 @@ class Database: ...@@ -116,7 +116,7 @@ class Database:
self._store_password(username, password) self._store_password(username, password)
def del_user(self, username): def del_user(self, username):
if not self._users.has_key(username): if not self._users.has_key(username):
raise LookupError, "No such user: %s" % username raise LookupError, "No such user: %s" % username
del self._users[username] del self._users[username]
......
...@@ -13,7 +13,7 @@ ...@@ -13,7 +13,7 @@
############################################################################## ##############################################################################
"""Monitor behavior of ZEO server and record statistics. """Monitor behavior of ZEO server and record statistics.
$Id: monitor.py,v 1.3 2003/01/15 21:23:16 jeremy Exp $ $Id: monitor.py,v 1.4 2003/10/02 18:17:22 jeremy Exp $
""" """
import asyncore import asyncore
...@@ -54,7 +54,7 @@ class StorageStats: ...@@ -54,7 +54,7 @@ class StorageStats:
elif field == "Active transactions": elif field == "Active transactions":
self.active_txns = int(value) self.active_txns = int(value)
elif field == "Commit lock held for": elif field == "Commit lock held for":
# This assumes # This assumes
self.lock_time = time.time() - int(value) self.lock_time = time.time() - int(value)
elif field == "Commits": elif field == "Commits":
self.commits = int(value) self.commits = int(value)
...@@ -112,7 +112,7 @@ class StatsClient(asyncore.dispatcher): ...@@ -112,7 +112,7 @@ class StatsClient(asyncore.dispatcher):
n = self.socket.send(s) n = self.socket.send(s)
if n < len(s): if n < len(s):
self.buf.append(s[:n]) self.buf.append(s[:n])
if self.closed and not self.buf: if self.closed and not self.buf:
asyncore.dispatcher.close(self) asyncore.dispatcher.close(self)
......
...@@ -27,7 +27,7 @@ from ZEO.tests.TestThread import TestThread ...@@ -27,7 +27,7 @@ from ZEO.tests.TestThread import TestThread
ZERO = '\0'*8 ZERO = '\0'*8
class DummyDB: class DummyDB:
def invalidate(self, *args): def invalidate(self, *args, **kwargs):
pass pass
class WorkerThread(TestThread): class WorkerThread(TestThread):
...@@ -116,7 +116,7 @@ class CommitLockTests: ...@@ -116,7 +116,7 @@ class CommitLockTests:
self._dostore() self._dostore()
self._cleanup() self._cleanup()
def checkCommitLockVoteAbort(self): def checkCommitLockVoteAbort(self):
oid, txn = self._start_txn() oid, txn = self._start_txn()
self._storage.tpc_vote(txn) self._storage.tpc_vote(txn)
...@@ -129,7 +129,7 @@ class CommitLockTests: ...@@ -129,7 +129,7 @@ class CommitLockTests:
self._dostore() self._dostore()
self._cleanup() self._cleanup()
def checkCommitLockVoteClose(self): def checkCommitLockVoteClose(self):
oid, txn = self._start_txn() oid, txn = self._start_txn()
self._storage.tpc_vote(txn) self._storage.tpc_vote(txn)
...@@ -153,7 +153,7 @@ class CommitLockTests: ...@@ -153,7 +153,7 @@ class CommitLockTests:
def _finish_undo(self, msgid): def _finish_undo(self, msgid):
return self._storage._server.rpc._deferred_wait(msgid) return self._storage._server.rpc._deferred_wait(msgid)
def checkCommitLockUndoFinish(self): def checkCommitLockUndoFinish(self):
trans_id = self._get_trans_id() trans_id = self._get_trans_id()
oid, txn = self._start_txn() oid, txn = self._start_txn()
...@@ -170,7 +170,7 @@ class CommitLockTests: ...@@ -170,7 +170,7 @@ class CommitLockTests:
self._dostore() self._dostore()
self._cleanup() self._cleanup()
def checkCommitLockUndoAbort(self): def checkCommitLockUndoAbort(self):
trans_id = self._get_trans_id() trans_id = self._get_trans_id()
oid, txn = self._start_txn() oid, txn = self._start_txn()
...@@ -186,7 +186,7 @@ class CommitLockTests: ...@@ -186,7 +186,7 @@ class CommitLockTests:
self._dostore() self._dostore()
self._cleanup() self._cleanup()
def checkCommitLockUndoClose(self): def checkCommitLockUndoClose(self):
trans_id = self._get_trans_id() trans_id = self._get_trans_id()
oid, txn = self._start_txn() oid, txn = self._start_txn()
...@@ -201,23 +201,24 @@ class CommitLockTests: ...@@ -201,23 +201,24 @@ class CommitLockTests:
self._finish_threads() self._finish_threads()
self._cleanup() self._cleanup()
def _begin_threads(self): def _begin_threads(self):
# Start a second transaction on a different connection without # Start a second transaction on a different connection without
# blocking the test thread. # blocking the test thread. Returns only after each thread has
# set it's ready event.
self._storages = [] self._storages = []
self._threads = [] self._threads = []
for i in range(self.NUM_CLIENTS): for i in range(self.NUM_CLIENTS):
storage = self._duplicate_client() storage = self._duplicate_client()
txn = Transaction() txn = Transaction()
tid = self._get_timestamp() tid = self._get_timestamp()
t = WorkerThread(self, storage, txn) t = WorkerThread(self, storage, txn)
self._threads.append(t) self._threads.append(t)
t.start() t.start()
t.ready.wait() t.ready.wait()
# Close on the connections abnormally to test server response # Close on the connections abnormally to test server response
if i == 0: if i == 0:
storage.close() storage.close()
......
...@@ -170,7 +170,7 @@ class CommonSetupTearDown(StorageTestBase): ...@@ -170,7 +170,7 @@ class CommonSetupTearDown(StorageTestBase):
if ro_svr: if ro_svr:
zconf.read_only = 1 zconf.read_only = 1
if self.monitor: if self.monitor:
zconf.monitor_address = ("", 42000) zconf.monitor_address = ("", 42000)
if self.invq: if self.invq:
zconf.invalidation_queue_size = self.invq zconf.invalidation_queue_size = self.invq
if self.timeout: if self.timeout:
......
...@@ -347,8 +347,8 @@ class InvalidationTests: ...@@ -347,8 +347,8 @@ class InvalidationTests:
# Run two threads that update the BTree # Run two threads that update the BTree
cd = {} cd = {}
t1 = self.StressThread(self, db1, stop, 1, cd, 1, sleep=0.001) t1 = self.StressThread(self, db1, stop, 1, cd, 1, sleep=0.01)
t2 = self.StressThread(self, db1, stop, 2, cd, 2, sleep=0.001) t2 = self.StressThread(self, db1, stop, 2, cd, 2, sleep=0.01)
self.go(stop, cd, t1, t2) self.go(stop, cd, t1, t2)
cn.sync() cn.sync()
...@@ -375,8 +375,8 @@ class InvalidationTests: ...@@ -375,8 +375,8 @@ class InvalidationTests:
cd = {} cd = {}
t1 = self.StressThread(self, db1, stop, 1, cd, 1, 3) t1 = self.StressThread(self, db1, stop, 1, cd, 1, 3)
t2 = self.StressThread(self, db2, stop, 2, cd, 2, 3, 0.001) t2 = self.StressThread(self, db2, stop, 2, cd, 2, 3, 0.01)
t3 = self.StressThread(self, db2, stop, 3, cd, 3, 3, 0.001) t3 = self.StressThread(self, db2, stop, 3, cd, 3, 3, 0.01)
self.go(stop, cd, t1, t2, t3) self.go(stop, cd, t1, t2, t3)
cn.sync() cn.sync()
...@@ -404,8 +404,8 @@ class InvalidationTests: ...@@ -404,8 +404,8 @@ class InvalidationTests:
cd = {} cd = {}
t1 = VersionStressThread(self, db1, stop, 1, cd, 1, 3) t1 = VersionStressThread(self, db1, stop, 1, cd, 1, 3)
t2 = VersionStressThread(self, db2, stop, 2, cd, 2, 3, 0.001) t2 = VersionStressThread(self, db2, stop, 2, cd, 2, 3, 0.01)
t3 = VersionStressThread(self, db2, stop, 3, cd, 3, 3, 0.001) t3 = VersionStressThread(self, db2, stop, 3, cd, 3, 3, 0.01)
self.go(stop, cd, t1, t2, t3) self.go(stop, cd, t1, t2, t3)
cn.sync() cn.sync()
...@@ -435,9 +435,9 @@ class InvalidationTests: ...@@ -435,9 +435,9 @@ class InvalidationTests:
# at the same time. # at the same time.
cd = {} cd = {}
t1 = LargeUpdatesThread(self, db1, stop, 1, cd, 1, 3, 0.001) t1 = LargeUpdatesThread(self, db1, stop, 1, cd, 1, 3, 0.02)
t2 = LargeUpdatesThread(self, db2, stop, 2, cd, 2, 3, 0.001) t2 = LargeUpdatesThread(self, db2, stop, 2, cd, 2, 3, 0.01)
t3 = LargeUpdatesThread(self, db2, stop, 3, cd, 3, 3, 0.001) t3 = LargeUpdatesThread(self, db2, stop, 3, cd, 3, 3, 0.01)
self.go(stop, cd, t1, t2, t3) self.go(stop, cd, t1, t2, t3)
cn.sync() cn.sync()
......
...@@ -13,11 +13,11 @@ ...@@ -13,11 +13,11 @@
############################################################################## ##############################################################################
"""Implements plaintext password authentication. The password is stored in """Implements plaintext password authentication. The password is stored in
an SHA hash in the Database. The client sends over the plaintext an SHA hash in the Database. The client sends over the plaintext
password, and the SHA hashing is done on the server side. password, and the SHA hashing is done on the server side.
This mechanism offers *no network security at all*; the only security This mechanism offers *no network security at all*; the only security
is provided by not storing plaintext passwords on disk. (See the is provided by not storing plaintext passwords on disk.
auth_srp module for a secure mechanism)""" """
import sha import sha
...@@ -25,20 +25,31 @@ from ZEO.StorageServer import ZEOStorage ...@@ -25,20 +25,31 @@ from ZEO.StorageServer import ZEOStorage
from ZEO.auth import register_module from ZEO.auth import register_module
from ZEO.auth.base import Client, Database from ZEO.auth.base import Client, Database
def session_key(username, realm, password):
return sha.new("%s:%s:%s" % (username, realm, password)).hexdigest()
class StorageClass(ZEOStorage): class StorageClass(ZEOStorage):
def auth(self, username, password): def auth(self, username, password):
try: try:
dbpw = self.database.get_password(username) dbpw = self.database.get_password(username)
except LookupError: except LookupError:
return 0 return 0
password = sha.new(password).hexdigest() password_dig = sha.new(password).hexdigest()
return self.finish_auth(dbpw == password) if dbpw == password_dig:
self.connection.setSessionKey(session_key(username,
self.database.realm,
password))
return self.finish_auth(dbpw == password_dig)
class PlaintextClient(Client): class PlaintextClient(Client):
extensions = ["auth"] extensions = ["auth"]
def start(self, username, realm, password): def start(self, username, realm, password):
return self.stub.auth(username, password) if self.stub.auth(username, password):
return session_key(username, realm, password)
else:
return None
register_module("plaintext", StorageClass, PlaintextClient, Database) register_module("plaintext", StorageClass, PlaintextClient, Database)
...@@ -70,20 +70,20 @@ def start_zeo_server(storage_conf, zeo_conf, port, keep=0): ...@@ -70,20 +70,20 @@ def start_zeo_server(storage_conf, zeo_conf, port, keep=0):
Returns the ZEO port, the test server port, the pid, and the path Returns the ZEO port, the test server port, the pid, and the path
to the config file. to the config file.
""" """
# Store the config info in a temp file. # Store the config info in a temp file.
tmpfile = tempfile.mktemp(".conf") tmpfile = tempfile.mktemp(".conf")
fp = open(tmpfile, 'w') fp = open(tmpfile, 'w')
zeo_conf.dump(fp) zeo_conf.dump(fp)
fp.write(storage_conf) fp.write(storage_conf)
fp.close() fp.close()
# Find the zeoserver script # Find the zeoserver script
import ZEO.tests.zeoserver import ZEO.tests.zeoserver
script = ZEO.tests.zeoserver.__file__ script = ZEO.tests.zeoserver.__file__
if script.endswith('.pyc'): if script.endswith('.pyc'):
script = script[:-1] script = script[:-1]
# Create a list of arguments, which we'll tuplify below # Create a list of arguments, which we'll tuplify below
qa = _quote_arg qa = _quote_arg
args = [qa(sys.executable), qa(script), '-C', qa(tmpfile)] args = [qa(sys.executable), qa(script), '-C', qa(tmpfile)]
......
...@@ -18,8 +18,11 @@ import tempfile ...@@ -18,8 +18,11 @@ import tempfile
import time import time
import unittest import unittest
import zLOG
from ThreadedAsync import LoopCallback from ThreadedAsync import LoopCallback
from ZEO.ClientStorage import ClientStorage from ZEO.ClientStorage import ClientStorage
from ZEO.Exceptions import ClientDisconnected
from ZEO.StorageServer import StorageServer from ZEO.StorageServer import StorageServer
from ZEO.tests.ConnectionTests import CommonSetupTearDown from ZEO.tests.ConnectionTests import CommonSetupTearDown
...@@ -30,7 +33,7 @@ class AuthTest(CommonSetupTearDown): ...@@ -30,7 +33,7 @@ class AuthTest(CommonSetupTearDown):
__super_getServerConfig = CommonSetupTearDown.getServerConfig __super_getServerConfig = CommonSetupTearDown.getServerConfig
__super_setUp = CommonSetupTearDown.setUp __super_setUp = CommonSetupTearDown.setUp
__super_tearDown = CommonSetupTearDown.tearDown __super_tearDown = CommonSetupTearDown.tearDown
realm = None realm = None
def setUp(self): def setUp(self):
...@@ -74,7 +77,9 @@ class AuthTest(CommonSetupTearDown): ...@@ -74,7 +77,9 @@ class AuthTest(CommonSetupTearDown):
self.assert_(self._storage._connection) self.assert_(self._storage._connection)
self._storage._connection.poll() self._storage._connection.poll()
self.assert_(self._storage.is_connected()) self.assert_(self._storage.is_connected())
# Make a call to make sure the mechanism is working
self._storage.versions()
def testNOK(self): def testNOK(self):
self._storage = self.openClientStorage(wait=0, username="foo", self._storage = self.openClientStorage(wait=0, username="foo",
password="noogie", password="noogie",
...@@ -83,6 +88,20 @@ class AuthTest(CommonSetupTearDown): ...@@ -83,6 +88,20 @@ class AuthTest(CommonSetupTearDown):
# If the test established a connection, then it failed. # If the test established a connection, then it failed.
self.failIf(self._storage._connection) self.failIf(self._storage._connection)
def testUnauthenticatedMessage(self):
# Test that an unauthenticated message is rejected by the server
# if it was sent after the connection was authenticated.
# Sleep for 0.2 seconds to give the server some time to start up
# seems to be needed before and after creating the storage
self._storage = self.openClientStorage(wait=0, username="foo",
password="bar", realm=self.realm)
self.wait()
self._storage.versions()
# Manually clear the state of the hmac connection
self._storage._connection._SizedMessageAsyncConnection__hmac_send = None
# Once the client stops using the hmac, it should be disconnected.
self.assertRaises(ClientDisconnected, self._storage.versions)
class PlainTextAuth(AuthTest): class PlainTextAuth(AuthTest):
import ZEO.tests.auth_plaintext import ZEO.tests.auth_plaintext
protocol = "plaintext" protocol = "plaintext"
...@@ -108,4 +127,3 @@ def test_suite(): ...@@ -108,4 +127,3 @@ def test_suite():
if __name__ == "__main__": if __name__ == "__main__":
unittest.main(defaultTest='test_suite') unittest.main(defaultTest='test_suite')
...@@ -396,7 +396,7 @@ class PersistentClientCacheTests(unittest.TestCase): ...@@ -396,7 +396,7 @@ class PersistentClientCacheTests(unittest.TestCase):
version = "folio" version = "folio"
vdata = "Mend your speech a little, lest you may mar your fortunes." vdata = "Mend your speech a little, lest you may mar your fortunes."
vserial = "12346789" vserial = "12346789"
self.cache.store(self._oid, nvdata, nvserial, version, vdata, vserial) self.cache.store(self._oid, nvdata, nvserial, version, vdata, vserial)
self.cache.checkSize(10 * self.cachesize) # force a cache flip self.cache.checkSize(10 * self.cachesize) # force a cache flip
...@@ -421,7 +421,7 @@ class PersistentClientCacheTests(unittest.TestCase): ...@@ -421,7 +421,7 @@ class PersistentClientCacheTests(unittest.TestCase):
data, serial = self.cache.load(self._oid, xversion) data, serial = self.cache.load(self._oid, xversion)
self.assertEqual(data, xdata) self.assertEqual(data, xdata)
self.assertEqual(serial, xserial) self.assertEqual(serial, xserial)
class ClientCacheLongOIDTests(ClientCacheTests): class ClientCacheLongOIDTests(ClientCacheTests):
_oid = 'abcdefghijklmnop' * 2 _oid = 'abcdefghijklmnop' * 2
_oid2 = 'bcdefghijklmnopq' * 2 _oid2 = 'bcdefghijklmnopq' * 2
......
...@@ -13,7 +13,7 @@ ...@@ -13,7 +13,7 @@
############################################################################## ##############################################################################
"""Test that the monitor produce sensible results. """Test that the monitor produce sensible results.
$Id: testMonitor.py,v 1.6 2003/05/30 19:20:56 jeremy Exp $ $Id: testMonitor.py,v 1.7 2003/10/02 18:17:21 jeremy Exp $
""" """
import socket import socket
...@@ -70,7 +70,7 @@ class MonitorTests(CommonSetupTearDown): ...@@ -70,7 +70,7 @@ class MonitorTests(CommonSetupTearDown):
s.parse("\n".join(sect[1:])) s.parse("\n".join(sect[1:]))
return d return d
def getConfig(self, path, create, read_only): def getConfig(self, path, create, read_only):
return """<mappingstorage 1/>""" return """<mappingstorage 1/>"""
......
...@@ -132,7 +132,8 @@ class GenericTests( ...@@ -132,7 +132,8 @@ class GenericTests(
self._servers = [adminaddr] self._servers = [adminaddr]
self._conf_path = path self._conf_path = path
self._storage = ClientStorage(zport, '1', cache_size=20000000, self._storage = ClientStorage(zport, '1', cache_size=20000000,
min_disconnect_poll=0.5, wait=1) min_disconnect_poll=0.5, wait=1,
wait_timeout=60)
self._storage.registerDB(DummyDB(), None) self._storage.registerDB(DummyDB(), None)
def tearDown(self): def tearDown(self):
......
...@@ -122,8 +122,11 @@ class Suicide(threading.Thread): ...@@ -122,8 +122,11 @@ class Suicide(threading.Thread):
self._adminaddr = addr self._adminaddr = addr
def run(self): def run(self):
# If this process doesn't exit in 300 seconds, commit suicide # If this process doesn't exit in 330 seconds, commit suicide.
time.sleep(300) # The client threads in the ConcurrentUpdate tests will run for
# as long as 300 seconds. Set this timeout to 330 to minimize
# chance that the server gives up before the clients.
time.sleep(330)
log("zeoserver", "suicide thread invoking shutdown") log("zeoserver", "suicide thread invoking shutdown")
from ZEO.tests.forker import shutdown_zeo_server from ZEO.tests.forker import shutdown_zeo_server
# XXX If the -k option was given to zeoserver, then the process will # XXX If the -k option was given to zeoserver, then the process will
...@@ -134,7 +137,7 @@ class Suicide(threading.Thread): ...@@ -134,7 +137,7 @@ class Suicide(threading.Thread):
def main(): def main():
label = 'zeoserver:%d' % os.getpid() label = 'zeoserver:%d' % os.getpid()
log(label, 'starting') log(label, 'starting')
# We don't do much sanity checking of the arguments, since if we get it # We don't do much sanity checking of the arguments, since if we get it
# wrong, it's a bug in the test suite. # wrong, it's a bug in the test suite.
keep = 0 keep = 0
...@@ -150,11 +153,11 @@ def main(): ...@@ -150,11 +153,11 @@ def main():
zo = ZEOOptions() zo = ZEOOptions()
zo.realize(["-C", configfile]) zo.realize(["-C", configfile])
zeo_port = int(zo.address[1]) zeo_port = int(zo.address[1])
# XXX a hack # XXX a hack
if zo.auth_protocol == "plaintext": if zo.auth_protocol == "plaintext":
import ZEO.tests.auth_plaintext import ZEO.tests.auth_plaintext
# Open the config file and let ZConfig parse the data there. Then remove # Open the config file and let ZConfig parse the data there. Then remove
# the config file, otherwise we'll leave turds. # the config file, otherwise we'll leave turds.
# The rest of the args are hostname, portnum # The rest of the args are hostname, portnum
...@@ -186,7 +189,7 @@ def main(): ...@@ -186,7 +189,7 @@ def main():
storage.close() storage.close()
cleanup(storage) cleanup(storage)
sys.exit(2) sys.exit(2)
t.register_socket(server.dispatcher) t.register_socket(server.dispatcher)
# Create daemon suicide thread # Create daemon suicide thread
d = Suicide(test_addr) d = Suicide(test_addr)
......
...@@ -17,16 +17,12 @@ ...@@ -17,16 +17,12 @@
usage: python zeopasswd.py [options] username [password] usage: python zeopasswd.py [options] username [password]
-C/--configuration URL -- configuration file or URL -C/--configuration URL -- configuration file or URL
-p/--protocol -- authentication protocol name
-f/--filename -- authentication database filename
-r/--realm -- authentication database realm
-d/--delete -- delete user instead of updating password -d/--delete -- delete user instead of updating password
""" """
import getopt import getopt
import getpass import getpass
import sys import sys
import os
import ZConfig import ZConfig
import ZEO import ZEO
...@@ -39,41 +35,22 @@ def usage(msg): ...@@ -39,41 +35,22 @@ def usage(msg):
def options(args): def options(args):
"""Password-specific options loaded from regular ZEO config file.""" """Password-specific options loaded from regular ZEO config file."""
schema = ZConfig.loadSchema(os.path.join(os.path.dirname(ZEO.__file__),
"schema.xml"))
try: try:
options, args = getopt.getopt(args, "dr:p:f:C:", ["configure=", options, args = getopt.getopt(args, "C:", ["configure="])
"protocol=",
"filename=",
"realm"])
except getopt.error, msg: except getopt.error, msg:
usage(msg) usage(msg)
config = None config = None
delete = 0 delete = False
auth_protocol = None
auth_db = ""
auth_realm = None
for k, v in options: for k, v in options:
if k == '-C' or k == '--configure': if k == '-C' or k == '--configure':
schemafile = os.path.join(os.path.dirname(ZEO.__file__),
"schema.xml")
schema = ZConfig.loadSchema(schemafile)
config, nil = ZConfig.loadConfig(schema, v) config, nil = ZConfig.loadConfig(schema, v)
if k == '-d' or k == '--delete': if k == '-d' or k == '--delete':
delete = 1 delete = True
if k == '-p' or k == '--protocol': if config is None:
auth_protocol = v usage("Must specifiy configuration file")
if k == '-f' or k == '--filename':
auth_db = v
if k == '-r' or k == '--realm':
auth_realm = v
if config is not None:
if auth_protocol or auth_db:
usage("Conflicting options; use either -C *or* -p and -f")
auth_protocol = config.zeo.authentication_protocol
auth_db = config.zeo.authentication_database
auth_realm = config.zeo.authentication_realm
elif not (auth_protocol and auth_db):
usage("Must specifiy configuration file or protocol and database")
password = None password = None
if delete: if delete:
...@@ -91,22 +68,21 @@ def options(args): ...@@ -91,22 +68,21 @@ def options(args):
username = args[0] username = args[0]
else: else:
username, password = args username, password = args
return auth_protocol, auth_db, auth_realm, delete, username, password return config.zeo, delete, username, password
def main(args=None): def main(args=None):
p, auth_db, auth_realm, delete, username, password = options(args) options, delete, username, password = options(args)
p = options.authentication_protocol
if p is None: if p is None:
usage("ZEO configuration does not specify authentication-protocol") usage("ZEO configuration does not specify authentication-protocol")
if p == "digest": if p == "digest":
from ZEO.auth.auth_digest import DigestDatabase as Database from ZEO.auth.auth_digest import DigestDatabase as Database
elif p == "srp": elif p == "srp":
from ZEO.auth.auth_srp import SRPDatabase as Database from ZEO.auth.auth_srp import SRPDatabase as Database
else: if options.authentication_database is None:
raise ValueError, "Unknown database type %r" % p
if auth_db is None:
usage("ZEO configuration does not specify authentication-database") usage("ZEO configuration does not specify authentication-database")
db = Database(auth_db, auth_realm) db = Database(options.authentication_database)
if delete: if delete:
db.del_user(username) db.del_user(username)
else: else:
...@@ -116,5 +92,4 @@ def main(args=None): ...@@ -116,5 +92,4 @@ def main(args=None):
db.save() db.save()
if __name__ == "__main__": if __name__ == "__main__":
main(sys.argv[1:]) main(sys.argv)
...@@ -105,6 +105,7 @@ class ConnectionManager(object): ...@@ -105,6 +105,7 @@ class ConnectionManager(object):
if self.trigger is not None: if self.trigger is not None:
self.trigger.close() self.trigger.close()
self.trigger = None self.trigger = None
ThreadedAsync.remove_loop_callback(self.set_async)
def set_async(self, map): def set_async(self, map):
# This is the callback registered with ThreadedAsync. The # This is the callback registered with ThreadedAsync. The
...@@ -406,7 +407,7 @@ class ConnectThread(threading.Thread): ...@@ -406,7 +407,7 @@ class ConnectThread(threading.Thread):
del wrappers[wrap] del wrappers[wrap]
# XXX should check deadline # XXX should check deadline
class ConnectWrapper: class ConnectWrapper:
"""An object that handles the connection procedure for one socket. """An object that handles the connection procedure for one socket.
......
...@@ -126,11 +126,15 @@ class Connection(smac.SizedMessageAsyncConnection, object): ...@@ -126,11 +126,15 @@ class Connection(smac.SizedMessageAsyncConnection, object):
# Protocol history: # Protocol history:
# #
# Z200 -- original ZEO 2.0 protocol # Z200 -- Original ZEO 2.0 protocol
# #
# Z201 -- added invalidateTransaction() to client; # Z201 -- Added invalidateTransaction() to client.
# renamed several client methods; # Renamed several client methods.
# added lastTransaction() to server # Added several sever methods:
# lastTransaction()
# getAuthProtocol() and scheme-specific authentication methods
# getExtensionMethods().
# getInvalidations().
def __init__(self, sock, addr, obj=None): def __init__(self, sock, addr, obj=None):
self.obj = None self.obj = None
......
...@@ -31,7 +31,6 @@ class Dispatcher(asyncore.dispatcher): ...@@ -31,7 +31,6 @@ class Dispatcher(asyncore.dispatcher):
self.__super_init() self.__super_init()
self.addr = addr self.addr = addr
self.factory = factory self.factory = factory
self.clients = []
self._open_socket() self._open_socket()
def _open_socket(self): def _open_socket(self):
...@@ -58,4 +57,3 @@ class Dispatcher(asyncore.dispatcher): ...@@ -58,4 +57,3 @@ class Dispatcher(asyncore.dispatcher):
return return
c = self.factory(sock, addr) c = self.factory(sock, addr)
log("connect from %s: %s" % (repr(addr), c)) log("connect from %s: %s" % (repr(addr), c))
self.clients.append(c)
...@@ -64,7 +64,7 @@ del tmp_dict ...@@ -64,7 +64,7 @@ del tmp_dict
# that we could pass to send() without blocking. # that we could pass to send() without blocking.
SEND_SIZE = 60000 SEND_SIZE = 60000
MAC_BIT = 0x80000000 MAC_BIT = 0x80000000L
class SizedMessageAsyncConnection(asyncore.dispatcher): class SizedMessageAsyncConnection(asyncore.dispatcher):
__super_init = asyncore.dispatcher.__init__ __super_init = asyncore.dispatcher.__init__
...@@ -96,12 +96,33 @@ class SizedMessageAsyncConnection(asyncore.dispatcher): ...@@ -96,12 +96,33 @@ class SizedMessageAsyncConnection(asyncore.dispatcher):
self.__output_lock = threading.Lock() # Protects __output self.__output_lock = threading.Lock() # Protects __output
self.__output = [] self.__output = []
self.__closed = 0 self.__closed = 0
self.__hmac = None # Each side of the connection sends and receives messages. A
# MAC is generated for each message and depends on each
# previous MAC; the state of the MAC generator depends on the
# history of operations it has performed. So the MACs must be
# generated in the same order they are verified.
# Each side is guaranteed to receive messages in the order
# they are sent, but there is no ordering constraint between
# message sends and receives. If the two sides are A and B
# and message An indicates the nth message sent by A, then
# A1 A2 B1 B2 and A1 B1 B2 A2 are both legitimate total
# orderings of the messages.
# As a result, there must be seperate MAC generators for each
# side of the connection. If not, the generator state would
# be different after A1 A2 B1 B2 than it would be after
# A1 B1 B2 A2; if the generator state was different, the MAC
# could not be verified.
self.__hmac_send = None
self.__hmac_recv = None
self.__super_init(sock, map) self.__super_init(sock, map)
def setSessionKey(self, sesskey): def setSessionKey(self, sesskey):
log("set session key %r" % sesskey) log("set session key %r" % sesskey)
self.__hmac = hmac.HMAC(sesskey, digestmod=sha) self.__hmac_send = hmac.HMAC(sesskey, digestmod=sha)
self.__hmac_recv = hmac.HMAC(sesskey, digestmod=sha)
def get_addr(self): def get_addr(self):
return self.addr return self.addr
...@@ -150,16 +171,18 @@ class SizedMessageAsyncConnection(asyncore.dispatcher): ...@@ -150,16 +171,18 @@ class SizedMessageAsyncConnection(asyncore.dispatcher):
inp = "".join(inp) inp = "".join(inp)
offset = 0 offset = 0
expect_mac = 0 has_mac = 0
while (offset + msg_size) <= input_len: while (offset + msg_size) <= input_len:
msg = inp[offset:offset + msg_size] msg = inp[offset:offset + msg_size]
offset = offset + msg_size offset = offset + msg_size
if not state: if not state:
msg_size = struct.unpack(">i", msg)[0] msg_size = struct.unpack(">I", msg)[0]
expect_mac = msg_size & MAC_BIT has_mac = msg_size & MAC_BIT
if expect_mac: if has_mac:
msg_size ^= MAC_BIT msg_size ^= MAC_BIT
msg_size += 20 msg_size += 20
elif self.__hmac_send:
raise ValueError("Received message without MAC")
state = 1 state = 1
else: else:
msg_size = 4 msg_size = 4
...@@ -174,12 +197,12 @@ class SizedMessageAsyncConnection(asyncore.dispatcher): ...@@ -174,12 +197,12 @@ class SizedMessageAsyncConnection(asyncore.dispatcher):
# incoming call to be handled. During all this # incoming call to be handled. During all this
# time, the __input_lock is held. That's a good # time, the __input_lock is held. That's a good
# thing, because it serializes incoming calls. # thing, because it serializes incoming calls.
if expect_mac: if has_mac:
mac = msg[:20] mac = msg[:20]
msg = msg[20:] msg = msg[20:]
if self.__hmac: if self.__hmac_recv:
self.__hmac.update(msg) self.__hmac_recv.update(msg)
_mac = self.__hmac.digest() _mac = self.__hmac_recv.digest()
if mac != _mac: if mac != _mac:
raise ValueError("MAC failed: %r != %r" raise ValueError("MAC failed: %r != %r"
% (_mac, mac)) % (_mac, mac))
...@@ -245,8 +268,9 @@ class SizedMessageAsyncConnection(asyncore.dispatcher): ...@@ -245,8 +268,9 @@ class SizedMessageAsyncConnection(asyncore.dispatcher):
def message_output(self, message): def message_output(self, message):
if __debug__: if __debug__:
if self._debug: if self._debug:
log('message_output %d bytes: %s' % log("message_output %d bytes: %s hmac=%d" %
(len(message), short_repr(message)), (len(message), short_repr(message),
self.__hmac_send and 1 or 0),
level=zLOG.TRACE) level=zLOG.TRACE)
if self.__closed: if self.__closed:
...@@ -255,12 +279,12 @@ class SizedMessageAsyncConnection(asyncore.dispatcher): ...@@ -255,12 +279,12 @@ class SizedMessageAsyncConnection(asyncore.dispatcher):
self.__output_lock.acquire() self.__output_lock.acquire()
try: try:
# do two separate appends to avoid copying the message string # do two separate appends to avoid copying the message string
if self.__hmac: if self.__hmac_send:
self.__output.append(struct.pack(">i", len(message) | MAC_BIT)) self.__output.append(struct.pack(">I", len(message) | MAC_BIT))
self.__hmac.update(message) self.__hmac_send.update(message)
self.__output.append(self.__hmac.digest()) self.__output.append(self.__hmac_send.digest())
else: else:
self.__output.append(struct.pack(">i", len(message))) self.__output.append(struct.pack(">I", len(message)))
if len(message) <= SEND_SIZE: if len(message) <= SEND_SIZE:
self.__output.append(message) self.__output.append(message)
else: else:
......
...@@ -167,6 +167,15 @@ else: ...@@ -167,6 +167,15 @@ else:
self.lock = thread.allocate_lock() self.lock = thread.allocate_lock()
self.thunks = [] self.thunks = []
self._trigger_connected = 0 self._trigger_connected = 0
self._closed = 0
def close(self):
if not self._closed:
self._closed = 1
self.del_channel()
# self.socket is a, self.trigger is w from __init__
self.socket.close()
self.trigger.close()
def __repr__(self): def __repr__(self):
return '<select-trigger (loopback) at %x>' % id(self) return '<select-trigger (loopback) at %x>' % id(self)
......
...@@ -13,7 +13,7 @@ ...@@ -13,7 +13,7 @@
############################################################################## ##############################################################################
"""Handy standard storage machinery """Handy standard storage machinery
$Id: BaseStorage.py,v 1.35 2003/09/15 16:29:15 jeremy Exp $ $Id: BaseStorage.py,v 1.36 2003/10/02 18:17:19 jeremy Exp $
""" """
import cPickle import cPickle
import time import time
......
...@@ -13,7 +13,7 @@ ...@@ -13,7 +13,7 @@
############################################################################## ##############################################################################
"""Database connection support """Database connection support
$Id: Connection.py,v 1.99 2003/09/15 16:29:15 jeremy Exp $""" $Id: Connection.py,v 1.100 2003/10/02 18:17:19 jeremy Exp $"""
from __future__ import nested_scopes from __future__ import nested_scopes
...@@ -308,12 +308,12 @@ class Connection(ExportImport.ExportImport, object): ...@@ -308,12 +308,12 @@ class Connection(ExportImport.ExportImport, object):
method_name, args, kw = self.__onCommitActions.pop(0) method_name, args, kw = self.__onCommitActions.pop(0)
getattr(self, method_name)(transaction, *args, **kw) getattr(self, method_name)(transaction, *args, **kw)
return return
oid = object._p_oid oid = object._p_oid
if self._conflicts.has_key(oid): if self._conflicts.has_key(oid):
self.getTransaction().register(object) self.getTransaction().register(object)
raise ReadConflictError(object=object) raise ReadConflictError(object=object)
invalid = self._invalid invalid = self._invalid
if oid is None or object._p_jar is not self: if oid is None or object._p_jar is not self:
# new object # new object
...@@ -625,7 +625,7 @@ class Connection(ExportImport.ExportImport, object): ...@@ -625,7 +625,7 @@ class Connection(ExportImport.ExportImport, object):
else: else:
self.getTransaction().register(obj) self.getTransaction().register(obj)
raise ReadConflictError(object=obj) raise ReadConflictError(object=obj)
def oldstate(self, object, serial): def oldstate(self, object, serial):
oid=object._p_oid oid=object._p_oid
p = self._storage.loadSerial(oid, serial) p = self._storage.loadSerial(oid, serial)
...@@ -717,7 +717,7 @@ class Connection(ExportImport.ExportImport, object): ...@@ -717,7 +717,7 @@ class Connection(ExportImport.ExportImport, object):
# the connection does not match what is written to the # the connection does not match what is written to the
# database. Invalidate the object here to guarantee that # database. Invalidate the object here to guarantee that
# the new state is read the next time the object is used. # the new state is read the next time the object is used.
if not store_return: if not store_return:
return return
if isinstance(store_return, StringType): if isinstance(store_return, StringType):
...@@ -757,7 +757,7 @@ class Connection(ExportImport.ExportImport, object): ...@@ -757,7 +757,7 @@ class Connection(ExportImport.ExportImport, object):
def callback(): def callback():
d = {} d = {}
for oid in self._modified: for oid in self._modified:
d[oid] = 1 d[oid] = 1
self._db.invalidate(d, self) self._db.invalidate(d, self)
self._storage.tpc_finish(transaction, callback) self._storage.tpc_finish(transaction, callback)
......
...@@ -13,8 +13,8 @@ ...@@ -13,8 +13,8 @@
############################################################################## ##############################################################################
"""Database objects """Database objects
$Id: DB.py,v 1.54 2003/09/15 16:29:15 jeremy Exp $""" $Id: DB.py,v 1.55 2003/10/02 18:17:19 jeremy Exp $"""
__version__='$Revision: 1.54 $'[11:-2] __version__='$Revision: 1.55 $'[11:-2]
import cPickle, cStringIO, sys, POSException, UndoLogCompatible import cPickle, cStringIO, sys, POSException, UndoLogCompatible
from Connection import Connection from Connection import Connection
...@@ -145,9 +145,9 @@ class DB(UndoLogCompatible.UndoLogCompatible, object): ...@@ -145,9 +145,9 @@ class DB(UndoLogCompatible.UndoLogCompatible, object):
# We need to break circular refs to make it really go. # We need to break circular refs to make it really go.
# XXX What objects are involved in the cycle? # XXX What objects are involved in the cycle?
connection.__dict__.clear() connection.__dict__.clear()
return return
pool.append(connection) pool.append(connection)
if len(pool)==1: if len(pool)==1:
# Pool now usable again, unlock it. # Pool now usable again, unlock it.
......
...@@ -79,7 +79,7 @@ method:: ...@@ -79,7 +79,7 @@ method::
and call it to monitor the storage. and call it to monitor the storage.
""" """
__version__='$Revision: 1.20 $'[11:-2] __version__='$Revision: 1.21 $'[11:-2]
import base64, time, string import base64, time, string
from ZODB import POSException, BaseStorage, utils from ZODB import POSException, BaseStorage, utils
......
...@@ -115,7 +115,7 @@ ...@@ -115,7 +115,7 @@
# may have a back pointer to a version record or to a non-version # may have a back pointer to a version record or to a non-version
# record. # record.
# #
__version__='$Revision: 1.137 $'[11:-2] __version__='$Revision: 1.138 $'[11:-2]
import base64 import base64
from cPickle import Pickler, Unpickler, loads from cPickle import Pickler, Unpickler, loads
...@@ -293,7 +293,7 @@ class FileStorage(BaseStorage.BaseStorage, ...@@ -293,7 +293,7 @@ class FileStorage(BaseStorage.BaseStorage,
self._records_before_save = max(self._records_before_save, self._records_before_save = max(self._records_before_save,
len(self._index)) len(self._index))
self._ltid = tid self._ltid = tid
# self._pos should always point just past the last # self._pos should always point just past the last
# transaction. During 2PC, data is written after _pos. # transaction. During 2PC, data is written after _pos.
# invariant is restored at tpc_abort() or tpc_finish(). # invariant is restored at tpc_abort() or tpc_finish().
...@@ -607,7 +607,7 @@ class FileStorage(BaseStorage.BaseStorage, ...@@ -607,7 +607,7 @@ class FileStorage(BaseStorage.BaseStorage,
self._file.seek(u64(pnv)) self._file.seek(u64(pnv))
h_pnv = self._file.read(DATA_VERSION_HDR_LEN) h_pnv = self._file.read(DATA_VERSION_HDR_LEN)
newserial = h_pnv[8:16] newserial = h_pnv[8:16]
if self._index.get(oid) == srcpos: if self._index.get(oid) == srcpos:
# This is a current record! # This is a current record!
self._tindex[oid] = here self._tindex[oid] = here
...@@ -981,7 +981,7 @@ class FileStorage(BaseStorage.BaseStorage, ...@@ -981,7 +981,7 @@ class FileStorage(BaseStorage.BaseStorage,
else: else:
warn("restore could not find previous non-version data " warn("restore could not find previous non-version data "
"at %d or %d" % (prev, bp)) "at %d or %d" % (prev, bp))
return pnv return pnv
def supportsUndo(self): def supportsUndo(self):
...@@ -1075,7 +1075,7 @@ class FileStorage(BaseStorage.BaseStorage, ...@@ -1075,7 +1075,7 @@ class FileStorage(BaseStorage.BaseStorage,
if fsync is not None: fsync(file.fileno()) if fsync is not None: fsync(file.fileno())
self._pos = nextpos self._pos = nextpos
self._index.update(self._tindex) self._index.update(self._tindex)
self._vindex.update(self._tvindex) self._vindex.update(self._tvindex)
self._oid2serial.update(self._toid2serial) self._oid2serial.update(self._toid2serial)
...@@ -1084,16 +1084,16 @@ class FileStorage(BaseStorage.BaseStorage, ...@@ -1084,16 +1084,16 @@ class FileStorage(BaseStorage.BaseStorage,
del self._oid2serial[oid] del self._oid2serial[oid]
except KeyError: except KeyError:
pass pass
# Update the number of records that we've written # Update the number of records that we've written
# +1 for the transaction record # +1 for the transaction record
self._records_written += len(self._tindex) + 1 self._records_written += len(self._tindex) + 1
if self._records_written >= self._records_before_save: if self._records_written >= self._records_before_save:
self._save_index() self._save_index()
self._records_written = 0 self._records_written = 0
self._records_before_save = max(self._records_before_save, self._records_before_save = max(self._records_before_save,
len(self._index)) len(self._index))
self._ltid = tid self._ltid = tid
def _abort(self): def _abort(self):
...@@ -1538,7 +1538,7 @@ class FileStorage(BaseStorage.BaseStorage, ...@@ -1538,7 +1538,7 @@ class FileStorage(BaseStorage.BaseStorage,
# If the storage is empty, there's nothing to do. # If the storage is empty, there's nothing to do.
if not self._index: if not self._index:
return return
# Record pack time so we don't undo while packing # Record pack time so we don't undo while packing
self._lock_acquire() self._lock_acquire()
try: try:
......
...@@ -13,7 +13,7 @@ ...@@ -13,7 +13,7 @@
############################################################################## ##############################################################################
"""ZODB-defined exceptions """ZODB-defined exceptions
$Id: POSException.py,v 1.20 2003/06/10 15:46:31 shane Exp $""" $Id: POSException.py,v 1.21 2003/10/02 18:17:19 jeremy Exp $"""
from types import StringType, DictType from types import StringType, DictType
from ZODB.utils import oid_repr, serial_repr from ZODB.utils import oid_repr, serial_repr
...@@ -173,7 +173,7 @@ class UndoError(POSError): ...@@ -173,7 +173,7 @@ class UndoError(POSError):
class MultipleUndoErrors(UndoError): class MultipleUndoErrors(UndoError):
"""Several undo errors occured during a single transaction.""" """Several undo errors occured during a single transaction."""
def __init__(self, errs): def __init__(self, errs):
# provide a reason and oid for clients that only look at that # provide a reason and oid for clients that only look at that
UndoError.__init__(self, *errs[0]) UndoError.__init__(self, *errs[0])
......
...@@ -42,7 +42,7 @@ class TmpStore: ...@@ -42,7 +42,7 @@ class TmpStore:
def getName(self): def getName(self):
return self._db.getName() return self._db.getName()
def getSize(self): def getSize(self):
return self._pos return self._pos
......
...@@ -13,7 +13,7 @@ ...@@ -13,7 +13,7 @@
############################################################################## ##############################################################################
"""Transaction management """Transaction management
$Id: Transaction.py,v 1.49 2003/06/10 15:46:31 shane Exp $ $Id: Transaction.py,v 1.50 2003/10/02 18:17:19 jeremy Exp $
""" """
import time, sys, struct, POSException import time, sys, struct, POSException
...@@ -43,7 +43,7 @@ def jar_cmp(j1, j2): ...@@ -43,7 +43,7 @@ def jar_cmp(j1, j2):
except: except:
LOG("TM", WARNING, "jar missing sortKey() method: %s" % j2) LOG("TM", WARNING, "jar missing sortKey() method: %s" % j2)
k2 = id(j2) k2 = id(j2)
return cmp(k1, k2) return cmp(k1, k2)
class Transaction: class Transaction:
...@@ -271,12 +271,12 @@ class Transaction: ...@@ -271,12 +271,12 @@ class Transaction:
def _get_jars(self, objects, subtransaction): def _get_jars(self, objects, subtransaction):
# Returns a list of jars for this transaction. # Returns a list of jars for this transaction.
# Find all the jars and sort them in a globally consistent order. # Find all the jars and sort them in a globally consistent order.
# objects is a list of persistent objects and jars. # objects is a list of persistent objects and jars.
# If this is a subtransaction and a jar is not subtransaction aware, # If this is a subtransaction and a jar is not subtransaction aware,
# it's object gets delayed until the parent transaction commits. # it's object gets delayed until the parent transaction commits.
d = {} d = {}
for o in objects: for o in objects:
jar = getattr(o, '_p_jar', o) jar = getattr(o, '_p_jar', o)
...@@ -298,7 +298,7 @@ class Transaction: ...@@ -298,7 +298,7 @@ class Transaction:
if self._non_st_objects is None: if self._non_st_objects is None:
self._non_st_objects = [] self._non_st_objects = []
self._non_st_objects.append(o) self._non_st_objects.append(o)
jars = d.values() jars = d.values()
jars.sort(jar_cmp) jars.sort(jar_cmp)
...@@ -406,7 +406,7 @@ class Transaction: ...@@ -406,7 +406,7 @@ class Transaction:
# After the tpc_abort(), call abort_sub() on all the # After the tpc_abort(), call abort_sub() on all the
# subtrans-aware jars to *really* abort the subtransaction. # subtrans-aware jars to *really* abort the subtransaction.
# Example: For Connection(), the tpc_abort() will abort the # Example: For Connection(), the tpc_abort() will abort the
# subtransaction TmpStore() and abort_sub() will remove the # subtransaction TmpStore() and abort_sub() will remove the
# TmpStore. # TmpStore.
......
...@@ -12,7 +12,7 @@ ...@@ -12,7 +12,7 @@
# #
############################################################################## ##############################################################################
__version__ = '3.2b2' __version__ = '3.2c1'
import sys import sys
import cPersistence, Persistence import cPersistence, Persistence
......
...@@ -90,7 +90,7 @@ process must skip such objects, rather than deactivating them. ...@@ -90,7 +90,7 @@ process must skip such objects, rather than deactivating them.
static char cPickleCache_doc_string[] = static char cPickleCache_doc_string[] =
"Defines the PickleCache used by ZODB Connection objects.\n" "Defines the PickleCache used by ZODB Connection objects.\n"
"\n" "\n"
"$Id: cPickleCache.c,v 1.85 2003/05/30 19:20:55 jeremy Exp $\n"; "$Id: cPickleCache.c,v 1.86 2003/10/02 18:17:19 jeremy Exp $\n";
#define ASSIGN(V,E) {PyObject *__e; __e=(E); Py_XDECREF(V); (V)=__e;} #define ASSIGN(V,E) {PyObject *__e; __e=(E); Py_XDECREF(V); (V)=__e;}
#define UNLESS(E) if(!(E)) #define UNLESS(E) if(!(E))
...@@ -499,6 +499,17 @@ cc_clear(ccobject *self, PyObject *args) ...@@ -499,6 +499,17 @@ cc_clear(ccobject *self, PyObject *args)
Py_DECREF(o); Py_DECREF(o);
} }
self->ring_lock = 0; self->ring_lock = 0;
/* Free two references to the Connection, which can't be discovered
via garbage collection.
*/
Py_XDECREF(self->setklassstate);
self->setklassstate = NULL;
Py_XDECREF(self->jar);
self->jar = NULL;
Py_INCREF(Py_None); Py_INCREF(Py_None);
return Py_None; return Py_None;
} }
......
...@@ -13,7 +13,7 @@ ...@@ -13,7 +13,7 @@
############################################################################## ##############################################################################
"""Open database and storage from a configuration. """Open database and storage from a configuration.
$Id: config.py,v 1.14 2003/09/15 16:29:15 jeremy Exp $""" $Id: config.py,v 1.15 2003/10/02 18:17:19 jeremy Exp $"""
import os import os
from cStringIO import StringIO from cStringIO import StringIO
......
...@@ -192,7 +192,7 @@ class FileStorageFormatter: ...@@ -192,7 +192,7 @@ class FileStorageFormatter:
if dh.plen: if dh.plen:
self.fail(pos, "data record has back pointer and data") self.fail(pos, "data record has back pointer and data")
def DataHeaderFromString(s): def DataHeaderFromString(s):
return DataHeader(*struct.unpack(DATA_HDR, s)) return DataHeader(*struct.unpack(DATA_HDR, s))
class DataHeader: class DataHeader:
...@@ -338,7 +338,7 @@ class DataCopier(FileStorageFormatter): ...@@ -338,7 +338,7 @@ class DataCopier(FileStorageFormatter):
return pos return pos
pos += h.recordlen() pos += h.recordlen()
return 0 return 0
def _restore_pnv(self, oid, prev, version, bp): def _restore_pnv(self, oid, prev, version, bp):
# Find a valid pnv (previous non-version) pointer for this version. # Find a valid pnv (previous non-version) pointer for this version.
...@@ -415,7 +415,7 @@ class DataCopier(FileStorageFormatter): ...@@ -415,7 +415,7 @@ class DataCopier(FileStorageFormatter):
self._tfile.write(z64) self._tfile.write(z64)
else: else:
self._tfile.write(data) self._tfile.write(data)
class GC(FileStorageFormatter): class GC(FileStorageFormatter):
def __init__(self, file, eof, packtime): def __init__(self, file, eof, packtime):
...@@ -437,7 +437,7 @@ class GC(FileStorageFormatter): ...@@ -437,7 +437,7 @@ class GC(FileStorageFormatter):
# second is a dictionary mapping objects to lists of # second is a dictionary mapping objects to lists of
# positions; it is used to handle the same number of objects # positions; it is used to handle the same number of objects
# for which we must keep multiple revisions. # for which we must keep multiple revisions.
self.reachable = fsIndex() self.reachable = fsIndex()
self.reach_ex = {} self.reach_ex = {}
...@@ -460,7 +460,7 @@ class GC(FileStorageFormatter): ...@@ -460,7 +460,7 @@ class GC(FileStorageFormatter):
self.findReachableFromFuture() self.findReachableFromFuture()
# These mappings are no longer needed and may consume a lot # These mappings are no longer needed and may consume a lot
# of space. # of space.
del self.oid2verpos del self.oid2verpos
del self.oid2curpos del self.oid2curpos
def buildPackIndex(self): def buildPackIndex(self):
...@@ -528,7 +528,7 @@ class GC(FileStorageFormatter): ...@@ -528,7 +528,7 @@ class GC(FileStorageFormatter):
# non-current revision could refer to objects that were # non-current revision could refer to objects that were
# otherwise unreachable at the packtime. # otherwise unreachable at the packtime.
extra_roots = [] extra_roots = []
pos = self.packpos pos = self.packpos
while pos < self.eof: while pos < self.eof:
th = self._read_txn_header(pos) th = self._read_txn_header(pos)
...@@ -558,7 +558,7 @@ class GC(FileStorageFormatter): ...@@ -558,7 +558,7 @@ class GC(FileStorageFormatter):
extra_roots.append(dh.pnv) extra_roots.append(dh.pnv)
else: else:
self.reachable[dh.oid] = dh.back self.reachable[dh.oid] = dh.back
pos += dh.recordlen() pos += dh.recordlen()
tlen = self._read_num(pos) tlen = self._read_num(pos)
...@@ -631,7 +631,7 @@ class FileStoragePacker(FileStorageFormatter): ...@@ -631,7 +631,7 @@ class FileStoragePacker(FileStorageFormatter):
self._file.seek(0, 2) self._file.seek(0, 2)
self.file_end = self._file.tell() self.file_end = self._file.tell()
self._file.seek(0) self._file.seek(0)
self.gc = GC(self._file, self.file_end, self._stop) self.gc = GC(self._file, self.file_end, self._stop)
# The packer needs to acquire the parent's commit lock # The packer needs to acquire the parent's commit lock
...@@ -672,7 +672,7 @@ class FileStoragePacker(FileStorageFormatter): ...@@ -672,7 +672,7 @@ class FileStoragePacker(FileStorageFormatter):
# Txn and data records contain pointers to previous records. # Txn and data records contain pointers to previous records.
# Because these pointers are stored as file offsets, they # Because these pointers are stored as file offsets, they
# must be updated when we copy data. # must be updated when we copy data.
# XXX Need to add sanity checking to pack # XXX Need to add sanity checking to pack
self.gc.findReachable() self.gc.findReachable()
...@@ -730,7 +730,7 @@ class FileStoragePacker(FileStorageFormatter): ...@@ -730,7 +730,7 @@ class FileStoragePacker(FileStorageFormatter):
self._tfile.seek(new_pos - 8) self._tfile.seek(new_pos - 8)
self._tfile.write(p64(tlen)) self._tfile.write(p64(tlen))
tlen = self._read_num(pos) tlen = self._read_num(pos)
if tlen != th.tlen: if tlen != th.tlen:
self.fail(pos, "redundant transaction length does not " self.fail(pos, "redundant transaction length does not "
...@@ -757,7 +757,7 @@ class FileStoragePacker(FileStorageFormatter): ...@@ -757,7 +757,7 @@ class FileStoragePacker(FileStorageFormatter):
Returns position of txn header in output file and position Returns position of txn header in output file and position
of next record in the input file. of next record in the input file.
If any data records are copied, also write txn header (th). If any data records are copied, also write txn header (th).
""" """
copy = 0 copy = 0
...@@ -878,4 +878,3 @@ class FileStoragePacker(FileStorageFormatter): ...@@ -878,4 +878,3 @@ class FileStoragePacker(FileStorageFormatter):
if self._lock_counter % 20 == 0: if self._lock_counter % 20 == 0:
self._commit_lock_acquire() self._commit_lock_acquire()
return ipos return ipos
...@@ -227,7 +227,7 @@ def main(): ...@@ -227,7 +227,7 @@ def main():
except getopt.error: except getopt.error:
die() die()
print __doc__ % argv[0] print __doc__ % argv[0]
force = partial = verbose = 0 force = partial = verbose = 0
pack = None pack = None
for opt, v in opts: for opt, v in opts:
...@@ -321,7 +321,7 @@ def recover(inp, outp, verbose=0, partial=0, force=0, pack=0): ...@@ -321,7 +321,7 @@ def recover(inp, outp, verbose=0, partial=0, force=0, pack=0):
l = "bp" l = "bp"
else: else:
l = len(r.data) l = len(r.data)
print "%7d %s %s" % (u64(r.oid), l, r.version) print "%7d %s %s" % (u64(r.oid), l, r.version)
s = ofs.restore(r.oid, r.serial, r.data, r.version, s = ofs.restore(r.oid, r.serial, r.data, r.version,
r.data_txn, txn) r.data_txn, txn)
...@@ -372,4 +372,3 @@ def recover(inp, outp, verbose=0, partial=0, force=0, pack=0): ...@@ -372,4 +372,3 @@ def recover(inp, outp, verbose=0, partial=0, force=0, pack=0):
if __name__ == "__main__": if __name__ == "__main__":
main() main()
...@@ -2,14 +2,14 @@ ...@@ -2,14 +2,14 @@
# #
# Copyright (c) 2001, 2002 Zope Corporation and Contributors. # Copyright (c) 2001, 2002 Zope Corporation and Contributors.
# All Rights Reserved. # All Rights Reserved.
# #
# This software is subject to the provisions of the Zope Public License, # 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. # 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 # THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED # WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS # WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
# FOR A PARTICULAR PURPOSE. # FOR A PARTICULAR PURPOSE.
# #
############################################################################## ##############################################################################
"""Run the basic tests for a storage as described in the official storage API """Run the basic tests for a storage as described in the official storage API
......
...@@ -2,14 +2,14 @@ ...@@ -2,14 +2,14 @@
# #
# Copyright (c) 2001, 2002 Zope Corporation and Contributors. # Copyright (c) 2001, 2002 Zope Corporation and Contributors.
# All Rights Reserved. # All Rights Reserved.
# #
# This software is subject to the provisions of the Zope Public License, # 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. # 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 # THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED # WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS # WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
# FOR A PARTICULAR PURPOSE. # FOR A PARTICULAR PURPOSE.
# #
############################################################################## ##############################################################################
"""Tests for application-level conflict resolution.""" """Tests for application-level conflict resolution."""
......
...@@ -2,14 +2,14 @@ ...@@ -2,14 +2,14 @@
# #
# Copyright (c) 2001, 2002 Zope Corporation and Contributors. # Copyright (c) 2001, 2002 Zope Corporation and Contributors.
# All Rights Reserved. # All Rights Reserved.
# #
# This software is subject to the provisions of the Zope Public License, # 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. # 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 # THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED # WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS # WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
# FOR A PARTICULAR PURPOSE. # FOR A PARTICULAR PURPOSE.
# #
############################################################################## ##############################################################################
"""Do some minimal tests of data corruption""" """Do some minimal tests of data corruption"""
......
...@@ -2,14 +2,14 @@ ...@@ -2,14 +2,14 @@
# #
# Copyright (c) 2001, 2002 Zope Corporation and Contributors. # Copyright (c) 2001, 2002 Zope Corporation and Contributors.
# All Rights Reserved. # All Rights Reserved.
# #
# This software is subject to the provisions of the Zope Public License, # 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. # 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 # THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED # WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS # WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
# FOR A PARTICULAR PURPOSE. # FOR A PARTICULAR PURPOSE.
# #
############################################################################## ##############################################################################
"""Run the history() related tests for a storage. """Run the history() related tests for a storage.
......
...@@ -2,14 +2,14 @@ ...@@ -2,14 +2,14 @@
# #
# Copyright (c) 2001, 2002 Zope Corporation and Contributors. # Copyright (c) 2001, 2002 Zope Corporation and Contributors.
# All Rights Reserved. # All Rights Reserved.
# #
# This software is subject to the provisions of the Zope Public License, # 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. # 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 # THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED # WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS # WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
# FOR A PARTICULAR PURPOSE. # FOR A PARTICULAR PURPOSE.
# #
############################################################################## ##############################################################################
"""Run tests against the iterator() interface for storages. """Run tests against the iterator() interface for storages.
......
...@@ -2,14 +2,14 @@ ...@@ -2,14 +2,14 @@
# #
# Copyright (c) 2001, 2002 Zope Corporation and Contributors. # Copyright (c) 2001, 2002 Zope Corporation and Contributors.
# All Rights Reserved. # All Rights Reserved.
# #
# This software is subject to the provisions of the Zope Public License, # 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. # 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 # THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED # WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS # WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
# FOR A PARTICULAR PURPOSE. # FOR A PARTICULAR PURPOSE.
# #
############################################################################## ##############################################################################
class LocalStorage: class LocalStorage:
"""A single test that only make sense for local storages. """A single test that only make sense for local storages.
......
...@@ -96,7 +96,6 @@ class ZODBClientThread(TestThread): ...@@ -96,7 +96,6 @@ class ZODBClientThread(TestThread):
return root.get(name) return root.get(name)
except ConflictError: except ConflictError:
get_transaction().abort() get_transaction().abort()
root._p_jar.sync()
class StorageClientThread(TestThread): class StorageClientThread(TestThread):
......
...@@ -2,14 +2,14 @@ ...@@ -2,14 +2,14 @@
# #
# Copyright (c) 2001, 2002 Zope Corporation and Contributors. # Copyright (c) 2001, 2002 Zope Corporation and Contributors.
# All Rights Reserved. # All Rights Reserved.
# #
# This software is subject to the provisions of the Zope Public License, # 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. # 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 # THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED # WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS # WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
# FOR A PARTICULAR PURPOSE. # FOR A PARTICULAR PURPOSE.
# #
############################################################################## ##############################################################################
"""A minimal persistent object to use for tests""" """A minimal persistent object to use for tests"""
......
...@@ -2,14 +2,14 @@ ...@@ -2,14 +2,14 @@
# #
# Copyright (c) 2001, 2002 Zope Corporation and Contributors. # Copyright (c) 2001, 2002 Zope Corporation and Contributors.
# All Rights Reserved. # All Rights Reserved.
# #
# This software is subject to the provisions of the Zope Public License, # 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. # 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 # THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED # WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS # WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
# FOR A PARTICULAR PURPOSE. # FOR A PARTICULAR PURPOSE.
# #
############################################################################## ##############################################################################
"""Run some tests relevant for storages that support pack().""" """Run some tests relevant for storages that support pack()."""
...@@ -472,13 +472,13 @@ class PackableStorage(PackableStorageBase): ...@@ -472,13 +472,13 @@ class PackableStorage(PackableStorageBase):
obj2 = self._newobj() obj2 = self._newobj()
oid2 = obj2.getoid() oid2 = obj2.getoid()
obj2.value = 2 obj2.value = 2
# Commit the first revision of each of them # Commit the first revision of each of them
revid11 = self._dostoreNP(oid1, data=pickle.dumps(obj1), revid11 = self._dostoreNP(oid1, data=pickle.dumps(obj1),
description="1-1") description="1-1")
revid22 = self._dostoreNP(oid2, data=pickle.dumps(obj2), revid22 = self._dostoreNP(oid2, data=pickle.dumps(obj2),
description="2-2") description="2-2")
# remember the time. everything above here will be packed away # remember the time. everything above here will be packed away
snooze() snooze()
packtime = time.time() packtime = time.time()
...@@ -509,7 +509,7 @@ class ClientThread(threading.Thread): ...@@ -509,7 +509,7 @@ class ClientThread(threading.Thread):
def __init__(self, db): def __init__(self, db):
threading.Thread.__init__(self) threading.Thread.__init__(self)
self.root = db.open().root() self.root = db.open().root()
def run(self): def run(self):
for j in range(50): for j in range(50):
try: try:
......
...@@ -2,14 +2,14 @@ ...@@ -2,14 +2,14 @@
# #
# Copyright (c) 2001, 2002 Zope Corporation and Contributors. # Copyright (c) 2001, 2002 Zope Corporation and Contributors.
# All Rights Reserved. # All Rights Reserved.
# #
# This software is subject to the provisions of the Zope Public License, # 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. # 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 # THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED # WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS # WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
# FOR A PARTICULAR PURPOSE. # FOR A PARTICULAR PURPOSE.
# #
############################################################################## ##############################################################################
"""Test that a storage's values persist across open and close.""" """Test that a storage's values persist across open and close."""
......
...@@ -2,14 +2,14 @@ ...@@ -2,14 +2,14 @@
# #
# Copyright (c) 2001, 2002 Zope Corporation and Contributors. # Copyright (c) 2001, 2002 Zope Corporation and Contributors.
# All Rights Reserved. # All Rights Reserved.
# #
# This software is subject to the provisions of the Zope Public License, # 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. # 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 # THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED # WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS # WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
# FOR A PARTICULAR PURPOSE. # FOR A PARTICULAR PURPOSE.
# #
############################################################################## ##############################################################################
from ZODB.POSException import ReadOnlyError from ZODB.POSException import ReadOnlyError
from ZODB.Transaction import Transaction from ZODB.Transaction import Transaction
......
...@@ -2,14 +2,14 @@ ...@@ -2,14 +2,14 @@
# #
# Copyright (c) 2001, 2002 Zope Corporation and Contributors. # Copyright (c) 2001, 2002 Zope Corporation and Contributors.
# All Rights Reserved. # All Rights Reserved.
# #
# This software is subject to the provisions of the Zope Public License, # 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. # 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 # THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED # WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS # WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
# FOR A PARTICULAR PURPOSE. # FOR A PARTICULAR PURPOSE.
# #
############################################################################## ##############################################################################
"""More recovery and iterator tests.""" """More recovery and iterator tests."""
...@@ -71,7 +71,7 @@ class RecoveryStorage(IteratorDeepCompare): ...@@ -71,7 +71,7 @@ class RecoveryStorage(IteratorDeepCompare):
self.assertRaises(IndexError, lambda i, t=trans: t[i], 1) self.assertRaises(IndexError, lambda i, t=trans: t[i], 1)
self.assertEqual(data.oid, oid) self.assertEqual(data.oid, oid)
self.assertEqual(data.data, None) self.assertEqual(data.data, None)
def checkRecoverUndoInVersion(self): def checkRecoverUndoInVersion(self):
oid = self._storage.new_oid() oid = self._storage.new_oid()
version = "aVersion" version = "aVersion"
...@@ -128,7 +128,7 @@ class RecoveryStorage(IteratorDeepCompare): ...@@ -128,7 +128,7 @@ class RecoveryStorage(IteratorDeepCompare):
self._dst = self.new_dest() self._dst = self.new_dest()
self._dst.copyTransactionsFrom(self._storage) self._dst.copyTransactionsFrom(self._storage)
self.compare(self._storage, self._dst) self.compare(self._storage, self._dst)
def checkRestoreAcrossPack(self): def checkRestoreAcrossPack(self):
db = DB(self._storage) db = DB(self._storage)
c = db.open() c = db.open()
......
...@@ -2,14 +2,14 @@ ...@@ -2,14 +2,14 @@
# #
# Copyright (c) 2001, 2002 Zope Corporation and Contributors. # Copyright (c) 2001, 2002 Zope Corporation and Contributors.
# All Rights Reserved. # All Rights Reserved.
# #
# This software is subject to the provisions of the Zope Public License, # 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. # 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 # THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED # WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS # WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
# FOR A PARTICULAR PURPOSE. # FOR A PARTICULAR PURPOSE.
# #
############################################################################## ##############################################################################
"""Check loadSerial() on storages that support historical revisions.""" """Check loadSerial() on storages that support historical revisions."""
......
...@@ -2,14 +2,14 @@ ...@@ -2,14 +2,14 @@
# #
# Copyright (c) 2001, 2002 Zope Corporation and Contributors. # Copyright (c) 2001, 2002 Zope Corporation and Contributors.
# All Rights Reserved. # All Rights Reserved.
# #
# This software is subject to the provisions of the Zope Public License, # 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. # 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 # THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED # WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS # WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
# FOR A PARTICULAR PURPOSE. # FOR A PARTICULAR PURPOSE.
# #
############################################################################## ##############################################################################
"""Provide a mixin base class for storage tests. """Provide a mixin base class for storage tests.
...@@ -210,7 +210,7 @@ class StorageTestBase(unittest.TestCase): ...@@ -210,7 +210,7 @@ class StorageTestBase(unittest.TestCase):
def _dostoreNP(self, oid=None, revid=None, data=None, version=None, def _dostoreNP(self, oid=None, revid=None, data=None, version=None,
user=None, description=None): user=None, description=None):
return self._dostore(oid, revid, data, version, 1, user, description) return self._dostore(oid, revid, data, version, 1, user, description)
# The following methods depend on optional storage features. # The following methods depend on optional storage features.
def _undo(self, tid, oid=None): def _undo(self, tid, oid=None):
......
...@@ -2,14 +2,14 @@ ...@@ -2,14 +2,14 @@
# #
# Copyright (c) 2001, 2002 Zope Corporation and Contributors. # Copyright (c) 2001, 2002 Zope Corporation and Contributors.
# All Rights Reserved. # All Rights Reserved.
# #
# This software is subject to the provisions of the Zope Public License, # 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. # 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 # THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED # WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS # WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
# FOR A PARTICULAR PURPOSE. # FOR A PARTICULAR PURPOSE.
# #
############################################################################## ##############################################################################
"""Test the storage's implemenetation of the storage synchronization spec. """Test the storage's implemenetation of the storage synchronization spec.
......
...@@ -42,7 +42,7 @@ def snooze(): ...@@ -42,7 +42,7 @@ def snooze():
now = time.time() now = time.time()
while now == time.time(): while now == time.time():
time.sleep(0.1) time.sleep(0.1)
def listeq(L1, L2): def listeq(L1, L2):
"""Return True if L1.sort() == L2.sort()""" """Return True if L1.sort() == L2.sort()"""
c1 = L1[:] c1 = L1[:]
...@@ -608,11 +608,11 @@ class TransactionalUndoStorage: ...@@ -608,11 +608,11 @@ class TransactionalUndoStorage:
txn.commit() txn.commit()
set_pack_time() set_pack_time()
root._p_deactivate() root._p_deactivate()
cn.sync() cn.sync()
self.assert_(listeq(root.keys(), ["key0", "key2"])) self.assert_(listeq(root.keys(), ["key0", "key2"]))
L = db.undoInfo() L = db.undoInfo()
db.undo(L[0]["id"]) db.undo(L[0]["id"])
txn = get_transaction() txn = get_transaction()
...@@ -624,7 +624,7 @@ class TransactionalUndoStorage: ...@@ -624,7 +624,7 @@ class TransactionalUndoStorage:
root._p_deactivate() root._p_deactivate()
cn.sync() cn.sync()
self.assert_(listeq(root.keys(), ["key0", "key1", "key2"])) self.assert_(listeq(root.keys(), ["key0", "key1", "key2"]))
for t in pack_times: for t in pack_times:
self._storage.pack(t, referencesf) self._storage.pack(t, referencesf)
...@@ -663,7 +663,7 @@ class TransactionalUndoStorage: ...@@ -663,7 +663,7 @@ class TransactionalUndoStorage:
self.assertEqual(rt["test"].value, i % 2 and 3 or 1) self.assertEqual(rt["test"].value, i % 2 and 3 or 1)
self.assertEqual(rt["test2"].value, 2) self.assertEqual(rt["test2"].value, 2)
packtimes.append(time.time()) packtimes.append(time.time())
snooze() snooze()
...@@ -723,7 +723,7 @@ class TransactionalUndoStorage: ...@@ -723,7 +723,7 @@ class TransactionalUndoStorage:
s.transactionalUndo(tid, t) s.transactionalUndo(tid, t)
s.tpc_vote(t) s.tpc_vote(t)
s.tpc_finish(t) s.tpc_finish(t)
for i in range(BATCHES): for i in range(BATCHES):
undo(i) undo(i)
...@@ -740,14 +740,14 @@ class TransactionalUndoStorage: ...@@ -740,14 +740,14 @@ class TransactionalUndoStorage:
for i in range(BATCHES): for i in range(BATCHES):
txn = iter[offset] txn = iter[offset]
offset += 1 offset += 1
tid = p64(i + 1) tid = p64(i + 1)
eq(txn.tid, tid) eq(txn.tid, tid)
L1 = [(rec.oid, rec.serial, rec.data_txn) for rec in txn] L1 = [(rec.oid, rec.serial, rec.data_txn) for rec in txn]
L2 = [(oid, revid, None) for _tid, oid, revid in orig L2 = [(oid, revid, None) for _tid, oid, revid in orig
if _tid == tid] if _tid == tid]
eq(L1, L2) eq(L1, L2)
for i in range(BATCHES * OBJECTS): for i in range(BATCHES * OBJECTS):
...@@ -789,5 +789,3 @@ class TransactionalUndoStorage: ...@@ -789,5 +789,3 @@ class TransactionalUndoStorage:
self.assertEqual(d['description'],'t1') self.assertEqual(d['description'],'t1')
self.assertEqual(d['k2'],'this is transaction metadata') self.assertEqual(d['k2'],'this is transaction metadata')
self.assertEqual(d['user_name'],'p3 u3') self.assertEqual(d['user_name'],'p3 u3')
...@@ -2,14 +2,14 @@ ...@@ -2,14 +2,14 @@
# #
# Copyright (c) 2001, 2002 Zope Corporation and Contributors. # Copyright (c) 2001, 2002 Zope Corporation and Contributors.
# All Rights Reserved. # All Rights Reserved.
# #
# This software is subject to the provisions of the Zope Public License, # 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. # 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 # THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED # WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS # WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
# FOR A PARTICULAR PURPOSE. # FOR A PARTICULAR PURPOSE.
# #
############################################################################## ##############################################################################
from __future__ import nested_scopes from __future__ import nested_scopes
...@@ -60,7 +60,7 @@ class TransactionalUndoVersionStorage: ...@@ -60,7 +60,7 @@ class TransactionalUndoVersionStorage:
self.assertEqual(zodb_unpickle(data), MinPO(versiondata)) self.assertEqual(zodb_unpickle(data), MinPO(versiondata))
data, revid = self._storage.load(oid, '') data, revid = self._storage.load(oid, '')
self.assertEqual(zodb_unpickle(data), MinPO(nonversiondata)) self.assertEqual(zodb_unpickle(data), MinPO(nonversiondata))
oid = self._storage.new_oid() oid = self._storage.new_oid()
version = 'one' version = 'one'
revid_a = self._dostore(oid, data=MinPO(91)) revid_a = self._dostore(oid, data=MinPO(91))
...@@ -68,17 +68,17 @@ class TransactionalUndoVersionStorage: ...@@ -68,17 +68,17 @@ class TransactionalUndoVersionStorage:
version=version) version=version)
revid_c = self._dostore(oid, revid=revid_b, data=MinPO(93), revid_c = self._dostore(oid, revid=revid_b, data=MinPO(93),
version=version) version=version)
info = self._storage.undoInfo() info = self._storage.undoInfo()
self._undo(info[0]['id'], oid) self._undo(info[0]['id'], oid)
data, revid = self._storage.load(oid, '') data, revid = self._storage.load(oid, '')
eq(revid, revid_a) eq(revid, revid_a)
eq(zodb_unpickle(data), MinPO(91)) eq(zodb_unpickle(data), MinPO(91))
data, revid = self._storage.load(oid, version) data, revid = self._storage.load(oid, version)
unless(revid > revid_b and revid > revid_c) unless(revid > revid_b and revid > revid_c)
eq(zodb_unpickle(data), MinPO(92)) eq(zodb_unpickle(data), MinPO(92))
# Now commit the version... # Now commit the version...
t = Transaction() t = Transaction()
self._storage.tpc_begin(t) self._storage.tpc_begin(t)
...@@ -89,7 +89,7 @@ class TransactionalUndoVersionStorage: ...@@ -89,7 +89,7 @@ class TransactionalUndoVersionStorage:
eq(oids[0], oid) eq(oids[0], oid)
check_objects(92, 92) check_objects(92, 92)
# ...and undo the commit # ...and undo the commit
info = self._storage.undoInfo() info = self._storage.undoInfo()
self._undo(info[0]['id'], oid) self._undo(info[0]['id'], oid)
...@@ -101,11 +101,11 @@ class TransactionalUndoVersionStorage: ...@@ -101,11 +101,11 @@ class TransactionalUndoVersionStorage:
assert oids[0] == oid assert oids[0] == oid
check_objects(91, 91) check_objects(91, 91)
# Now undo the abort # Now undo the abort
info=self._storage.undoInfo() info=self._storage.undoInfo()
self._undo(info[0]['id'], oid) self._undo(info[0]['id'], oid)
check_objects(91, 92) check_objects(91, 92)
def checkUndoCommitVersion(self): def checkUndoCommitVersion(self):
......
...@@ -493,7 +493,7 @@ class VersionStorage: ...@@ -493,7 +493,7 @@ class VersionStorage:
self._storage.pack(time.time(), referencesf) self._storage.pack(time.time(), referencesf)
cn.sync() cn.sync()
cn._cache.clear() cn._cache.clear()
# make sure all the non-version data is there # make sure all the non-version data is there
for name, obj in root.items(): for name, obj in root.items():
self.assertEqual(name, obj.value) self.assertEqual(name, obj.value)
...@@ -516,16 +516,15 @@ class VersionStorage: ...@@ -516,16 +516,15 @@ class VersionStorage:
t = time.time() t = time.time()
snooze() snooze()
L = db.undoInfo() L = db.undoInfo()
db.undo(L[0]["id"]) db.undo(L[0]["id"])
txn = get_transaction() txn = get_transaction()
txn.note("undo abort") txn.note("undo abort")
txn.commit() txn.commit()
self._storage.pack(t, referencesf) self._storage.pack(t, referencesf)
cn2 = db.open(version="b") cn2 = db.open(version="b")
rt2 = cn2.root() rt2 = cn2.root()
self.assertEqual(rt2["b"].value.value, "still version") self.assertEqual(rt2["b"].value.value, "still version")
...@@ -4,14 +4,14 @@ ...@@ -4,14 +4,14 @@
# #
# Copyright (c) 2002 Zope Corporation and Contributors. # Copyright (c) 2002 Zope Corporation and Contributors.
# All Rights Reserved. # All Rights Reserved.
# #
# This software is subject to the provisions of the Zope Public License, # 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. # 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 # THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED # WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS # WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
# FOR A PARTICULAR PURPOSE # FOR A PARTICULAR PURPOSE
# #
############################################################################## ##############################################################################
"""Functional test to produce a dangling reference.""" """Functional test to produce a dangling reference."""
...@@ -61,6 +61,6 @@ def main(): ...@@ -61,6 +61,6 @@ def main():
db = DB(fs) db = DB(fs)
create_dangling_ref(db) create_dangling_ref(db)
db.close() db.close()
if __name__ == "__main__": if __name__ == "__main__":
main() main()
...@@ -2,14 +2,14 @@ ...@@ -2,14 +2,14 @@
# #
# Copyright (c) 2001, 2002 Zope Corporation and Contributors. # Copyright (c) 2001, 2002 Zope Corporation and Contributors.
# All Rights Reserved. # All Rights Reserved.
# #
# This software is subject to the provisions of the Zope Public License, # 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. # 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 # THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED # WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS # WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
# FOR A PARTICULAR PURPOSE. # FOR A PARTICULAR PURPOSE.
# #
############################################################################## ##############################################################################
"""A few simple tests of the public cache API. """A few simple tests of the public cache API.
......
...@@ -56,6 +56,7 @@ class ZODBConfigTest(ConfigTestBase): ...@@ -56,6 +56,7 @@ class ZODBConfigTest(ConfigTestBase):
""") """)
def test_file_config1(self): def test_file_config1(self):
import ZODB.FileStorage
path = tempfile.mktemp() path = tempfile.mktemp()
self._test( self._test(
""" """
...@@ -65,9 +66,10 @@ class ZODBConfigTest(ConfigTestBase): ...@@ -65,9 +66,10 @@ class ZODBConfigTest(ConfigTestBase):
</filestorage> </filestorage>
</zodb> </zodb>
""" % path) """ % path)
os.unlink(path) ZODB.FileStorage.cleanup(path)
def test_file_config2(self): def test_file_config2(self):
import ZODB.FileStorage
path = tempfile.mktemp() path = tempfile.mktemp()
cfg = """ cfg = """
<zodb> <zodb>
...@@ -79,6 +81,7 @@ class ZODBConfigTest(ConfigTestBase): ...@@ -79,6 +81,7 @@ class ZODBConfigTest(ConfigTestBase):
</zodb> </zodb>
""" % path """ % path
self.assertRaises(ReadOnlyError, self._test, cfg) self.assertRaises(ReadOnlyError, self._test, cfg)
ZODB.FileStorage.cleanup(path)
def test_zeo_config(self): def test_zeo_config(self):
# We're looking for a port that doesn't exist so a connection attempt # We're looking for a port that doesn't exist so a connection attempt
......
...@@ -2,14 +2,14 @@ ...@@ -2,14 +2,14 @@
# #
# Copyright (c) 2001, 2002 Zope Corporation and Contributors. # Copyright (c) 2001, 2002 Zope Corporation and Contributors.
# All Rights Reserved. # All Rights Reserved.
# #
# This software is subject to the provisions of the Zope Public License, # 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. # 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 # THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED # WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS # WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
# FOR A PARTICULAR PURPOSE. # FOR A PARTICULAR PURPOSE.
# #
############################################################################## ##############################################################################
import os import os
import time import time
...@@ -57,14 +57,14 @@ class DBTests(unittest.TestCase): ...@@ -57,14 +57,14 @@ class DBTests(unittest.TestCase):
# Test that we can remove a version pool # Test that we can remove a version pool
# This is white box because we check some internal data structures # This is white box because we check some internal data structures
self.dowork() self.dowork()
self.dowork('v2') self.dowork('v2')
c1 = self.db.open('v1') c1 = self.db.open('v1')
c1.close() # return to pool c1.close() # return to pool
c12 = self.db.open('v1') c12 = self.db.open('v1')
c12.close() # return to pool c12.close() # return to pool
self.assert_(c1 is c12) # should be same self.assert_(c1 is c12) # should be same
pools, pooll = self.db._pools pools, pooll = self.db._pools
...@@ -78,7 +78,7 @@ class DBTests(unittest.TestCase): ...@@ -78,7 +78,7 @@ class DBTests(unittest.TestCase):
c12 = self.db.open('v1') c12 = self.db.open('v1')
c12.close() # return to pool c12.close() # return to pool
self.assert_(c1 is not c12) # should be different self.assert_(c1 is not c12) # should be different
self.assertEqual(len(pools), 3) self.assertEqual(len(pools), 3)
self.assertEqual(len(pooll), 3) self.assertEqual(len(pooll), 3)
...@@ -95,13 +95,13 @@ class DBTests(unittest.TestCase): ...@@ -95,13 +95,13 @@ class DBTests(unittest.TestCase):
# Test that we can remove a version pool # Test that we can remove a version pool
# This is white box because we check some internal data structures # This is white box because we check some internal data structures
self.dowork() self.dowork()
self.dowork('v2') self.dowork('v2')
c1 = self.db.open('v1') c1 = self.db.open('v1')
c1.close() # return to pool c1.close() # return to pool
c12 = self.db.open('v1') c12 = self.db.open('v1')
self.assert_(c1 is c12) # should be same self.assert_(c1 is c12) # should be same
pools, pooll = self.db._pools pools, pooll = self.db._pools
...@@ -120,7 +120,7 @@ class DBTests(unittest.TestCase): ...@@ -120,7 +120,7 @@ class DBTests(unittest.TestCase):
c12 = self.db.open('v1') c12 = self.db.open('v1')
c12.close() # return to pool c12.close() # return to pool
self.assert_(c1 is not c12) # should be different self.assert_(c1 is not c12) # should be different
self.assertEqual(len(pools), 3) self.assertEqual(len(pools), 3)
self.assertEqual(len(pooll), 3) self.assertEqual(len(pooll), 3)
......
...@@ -2,14 +2,14 @@ ...@@ -2,14 +2,14 @@
# #
# Copyright (c) 2001, 2002 Zope Corporation and Contributors. # Copyright (c) 2001, 2002 Zope Corporation and Contributors.
# All Rights Reserved. # All Rights Reserved.
# #
# This software is subject to the provisions of the Zope Public License, # 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. # 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 # THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED # WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS # WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
# FOR A PARTICULAR PURPOSE. # FOR A PARTICULAR PURPOSE.
# #
############################################################################## ##############################################################################
from __future__ import nested_scopes from __future__ import nested_scopes
...@@ -92,21 +92,21 @@ class FileStorageTests( ...@@ -92,21 +92,21 @@ class FileStorageTests(
from ZODB.fsIndex import fsIndex from ZODB.fsIndex import fsIndex
# Hack FileStorage to create dictionary indexes # Hack FileStorage to create dictionary indexes
self._storage = OldFileStorage('FileStorageTests.fs') self._storage = OldFileStorage('FileStorageTests.fs')
self.assertEqual(type(self._storage._index), type({})) self.assertEqual(type(self._storage._index), type({}))
for i in range(10): for i in range(10):
self._dostore() self._dostore()
# Should save the index # Should save the index
self._storage.close() self._storage.close()
self._storage = ZODB.FileStorage.FileStorage( self._storage = ZODB.FileStorage.FileStorage(
'FileStorageTests.fs', read_only=1) 'FileStorageTests.fs', read_only=1)
self.assertEqual(type(self._storage._index), type({})) self.assertEqual(type(self._storage._index), type({}))
def check_conversion_to_fsIndex(self): def check_conversion_to_fsIndex(self):
self.tearDown() self.tearDown()
...@@ -117,16 +117,16 @@ class FileStorageTests( ...@@ -117,16 +117,16 @@ class FileStorageTests(
from ZODB.fsIndex import fsIndex from ZODB.fsIndex import fsIndex
# Hack FileStorage to create dictionary indexes # Hack FileStorage to create dictionary indexes
self._storage = OldFileStorage('FileStorageTests.fs') self._storage = OldFileStorage('FileStorageTests.fs')
self.assertEqual(type(self._storage._index), type({})) self.assertEqual(type(self._storage._index), type({}))
for i in range(10): for i in range(10):
self._dostore() self._dostore()
oldindex = self._storage._index.copy() oldindex = self._storage._index.copy()
# Should save the index # Should save the index
self._storage.close() self._storage.close()
...@@ -151,7 +151,7 @@ class FileStorageTests( ...@@ -151,7 +151,7 @@ class FileStorageTests(
# This would make the unit tests too slow # This would make the unit tests too slow
# check_save_after_load_that_worked_hard(self) # check_save_after_load_that_worked_hard(self)
def check_periodic_save_index(self): def check_periodic_save_index(self):
......
...@@ -2,14 +2,14 @@ ...@@ -2,14 +2,14 @@
# #
# Copyright (c) 2001, 2002 Zope Corporation and Contributors. # Copyright (c) 2001, 2002 Zope Corporation and Contributors.
# All Rights Reserved. # All Rights Reserved.
# #
# This software is subject to the provisions of the Zope Public License, # 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. # 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 # THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED # WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS # WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
# FOR A PARTICULAR PURPOSE. # FOR A PARTICULAR PURPOSE.
# #
############################################################################## ##############################################################################
"""Test the list interface to PersistentList """Test the list interface to PersistentList
""" """
......
...@@ -2,14 +2,14 @@ ...@@ -2,14 +2,14 @@
# #
# Copyright (c) 2001, 2002 Zope Corporation and Contributors. # Copyright (c) 2001, 2002 Zope Corporation and Contributors.
# All Rights Reserved. # All Rights Reserved.
# #
# This software is subject to the provisions of the Zope Public License, # 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. # 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 # THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED # WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS # WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
# FOR A PARTICULAR PURPOSE. # FOR A PARTICULAR PURPOSE.
# #
############################################################################## ##############################################################################
"""Verify that PersistentMapping works with old versions of Zope. """Verify that PersistentMapping works with old versions of Zope.
......
...@@ -151,5 +151,3 @@ class RecoverTest(unittest.TestCase): ...@@ -151,5 +151,3 @@ class RecoverTest(unittest.TestCase):
def test_suite(): def test_suite():
return unittest.makeSuite(RecoverTest) return unittest.makeSuite(RecoverTest)
...@@ -2,14 +2,14 @@ ...@@ -2,14 +2,14 @@
# #
# Copyright (c) 2001, 2002 Zope Corporation and Contributors. # Copyright (c) 2001, 2002 Zope Corporation and Contributors.
# All Rights Reserved. # All Rights Reserved.
# #
# This software is subject to the provisions of the Zope Public License, # 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. # 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 # THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED # WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS # WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
# FOR A PARTICULAR PURPOSE. # FOR A PARTICULAR PURPOSE.
# #
############################################################################## ##############################################################################
"""Test the TimeStamp utility type""" """Test the TimeStamp utility type"""
......
...@@ -14,7 +14,7 @@ ...@@ -14,7 +14,7 @@
""" """
Revision information: Revision information:
$Id: testTransaction.py,v 1.12 2003/01/27 20:29:50 bwarsaw Exp $ $Id: testTransaction.py,v 1.13 2003/10/02 18:17:17 jeremy Exp $
""" """
""" """
...@@ -599,7 +599,7 @@ class HoserJar(BasicJar): ...@@ -599,7 +599,7 @@ class HoserJar(BasicJar):
# The HoserJars coordinate their actions via the class variable # The HoserJars coordinate their actions via the class variable
# committed. The check() method will only raise its exception # committed. The check() method will only raise its exception
# if committed > 0. # if committed > 0.
committed = 0 committed = 0
...@@ -615,7 +615,7 @@ class HoserJar(BasicJar): ...@@ -615,7 +615,7 @@ class HoserJar(BasicJar):
self.check('tpc_finish') self.check('tpc_finish')
self.ctpc_finish += 1 self.ctpc_finish += 1
HoserJar.committed += 1 HoserJar.committed += 1
def test_suite(): def test_suite():
......
...@@ -2,14 +2,14 @@ ...@@ -2,14 +2,14 @@
# #
# Copyright (c) 2001, 2002 Zope Corporation and Contributors. # Copyright (c) 2001, 2002 Zope Corporation and Contributors.
# All Rights Reserved. # All Rights Reserved.
# #
# This software is subject to the provisions of the Zope Public License, # 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. # 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 # THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED # WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS # WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
# FOR A PARTICULAR PURPOSE. # FOR A PARTICULAR PURPOSE.
# #
############################################################################## ##############################################################################
"""Test the routines to convert between long and 64-bit strings""" """Test the routines to convert between long and 64-bit strings"""
......
...@@ -2,14 +2,14 @@ ...@@ -2,14 +2,14 @@
# #
# Copyright (c) 2001, 2002 Zope Corporation and Contributors. # Copyright (c) 2001, 2002 Zope Corporation and Contributors.
# All Rights Reserved. # All Rights Reserved.
# #
# This software is subject to the provisions of the Zope Public License, # 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. # 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 # THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED # WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS # WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
# FOR A PARTICULAR PURPOSE. # FOR A PARTICULAR PURPOSE.
# #
############################################################################## ##############################################################################
from __future__ import nested_scopes from __future__ import nested_scopes
...@@ -213,7 +213,7 @@ class ZODBTests(unittest.TestCase): ...@@ -213,7 +213,7 @@ class ZODBTests(unittest.TestCase):
r2 = cn2.root() r2 = cn2.root()
self.assertEqual(r1._p_serial, r2._p_serial) self.assertEqual(r1._p_serial, r2._p_serial)
self.obj.child2 = P() self.obj.child2 = P()
conn.getTransaction().commit() conn.getTransaction().commit()
......
...@@ -2,14 +2,14 @@ ...@@ -2,14 +2,14 @@
# #
# Copyright (c) 2001, 2002 Zope Corporation and Contributors. # Copyright (c) 2001, 2002 Zope Corporation and Contributors.
# All Rights Reserved. # All Rights Reserved.
# #
# This software is subject to the provisions of the Zope Public License, # 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. # 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 # THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED # WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS # WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
# FOR A PARTICULAR PURPOSE. # FOR A PARTICULAR PURPOSE.
# #
############################################################################## ##############################################################################
import unittest, sys import unittest, sys
from ZODB.fsIndex import fsIndex from ZODB.fsIndex import fsIndex
......
...@@ -34,7 +34,7 @@ def transact(f, note=None, retries=5): ...@@ -34,7 +34,7 @@ def transact(f, note=None, retries=5):
""" """
# XXX deal with ZEO disconnected errors? # XXX deal with ZEO disconnected errors?
def g(*args, **kwargs): def g(*args, **kwargs):
n = retries n = retries
while n: while n:
......
...@@ -96,4 +96,3 @@ def oid_repr(oid): ...@@ -96,4 +96,3 @@ def oid_repr(oid):
return repr(oid) return repr(oid)
serial_repr = oid_repr serial_repr = oid_repr
This directory contains a collect of utilities for managing ZODB This directory contains a collection of utilities for managing ZODB
databases. Some are more useful than others. If you install ZODB databases. Some are more useful than others. If you install ZODB
using distutils ("python setup.py install"), fsdump.py, fstest.py, using distutils ("python setup.py install"), fsdump.py, fstest.py,
repozo.py, and zeopack.py will be installed in /usr/local/bin. repozo.py, and zeopack.py will be installed in /usr/local/bin.
...@@ -7,27 +7,27 @@ Unless otherwise noted, these scripts are invoked with the name of the ...@@ -7,27 +7,27 @@ Unless otherwise noted, these scripts are invoked with the name of the
Data.fs file as their only argument. Example: checkbtrees.py data.fs. Data.fs file as their only argument. Example: checkbtrees.py data.fs.
analyze.py -- A transaction analyzer for FileStorage analyze.py -- a transaction analyzer for FileStorage
Reports on the data in a FileStorage. The report is organized by Reports on the data in a FileStorage. The report is organized by
class. It shows total data, as well as separate reports for current class. It shows total data, as well as separate reports for current
and historical revisions of objects. and historical revisions of objects.
checkbtrees.py -- Checks BTrees in a FileStorage for corruption. checkbtrees.py -- checks BTrees in a FileStorage for corruption
Attempts to find all the BTrees contained in a Data.fs and calls their Attempts to find all the BTrees contained in a Data.fs, calls their
_check() methods. _check() methods, and runs them through BTrees.check.check().
fsdump.py -- Summarize FileStorage contents, one line per revision. fsdump.py -- summarize FileStorage contents, one line per revision
Prints a report of FileStorage contents, with one line for each Prints a report of FileStorage contents, with one line for each
transaction and one line for each data record in that transaction. transaction and one line for each data record in that transaction.
Includes time stamps, file positions, and class names. Includes time stamps, file positions, and class names.
fstest.py -- Simple consistency checker for FileStorage fstest.py -- simple consistency checker for FileStorage
usage: fstest.py [-v] data.fs usage: fstest.py [-v] data.fs
...@@ -46,7 +46,14 @@ possible for the damage to occur only in the part of the file that ...@@ -46,7 +46,14 @@ possible for the damage to occur only in the part of the file that
stores object pickles. Those errors will go undetected. stores object pickles. Those errors will go undetected.
netspace.py -- Hackish attempt to report on size of objects space.py -- report space used by objects in a FileStorage
usage: space.py [-v] data.fs
This ignores revisions and versions.
netspace.py -- hackish attempt to report on size of objects
usage: netspace.py [-P | -v] data.fs usage: netspace.py [-P | -v] data.fs
...@@ -57,7 +64,7 @@ Traverses objects from the database root and attempts to calculate ...@@ -57,7 +64,7 @@ Traverses objects from the database root and attempts to calculate
size of object, including all reachable subobjects. size of object, including all reachable subobjects.
parsezeolog.py -- Parse BLATHER logs from ZEO server. parsezeolog.py -- parse BLATHER logs from ZEO server
This script may be obsolete. It has not been tested against the This script may be obsolete. It has not been tested against the
current log output of the ZEO server. current log output of the ZEO server.
...@@ -66,12 +73,12 @@ Reports on the time and size of transactions committed by a ZEO ...@@ -66,12 +73,12 @@ Reports on the time and size of transactions committed by a ZEO
server, by inspecting log messages at BLATHER level. server, by inspecting log messages at BLATHER level.
repozo.py -- Incremental backup utility for FileStorage. repozo.py -- incremental backup utility for FileStorage
Run the script with the -h option to see usage details. Run the script with the -h option to see usage details.
timeout.py -- Script to test transaction timeout timeout.py -- script to test transaction timeout
usage: timeout.py address delay [storage-name] usage: timeout.py address delay [storage-name]
...@@ -80,13 +87,13 @@ and tpc_vote(), and then sleeps forever. This should trigger the ...@@ -80,13 +87,13 @@ and tpc_vote(), and then sleeps forever. This should trigger the
transaction timeout feature of the server. transaction timeout feature of the server.
zeopack.py -- Script to pack a ZEO server. zeopack.py -- pack a ZEO server
The script connects to a server and calls pack() on a specific The script connects to a server and calls pack() on a specific
storage. See the script for usage details. storage. See the script for usage details.
zeoreplay.py -- Experimental script to replay transactions from a ZEO log. zeoreplay.py -- experimental script to replay transactions from a ZEO log
Like parsezeolog.py, this may be obsolete because it was written Like parsezeolog.py, this may be obsolete because it was written
against an earlier version of the ZEO server. See the script for against an earlier version of the ZEO server. See the script for
...@@ -95,7 +102,7 @@ usage details. ...@@ -95,7 +102,7 @@ usage details.
zeoup.py zeoup.py
Usage: zeoup.py [options] usage: zeoup.py [options]
The test will connect to a ZEO server, load the root object, and The test will connect to a ZEO server, load the root object, and
attempt to update the zeoup counter in the root. It will report attempt to update the zeoup counter in the root. It will report
...@@ -106,13 +113,34 @@ start a transaction. ...@@ -106,13 +113,34 @@ start a transaction.
See the script for details about the options. See the script for details about the options.
zodbload.py - exercise ZODB under a heavy synthesized Zope-like load zodbload.py -- exercise ZODB under a heavy synthesized Zope-like load
See the module docstring for details. Note that this script requires See the module docstring for details. Note that this script requires
Zope. New in ZODB3 3.1.4. Zope. New in ZODB3 3.1.4.
zeoserverlog.py - analyze ZEO server log for performance statistics zeoserverlog.py -- analyze ZEO server log for performance statistics
See the module docstring for details; there are a large number of See the module docstring for details; there are a large number of
options. New in ZODB3 3.1.4. options. New in ZODB3 3.1.4.
\ No newline at end of file
fsrefs.py -- check FileStorage for dangling references
fstail.py -- display the most recent transactions in a FileStorage
usage: fstail.py [-n nxtn] data.fs
The most recent ntxn transactions are displayed, to stdout.
Optional argument -n specifies ntxn, and defaults to 10.
migrate.py -- do a storage migration and gather statistics
See the module docstring for details.
zeoqueue.py -- report number of clients currently waiting in the ZEO queue
See the module docstring for details.
...@@ -160,7 +160,7 @@ class TestCorruptedFS(unittest.TestCase): ...@@ -160,7 +160,7 @@ class TestCorruptedFS(unittest.TestCase):
newlen = struct.pack(">II", 0, tl - (len(data) - 24)) newlen = struct.pack(">II", 0, tl - (len(data) - 24))
self._file.write(newlen) self._file.write(newlen)
self.detectsError("truncated at") self.detectsError("truncated at")
def testBadDataLength(self): def testBadDataLength(self):
self.copyTransactions(1) self.copyTransactions(1)
tl, data = self.getHeader() tl, data = self.getHeader()
...@@ -180,4 +180,3 @@ class TestCorruptedFS(unittest.TestCase): ...@@ -180,4 +180,3 @@ class TestCorruptedFS(unittest.TestCase):
if __name__ == "__main__": if __name__ == "__main__":
unittest.main() unittest.main()
...@@ -26,7 +26,7 @@ class PackerTests(StorageTestBase): ...@@ -26,7 +26,7 @@ class PackerTests(StorageTestBase):
self.started = 0 self.started = 0
def start(self): def start(self):
self.started =1 self.started =1
self.path = tempfile.mktemp(suffix=".fs") self.path = tempfile.mktemp(suffix=".fs")
self._storage = FileStorage(self.path) self._storage = FileStorage(self.path)
self.db = ZODB.DB(self._storage) self.db = ZODB.DB(self._storage)
...@@ -105,7 +105,7 @@ class PackerTests(StorageTestBase): ...@@ -105,7 +105,7 @@ class PackerTests(StorageTestBase):
assert os.path.exists(self.path + ".old") assert os.path.exists(self.path + ".old")
class UpTest(unittest.TestCase): class UpTest(unittest.TestCase):
def testUp(self): def testUp(self):
status = os.system("zeoup.py -p 19") status = os.system("zeoup.py -p 19")
# There is no ZEO server on port 19, so we should see non-zero # There is no ZEO server on port 19, so we should see non-zero
......
...@@ -140,7 +140,7 @@ Commands: ...@@ -140,7 +140,7 @@ Commands:
- wall time to verify - wall time to verify
- average miliseconds to verify per object. - average miliseconds to verify per object.
$Id: zeoserverlog.py,v 1.2 2003/09/15 16:29:19 jeremy Exp $ $Id: zeoserverlog.py,v 1.3 2003/10/02 18:17:26 jeremy Exp $
""" """
import datetime, sys, re, os import datetime, sys, re, os
......
...@@ -88,7 +88,7 @@ Usage: loadmail2 [options] ...@@ -88,7 +88,7 @@ Usage: loadmail2 [options]
Specify the mailbox for getting input data. Specify the mailbox for getting input data.
$Id: zodbload.py,v 1.2 2003/09/15 16:29:19 jeremy Exp $ $Id: zodbload.py,v 1.3 2003/10/02 18:17:26 jeremy Exp $
""" """
import mailbox import mailbox
......
...@@ -21,4 +21,3 @@ class BaseLogger: ...@@ -21,4 +21,3 @@ class BaseLogger:
for handler in self.logger.handlers: for handler in self.logger.handlers:
if hasattr(handler, 'reopen') and callable(handler.reopen): if hasattr(handler, 'reopen') and callable(handler.reopen):
handler.reopen() handler.reopen()
...@@ -75,8 +75,3 @@ class StartupHandler(Handler): ...@@ -75,8 +75,3 @@ class StartupHandler(Handler):
for record in self.buffer: for record in self.buffer:
target.handle(record) target.handle(record)
self.buffer = [] self.buffer = []
...@@ -17,6 +17,7 @@ import sys ...@@ -17,6 +17,7 @@ import sys
import tempfile import tempfile
import unittest import unittest
import zLOG import zLOG
import logging
severity_string = { severity_string = {
-300: 'TRACE', -300: 'TRACE',
...@@ -50,13 +51,24 @@ class StupidLogTest(unittest.TestCase): ...@@ -50,13 +51,24 @@ class StupidLogTest(unittest.TestCase):
self.wipeEnvironment() self.wipeEnvironment()
self.path = tempfile.mktemp() self.path = tempfile.mktemp()
self._severity = 0 self._severity = 0
# Windows cannot remove a file that's open. The logging code
# keeps the log file open, and I can't find an advertised API
# to tell the logger to close a log file. So here we cheat:
# tearDown() will close and remove all the handlers that pop
# into existence after setUp() runs. This breaks into internals,
# but I couldn't find a sane way to do it.
self.handlers = logging._handlers.keys() # capture current handlers
def tearDown(self): def tearDown(self):
try: # Close and remove all the handlers that came into existence
os.remove(self.path) # since setUp ran.
except os.error: for h in logging._handlers.keys():
pass if h not in self.handlers:
h.close()
del logging._handlers[h]
os.remove(self.path)
self.wipeEnvironment() self.wipeEnvironment()
zLOG.initialize()
def setLog(self, severity=0): def setLog(self, severity=0):
os.environ['%s_LOG_FILE' % self.prefix] = self.path os.environ['%s_LOG_FILE' % self.prefix] = self.path
...@@ -111,14 +123,20 @@ class StupidLogTest(unittest.TestCase): ...@@ -111,14 +123,20 @@ class StupidLogTest(unittest.TestCase):
self.setLog() self.setLog()
zLOG.LOG("basic", zLOG.INFO, "summary") zLOG.LOG("basic", zLOG.INFO, "summary")
f = self.getLogFile() f = self.getLogFile()
self.verifyEntry(f, subsys="basic", summary="summary") try:
self.verifyEntry(f, subsys="basic", summary="summary")
finally:
f.close()
def checkDetail(self): def checkDetail(self):
self.setLog() self.setLog()
zLOG.LOG("basic", zLOG.INFO, "xxx", "this is a detail") zLOG.LOG("basic", zLOG.INFO, "xxx", "this is a detail")
f = self.getLogFile() f = self.getLogFile()
self.verifyEntry(f, subsys="basic", detail="detail") try:
self.verifyEntry(f, subsys="basic", detail="detail")
finally:
f.close()
def checkError(self): def checkError(self):
self.setLog() self.setLog()
...@@ -131,9 +149,13 @@ class StupidLogTest(unittest.TestCase): ...@@ -131,9 +149,13 @@ class StupidLogTest(unittest.TestCase):
zLOG.LOG("basic", zLOG.ERROR, "raised exception", error=err) zLOG.LOG("basic", zLOG.ERROR, "raised exception", error=err)
f = self.getLogFile() f = self.getLogFile()
self.verifyEntry(f, subsys="basic", summary="summary") try:
self.verifyEntry(f, subsys="basic", severity=zLOG.ERROR, self.verifyEntry(f, subsys="basic", summary="summary")
error=err) self.verifyEntry(f, subsys="basic", severity=zLOG.ERROR,
error=err)
finally:
f.close()
class EventLogTest(StupidLogTest): class EventLogTest(StupidLogTest):
""" Test alternate envvars EVENT_LOG_FILE and EVENT_LOG_SEVERITY """ """ Test alternate envvars EVENT_LOG_FILE and EVENT_LOG_SEVERITY """
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment