testCluster.py 3.88 KB
Newer Older
1
#
Grégory Wisniewski's avatar
Grégory Wisniewski committed
2
# Copyright (C) 2009-2010  Nexedi SA
3
#
4 5 6 7
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2
# of the License, or (at your option) any later version.
8
#
9 10 11 12 13 14 15
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
16
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
17 18

import unittest
19 20 21 22 23
import transaction

from ZODB.tests.StorageTestBase import zodb_pickle
from Persistence import Persistent

24
from neo.tests.functional import NEOCluster, NEOFunctionalTest
25

26
class ClusterTests(NEOFunctionalTest):
27

28
    def setUp(self):
29
        NEOFunctionalTest.setUp(self)
30 31 32 33 34 35
        self.neo = None

    def tearDown(self):
        if self.neo is not None:
            self.neo.stop()

36
    def testClusterBreaks(self):
37
        self.neo = NEOCluster(['test_neo1'], port_base=20000,
38 39 40 41 42 43 44
                master_node_count=1, temp_dir=self.getTempDirectory())
        neoctl = self.neo.getNEOCTL()
        self.neo.setupDB()
        self.neo.start()
        self.neo.expectClusterRunning()
        self.neo.expectOudatedCells(number=0)
        self.neo.killStorage()
45
        self.neo.expectClusterVerifying()
46

47
    def testClusterBreaksWithTwoNodes(self):
48 49
        self.neo = NEOCluster(['test_neo1', 'test_neo2'], port_base=20000,
                 partitions=2, master_node_count=1, replicas=0,
50
                 temp_dir=self.getTempDirectory())
51 52 53 54 55 56
        neoctl = self.neo.getNEOCTL()
        self.neo.setupDB()
        self.neo.start()
        self.neo.expectClusterRunning()
        self.neo.expectOudatedCells(number=0)
        self.neo.killStorage()
57
        self.neo.expectClusterVerifying()
58 59

    def testClusterDoesntBreakWithTwoNodesOneReplica(self):
60
        self.neo = NEOCluster(['test_neo1', 'test_neo2'], port_base=20000,
61 62
                         partitions=2, replicas=1, master_node_count=1,
                         temp_dir=self.getTempDirectory())
63 64 65 66 67 68 69
        neoctl = self.neo.getNEOCTL()
        self.neo.setupDB()
        self.neo.start()
        self.neo.expectClusterRunning()
        self.neo.expectOudatedCells(number=0)
        self.neo.killStorage()
        self.neo.expectClusterRunning()
70

71 72 73 74 75 76 77 78 79 80 81
    def testElectionWithManyMasters(self):
        MASTER_COUNT = 20
        self.neo = NEOCluster(['test_neo1', 'test_neo2'], port_base=20000,
            partitions=10, replicas=0, master_node_count=MASTER_COUNT,
            temp_dir=self.getTempDirectory())
        neoctl = self.neo.getNEOCTL()
        self.neo.start()
        self.neo.expectClusterRunning()
        self.neo.expectAllMasters(MASTER_COUNT)
        self.neo.expectOudatedCells(0)

82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101
    def testVerificationCommitUnfinishedTransactions(self):
        """ Verification step should commit unfinished transactions """
        # XXX: this kind of definition should be defined in base test class
        class PObject(Persistent):
            pass
        self.neo = NEOCluster(['test_neo1'], replicas=0,
            temp_dir=self.getTempDirectory())
        neoctl = self.neo.getNEOCTL()
        self.neo.start()
        db, conn = self.neo.getZODBConnection()
        conn.root()[0] = 'ok'
        transaction.commit()
        self.neo.stop()
        # XXX: (obj|trans) become t(obj|trans)
        self.neo.switchTables('test_neo1')
        self.neo.start()
        db, conn = self.neo.getZODBConnection()
        # transaction should be verified and commited
        self.assertEqual(conn.root()[0], 'ok')

102 103 104 105 106 107
def test_suite():
    return unittest.makeSuite(ClusterTests)

if __name__ == "__main__":
    unittest.main(defaultTest="test_suite")