testzeopack.py :  » Web-Frameworks » Zope » Zope-2.6.0 » utilities » ZODBTools » tests » Python Open Source

Home
Python Open Source
1.3.1.2 Python
2.Ajax
3.Aspect Oriented
4.Blog
5.Build
6.Business Application
7.Chart Report
8.Content Management Systems
9.Cryptographic
10.Database
11.Development
12.Editor
13.Email
14.ERP
15.Game 2D 3D
16.GIS
17.GUI
18.IDE
19.Installer
20.IRC
21.Issue Tracker
22.Language Interface
23.Log
24.Math
25.Media Sound Audio
26.Mobile
27.Network
28.Parser
29.PDF
30.Project Management
31.RSS
32.Search
33.Security
34.Template Engines
35.Test
36.UML
37.USB Serial
38.Web Frameworks
39.Web Server
40.Web Services
41.Web Unit
42.Wiki
43.Windows
44.XML
Python Open Source » Web Frameworks » Zope 
Zope » Zope 2.6.0 » utilities » ZODBTools » tests » testzeopack.py
from __future__ import nested_scopes
# Some simple tests for zeopack.py
# For this to work, zeopack.py must by on your PATH.

from ZODB.FileStorage import FileStorage
from ZODB.tests.StorageTestBase import StorageTestBase,removefs
from ZEO.tests import forker
import ZODB

import os
import socket
import tempfile
import threading
import time
import unittest

# XXX The forker interface isn't clearly defined.  It's different on
# different branches of ZEO.  This will break someday.

# XXX Only handle the Unix variant of the forker.  Just to give Tim
# something to do.

class PackerTests(StorageTestBase):

    def setUp(self):
        self.started = 0

    def start(self):
        self.started =1
        self.path = tempfile.mktemp(suffix=".fs")
        self._storage = FileStorage(self.path)
        self.db = ZODB.DB(self._storage)
        self.do_updates()
        self.pid, self.exit = forker.start_zeo_server(self._storage, self.addr)

    def do_updates(self):
        for i in range(100):
            self._dostore()

    def tearDown(self):
        if not self.started:
            return
        self.db.close()
        self._storage.close()
        self.exit.close()
        try:
            os.kill(self.pid, 9)
        except os.error:
            pass
        try:
            os.waitpid(self.pid, 0)
        except os.error, err:
            ##print "waitpid failed", err
            pass
        removefs(self.path)

    def set_inet_addr(self):
        self.host = socket.gethostname()
        self.port = forker.get_port()
        self.addr = self.host, self.port

    def testPack(self):
        self.set_inet_addr()
        self.start()
        status = os.system("zeopack.py -h %s -p %s" % (self.host, self.port))
        assert status == 0
        assert os.path.exists(self.path + ".old")

    def testPackDays(self):
        self.set_inet_addr()
        self.start()
        status = os.system("zeopack.py -h %s -p %s -d 1" % (self.host,
                                                            self.port))
        # Since we specified one day, nothing should get packed
        assert status == 0
        assert not os.path.exists(self.path + ".old")

    def testAF_UNIXPack(self):
        self.addr = tempfile.mktemp(suffix=".zeo-socket")
        self.start()
        status = os.system("zeopack.py -U %s" % self.addr)
        assert status == 0
        assert os.path.exists(self.path + ".old")

    def testNoServer(self):
        status = os.system("zeopack.py -p 19")
        assert status != 0

    def testWaitForServer(self):
        self.set_inet_addr()
        def delayed_start():
            time.sleep(11)
            self.start()
        t = threading.Thread(target=delayed_start)
        t.start()
        status = os.system("zeopack.py -h %s -p %s -W" % (self.host,
                                                          self.port))
        t.join()
        assert status == 0
        assert os.path.exists(self.path + ".old")

class UpTest(unittest.TestCase):

    def testUp(self):
        status = os.system("zeoup.py -p 19")
        # There is no ZEO server on port 19, so we should see non-zero
        # exit status.
        assert status != 0

if __name__ == "__main__":
    unittest.main()
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.