Commit e03754a5 authored by Barry Warsaw's avatar Barry Warsaw

Convert the ZEO test framework to use StorageTypes and ZConfig to

create the specific storage instances.  This lets us easily generalize
the tests (the Unix ones at least ;) to use the Berkeley Full storage.

Tim and I will check Windows compatibility soon.
parent df00e255
...@@ -13,14 +13,18 @@ ...@@ -13,14 +13,18 @@
############################################################################## ##############################################################################
"""Library for forking storage server and connecting client storage""" """Library for forking storage server and connecting client storage"""
import asyncore
import os import os
import sys
import types
import random import random
import socket import socket
import sys import asyncore
import traceback import traceback
import types from cStringIO import StringIO
import ZEO.ClientStorage import ZEO.ClientStorage
import ZConfig
from ZODB import StorageConfig
# Change value of PROFILE to enable server-side profiling # Change value of PROFILE to enable server-side profiling
PROFILE = 0 PROFILE = 0
...@@ -50,7 +54,8 @@ def get_port(): ...@@ -50,7 +54,8 @@ def get_port():
if os.name == "nt": if os.name == "nt":
def start_zeo_server(storage_name, args, addr=None, ro_svr=0): # XXX This is probably broken now
def start_zeo_server(conf, addr=None, ro_svr=0):
"""Start a ZEO server in a separate process. """Start a ZEO server in a separate process.
Returns the ZEO port, the test server port, and the pid. Returns the ZEO port, the test server port, and the pid.
...@@ -107,8 +112,7 @@ else: ...@@ -107,8 +112,7 @@ else:
except os.error: except os.error:
pass pass
def start_zeo_server(storage_name, args, addr, ro_svr=0): def start_zeo_server(conf, addr, ro_svr=0):
assert isinstance(args, types.TupleType)
rd, wr = os.pipe() rd, wr = os.pipe()
pid = os.fork() pid = os.fork()
if pid == 0: if pid == 0:
...@@ -119,11 +123,11 @@ else: ...@@ -119,11 +123,11 @@ else:
if PROFILE: if PROFILE:
p = hotshot.Profile("stats.s.%d" % os.getpid()) p = hotshot.Profile("stats.s.%d" % os.getpid())
p.runctx( p.runctx(
"run_server(addr, rd, wr, storage_name, args, ro_svr)", "run_server(addr, rd, wr, conf, ro_svr)",
globals(), locals()) globals(), locals())
p.close() p.close()
else: else:
run_server(addr, rd, wr, storage_name, args, ro_svr) run_server(addr, rd, wr, conf, ro_svr)
except: except:
print "Exception in ZEO server process" print "Exception in ZEO server process"
traceback.print_exc() traceback.print_exc()
...@@ -132,26 +136,26 @@ else: ...@@ -132,26 +136,26 @@ else:
os.close(rd) os.close(rd)
return pid, ZEOClientExit(wr) return pid, ZEOClientExit(wr)
def load_storage(name, args): def load_storage(conf):
package = __import__("ZODB." + name) fp = StringIO(conf)
mod = getattr(package, name) rootconf = ZConfig.loadfile(fp)
klass = getattr(mod, name) storageconf = rootconf.getSection('Storage')
return klass(*args) return StorageConfig.createStorage(storageconf)
def run_server(addr, rd, wr, storage_name, args, ro_svr): def run_server(addr, rd, wr, conf, ro_svr):
# in the child, run the storage server # in the child, run the storage server
global server global server
os.close(wr) os.close(wr)
ZEOServerExit(rd) ZEOServerExit(rd)
import ZEO.StorageServer, ZEO.zrpc.server import ZEO.StorageServer, ZEO.zrpc.server
storage = load_storage(storage_name, args) storage = load_storage(conf)
server = ZEO.StorageServer.StorageServer(addr, {'1':storage}, ro_svr) server = ZEO.StorageServer.StorageServer(addr, {'1':storage}, ro_svr)
ZEO.zrpc.server.loop() ZEO.zrpc.server.loop()
storage.close() storage.close()
if isinstance(addr, types.StringType): if isinstance(addr, types.StringType):
os.unlink(addr) os.unlink(addr)
def start_zeo(storage_name, args, cache=None, cleanup=None, def start_zeo(conf, cache=None, cleanup=None,
domain="AF_INET", storage_id="1", cache_size=20000000): domain="AF_INET", storage_id="1", cache_size=20000000):
"""Setup ZEO client-server for storage. """Setup ZEO client-server for storage.
...@@ -168,7 +172,7 @@ else: ...@@ -168,7 +172,7 @@ else:
else: else:
raise ValueError, "bad domain: %s" % domain raise ValueError, "bad domain: %s" % domain
pid, exit = start_zeo_server(storage_name, args, addr) pid, exit = start_zeo_server(conf, addr)
s = ZEO.ClientStorage.ClientStorage(addr, storage_id, s = ZEO.ClientStorage.ClientStorage(addr, storage_id,
client=cache, client=cache,
cache_size=cache_size, cache_size=cache_size,
......
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