testBootstrap.py 2.21 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
#
# Copyright (C) 2009  Nexedi SA
# 
# 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.
# 
# 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 31
        config = self.getStorageConfiguration()
        self.app = Application(**config)
32 33
        for address in self.app.master_node_list:
            self.app.nm.createMaster(address=address)
34
        self.bootstrap = BootstrapManager(self.app, 'main', NodeTypes.STORAGE)
35 36 37 38 39 40 41
        # 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
        
    def tearDown(self):
42
        NeoTestBase.tearDown(self)
43 44 45 46 47 48

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

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

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

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