def test_published_with_policy_sized_queue_and_rpc_down(self):
        publisher = self.publisher_cls(netutils.urlsplit(
            '%s://?policy=queue&max_queue_length=3' % self.protocol))

        side_effect = oslo_messaging.MessageDeliveryFailure()
        with mock.patch.object(publisher, '_send') as fake_send:
            fake_send.side_effect = side_effect
            for i in range(0, 5):
                for s in self.test_data:
                    setattr(s, self.attr, 'test-%d' % i)
                getattr(publisher, self.pub_func)(mock.MagicMock(),
                                                  self.test_data)

        self.assertEqual(3, len(publisher.local_queue))
        self.assertEqual(
            'test-2',
            publisher.local_queue[0][2][0][self.attr]
        )
        self.assertEqual(
            'test-3',
            publisher.local_queue[1][2][0][self.attr]
        )
        self.assertEqual(
            'test-4',
            publisher.local_queue[2][2][0][self.attr]
        )
Exemple #2
0
 def test_published_with_policy_drop_and_rpc_down(self):
     publisher = self.publisher_cls(
         netutils.urlsplit('%s://?policy=drop' % self.protocol))
     side_effect = oslo_messaging.MessageDeliveryFailure()
     with mock.patch.object(publisher, '_send') as fake_send:
         fake_send.side_effect = side_effect
         getattr(publisher, self.pub_func)(mock.MagicMock(), self.test_data)
         self.assertEqual(0, len(publisher.local_queue))
         fake_send.assert_called_once_with(mock.ANY, self.topic, mock.ANY)
Exemple #3
0
 def test_published_with_policy_block(self, mylog):
     publisher = self.publisher_cls(
         netutils.urlsplit('%s://?policy=default' % self.protocol))
     side_effect = oslo_messaging.MessageDeliveryFailure()
     with mock.patch.object(publisher, '_send') as fake_send:
         fake_send.side_effect = side_effect
         self.assertRaises(oslo_messaging.MessageDeliveryFailure,
                           getattr(publisher, self.pub_func),
                           mock.MagicMock(), self.test_data)
         self.assertTrue(mylog.info.called)
         self.assertEqual(0, len(publisher.local_queue))
         fake_send.assert_called_once_with(mock.ANY, self.topic, mock.ANY)
    def test_published_with_policy_queue_and_rpc_down_up(self):
        self.rpc_unreachable = True
        publisher = self.publisher_cls(
            netutils.urlsplit('%s://?policy=queue' % self.protocol))

        side_effect = oslo_messaging.MessageDeliveryFailure()
        with mock.patch.object(publisher, '_send') as fake_send:
            fake_send.side_effect = side_effect
            getattr(publisher, self.pub_func)(mock.MagicMock(),
                                              self.test_data)

            self.assertEqual(1, len(publisher.local_queue))

            fake_send.side_effect = mock.MagicMock()
            getattr(publisher, self.pub_func)(mock.MagicMock(),
                                              self.test_data)

            self.assertEqual(0, len(publisher.local_queue))

            topic = self.topic
            expected = [mock.call(mock.ANY, topic, mock.ANY),
                        mock.call(mock.ANY, topic, mock.ANY),
                        mock.call(mock.ANY, topic, mock.ANY)]
            self.assertEqual(expected, fake_send.mock_calls)