コード例 #1
0
ファイル: test_raft.py プロジェクト: ssi444/patroni
class TestDynMemberSyncObj(unittest.TestCase):

    @patch('pysyncobj.tcp_server.TcpServer.bind', Mock())
    def setUp(self):
        self.conf = SyncObjConf(appendEntriesUseBatch=False, dynamicMembershipChange=True, autoTick=False)
        self.so = DynMemberSyncObj('127.0.0.1:1234', ['127.0.0.1:1235'], self.conf)

    @patch.object(SyncObjUtility, 'sendMessage')
    def test_add_member(self, mock_send_message):
        mock_send_message.return_value = [{'addr': '127.0.0.1:1235'}, {'addr': '127.0.0.1:1236'}]
        mock_send_message.ver = 0
        DynMemberSyncObj('127.0.0.1:1234', ['127.0.0.1:1235'], self.conf)
        self.conf.dynamicMembershipChange = False
        DynMemberSyncObj('127.0.0.1:1234', ['127.0.0.1:1235'], self.conf)

    def test___onUtilityMessage(self):
        self.so._SyncObj__encryptor = Mock()
        mock_conn = Mock()
        mock_conn.sendRandKey = None
        self.so._SyncObj__transport._onIncomingMessageReceived(mock_conn, 'randkey')
        self.so._SyncObj__transport._onIncomingMessageReceived(mock_conn, ['members'])
        self.so._SyncObj__transport._onIncomingMessageReceived(mock_conn, ['status'])

    def test__SyncObj__doChangeCluster(self):
        self.so._SyncObj__doChangeCluster(['add', '127.0.0.1:1236'])

    def test_utility(self):
        utility = SyncObjUtility(['127.0.0.1:1235'], self.conf)
        utility.setPartnerNode(list(utility._SyncObj__otherNodes)[0])
        utility.sendMessage(['members'])
        utility._onMessageReceived(0, '')
コード例 #2
0
class TestDynMemberSyncObj(unittest.TestCase):
    @patch('pysyncobj.tcp_server.TcpServer.bind', Mock())
    def setUp(self):
        self.conf = SyncObjConf(appendEntriesUseBatch=False,
                                dynamicMembershipChange=True,
                                autoTick=False)
        self.so = DynMemberSyncObj('127.0.0.1:1234', ['127.0.0.1:1235'],
                                   self.conf)

    @patch.object(SyncObjUtility, 'executeCommand')
    def test_add_member(self, mock_execute_command):
        mock_execute_command.return_value = [{
            'addr': '127.0.0.1:1235'
        }, {
            'addr': '127.0.0.1:1236'
        }]
        mock_execute_command.ver = 0
        DynMemberSyncObj('127.0.0.1:1234', ['127.0.0.1:1235'], self.conf)
        self.conf.dynamicMembershipChange = False
        DynMemberSyncObj('127.0.0.1:1234', ['127.0.0.1:1235'], self.conf)

    def test_getMembers(self):
        mock_conn = Mock()
        self.so._SyncObj__transport._onIncomingMessageReceived(
            mock_conn, ['members'])

    def test__SyncObj__doChangeCluster(self):
        self.so._SyncObj__doChangeCluster(['add', '127.0.0.1:1236'])