testMasterApp.py 3.93 KB
Newer Older
Aurel's avatar
Aurel committed
1
#
Grégory Wisniewski's avatar
Grégory Wisniewski committed
2
# Copyright (C) 2009-2010  Nexedi SA
3
#
Aurel's avatar
Aurel committed
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
#
Aurel's avatar
Aurel committed
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.
Aurel's avatar
Aurel committed
17

18
import unittest
Aurel's avatar
Aurel committed
19
from mock import Mock
20
from neo.tests import NeoTestBase
Aurel's avatar
Aurel committed
21
from neo.master.app import Application
22
from neo.util import p64, u64
Aurel's avatar
Aurel committed
23

24
class MasterAppTests(NeoTestBase):
Aurel's avatar
Aurel committed
25 26 27

    def setUp(self):
        # create an application object
28
        config = self.getMasterConfiguration()
29
        self.app = Application(config)
Aurel's avatar
Aurel committed
30 31 32
        self.app.pt.clear()

    def tearDown(self):
33
        NeoTestBase.tearDown(self)
Aurel's avatar
Aurel committed
34

35
    def test_05_getNewOIDList(self):
36 37 38
        # must raise as we don"t have one
        self.assertEqual(self.app.loid, None)
        self.app.loid = None
39 40
        self.assertRaises(RuntimeError, self.app.getNewOIDList, 1)
        # ask list
41 42 43 44 45 46 47 48
        self.app.loid = p64(1)
        oid_list = self.app.getNewOIDList(15)
        self.assertEqual(len(oid_list), 15)
        i = 2
        # begin from 0, so generated oid from 1 to 15
        for oid in oid_list:
            self.assertEqual(u64(oid), i)
            i+=1
Aurel's avatar
Aurel committed
49 50

    def test_06_broadcastNodeInformation(self):
51
        # defined some nodes to which data will be send
52
        master_uuid = self.getNewUUID()
53
        master = self.app.nm.createMaster(uuid=master_uuid)
54
        storage_uuid = self.getNewUUID()
55
        storage = self.app.nm.createStorage(uuid=storage_uuid)
56
        client_uuid = self.getNewUUID()
57
        client = self.app.nm.createClient(uuid=client_uuid)
58
        # create conn and patch em
Grégory Wisniewski's avatar
Grégory Wisniewski committed
59 60 61
        master_conn = self.getFakeConnection()
        storage_conn = self.getFakeConnection()
        client_conn = self.getFakeConnection()
62 63 64
        master.setConnection(master_conn)
        storage.setConnection(storage_conn)
        client.setConnection(client_conn)
65 66 67
        master.setRunning()
        client.setRunning()
        storage.setRunning()
68 69
        self.app.nm.add(storage)
        self.app.nm.add(client)
Aurel's avatar
Aurel committed
70

71 72
        # no address defined, not send to client node
        c_node = self.app.nm.createClient(uuid = self.getNewUUID())
73
        self.app.broadcastNodesInformation([c_node])
74 75
        # check conn
        self.checkNoPacketSent(client_conn)
76
        self.checkNoPacketSent(master_conn)
77
        self.checkNotifyNodeInformation(storage_conn)
Aurel's avatar
Aurel committed
78

79 80
        # address defined and client type
        s_node = self.app.nm.createClient(
81
            uuid = self.getNewUUID(),
82
            address=("127.1.0.1", 3361)
83
        )
84
        self.app.broadcastNodesInformation([c_node])
85 86
        # check conn
        self.checkNoPacketSent(client_conn)
87
        self.checkNoPacketSent(master_conn)
88
        self.checkNotifyNodeInformation(storage_conn)
89

90 91
        # address defined and storage type
        s_node = self.app.nm.createStorage(
92
            uuid=self.getNewUUID(),
93
            address=("127.0.0.1", 1351)
94
        )
95

96
        self.app.broadcastNodesInformation([s_node])
97 98
        # check conn
        self.checkNotifyNodeInformation(client_conn)
99
        self.checkNoPacketSent(master_conn)
100
        self.checkNotifyNodeInformation(storage_conn)
Aurel's avatar
Aurel committed
101

102 103 104 105 106 107 108 109 110
        # node not running, don't send informations
        client.setPending()

        self.app.broadcastNodesInformation([s_node])
        # check conn
        self.checkNotifyNodeInformation(client_conn)
        self.checkNoPacketSent(master_conn)
        self.checkNotifyNodeInformation(storage_conn)

Aurel's avatar
Aurel committed
111 112 113 114

if __name__ == '__main__':
    unittest.main()