Commit b0b20798 authored by Jeremy Hylton's avatar Jeremy Hylton

Extend the monitor test suite to actually parse the monitor output.

parent 58bc45ce
...@@ -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.2 2003/01/09 23:55:57 jeremy Exp $ $Id: monitor.py,v 1.3 2003/01/15 21:23:16 jeremy Exp $
""" """
import asyncore import asyncore
...@@ -40,6 +40,35 @@ class StorageStats: ...@@ -40,6 +40,35 @@ class StorageStats:
self.conflicts_resolved = 0 self.conflicts_resolved = 0
self.start = time.ctime() self.start = time.ctime()
def parse(self, s):
# parse the dump format
lines = s.split("\n")
for line in lines:
field, value = line.split(":", 1)
if field == "Server started":
self.start = value
elif field == "Clients":
self.clients = int(value)
elif field == "Clients verifying":
self.verifying_clients = int(value)
elif field == "Active transactions":
self.active_txns = int(value)
elif field == "Commit lock held for":
# This assumes
self.lock_time = time.time() - int(value)
elif field == "Commits":
self.commits = int(value)
elif field == "Aborts":
self.aborts = int(value)
elif field == "Loads":
self.loads = int(value)
elif field == "Stores":
self.stores = int(value)
elif field == "Conflicts":
self.conflicts = int(value)
elif field == "Conflicts resolved":
self.conflicts_resolved = int(value)
def dump(self, f): def dump(self, f):
print >> f, "Server started:", self.start print >> f, "Server started:", self.start
print >> f, "Clients:", self.clients print >> f, "Clients:", self.clients
......
...@@ -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.2 2003/01/13 21:43:24 tim_one Exp $ $Id: testMonitor.py,v 1.3 2003/01/15 21:23:17 jeremy Exp $
""" """
import socket import socket
...@@ -21,6 +21,7 @@ import time ...@@ -21,6 +21,7 @@ import time
import unittest import unittest
from ZEO.tests.ConnectionTests import CommonSetupTearDown from ZEO.tests.ConnectionTests import CommonSetupTearDown
from ZEO.monitor import StorageStats
class MonitorTests(CommonSetupTearDown): class MonitorTests(CommonSetupTearDown):
...@@ -39,6 +40,37 @@ class MonitorTests(CommonSetupTearDown): ...@@ -39,6 +40,37 @@ class MonitorTests(CommonSetupTearDown):
s.close() s.close()
return "".join(L) return "".join(L)
def parse(self, s):
# Return a list of StorageStats, one for each storage.
lines = s.split("\n")
self.assert_(lines[0].startswith("ZEO monitor server"))
# lines[1] is a date
# Break up rest of lines into sections starting with Storage:
# and ending with a blank line.
sections = []
cur = None
for line in lines[2:]:
if line.startswith("Storage:"):
cur = [line]
elif line:
cur.append(line)
else:
if cur is not None:
sections.append(cur)
cur = None
assert cur is None # bug in the test code if this fails
d = {}
for sect in sections:
hdr = sect[0]
key, value = hdr.split(":")
storage = int(value)
s = d[storage] = StorageStats()
s.parse("\n".join(sect[1:]))
return d
def getConfig(self, path, create, read_only): def getConfig(self, path, create, read_only):
return """\ return """\
<Storage> <Storage>
...@@ -53,7 +85,10 @@ class MonitorTests(CommonSetupTearDown): ...@@ -53,7 +85,10 @@ class MonitorTests(CommonSetupTearDown):
s = self.get_monitor_output() s = self.get_monitor_output()
self.storage.close() self.storage.close()
self.assert_(s.find("monitor") != -1) self.assert_(s.find("monitor") != -1)
d = self.parse(s)
stats = d[1]
self.assertEqual(stats.clients, 1)
self.assertEqual(stats.commits, 0)
def test_suite(): def test_suite():
return unittest.makeSuite(MonitorTests) return unittest.makeSuite(MonitorTests)
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