testBootstrap.py 2.09 KB
Newer Older
1 2
#
# Copyright (C) 2009  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 19

import unittest
from mock import Mock
20
from neo.tests import NeoTestBase
21
from neo.storage.app import Application
22
from neo.bootstrap import BootstrapManager
23
from neo.protocol import NodeTypes
24

25
class BootstrapManagerTests(NeoTestBase):
26 27

    def setUp(self):
28
        self.prepareDatabase(number=1)
29
        # create an application object
30
        config = self.getStorageConfiguration()
31
        self.app = Application(config)
32
        self.bootstrap = BootstrapManager(self.app, 'main', NodeTypes.STORAGE)
33 34 35 36 37
        # define some variable to simulate client and storage node
        self.master_port = 10010
        self.storage_port = 10020
        self.num_partitions = 1009
        self.num_replicas = 2
38

39
    def tearDown(self):
40
        NeoTestBase.tearDown(self)
41 42 43 44 45 46

    # Common methods
    def getLastUUID(self):
        return self.uuid

    # Tests
47
    def testConnectionCompleted(self):
48 49 50 51
        uuid = self.getNewUUID()
        conn = Mock({"getUUID" : uuid,
                     "getAddress" : ("127.0.0.1", self.master_port)})
        self.bootstrap.connectionCompleted(conn)
52
        self.checkAskPrimary(conn)
53

54
    def testHandleNotReady(self):
55
        # the primary is not ready
56 57
        conn = Mock({})
        packet = Mock({})
58
        self.bootstrap.notReady(conn, packet, '')
59
        self.checkClosed(conn)
60
        self.checkNoPacketSent(conn)
61

62

63 64 65
if __name__ == "__main__":
    unittest.main()