Пример #1
0
    def test_unsubscribe(self):
        # Test that we remove the relevant subscription only and that
        # updates are no longer sent
        block = MagicMock(to_dict=MagicMock(return_value={
            "attr": "0",
            "inner": {
                "attr2": "other"
            }
        }))
        p = Process("proc", MagicMock())
        sub_1 = Subscribe(MagicMock(), MagicMock(), ["block"], False)
        sub_2 = Subscribe(MagicMock(), MagicMock(), ["block"], False)
        sub_1.set_id(1234)
        sub_2.set_id(4321)
        change_1 = BlockChanges([[["block", "attr"], "1"]])
        change_2 = BlockChanges([[["block", "attr"], "2"]])
        unsub_1 = Unsubscribe(MagicMock(), MagicMock())
        unsub_1.set_id(1234)

        p.q.get = MagicMock(side_effect=[
            sub_1, sub_2, change_1, unsub_1, change_2, PROCESS_STOP
        ])
        p._handle_block_add(BlockAdd(block, "block"))
        p.recv_loop()

        self.assertEqual([sub_2], p._subscriptions)
        self.assertEquals(1, len(unsub_1.response_queue.put.call_args_list))
        response = unsub_1.response_queue.put.call_args_list[0][0][0]
        self.assertIsNone(response.value)
        self.assertIs(unsub_1.context, response.context)

        sub_1_responses = sub_1.response_queue.put.call_args_list
        sub_2_responses = sub_2.response_queue.put.call_args_list
        self.assertEquals(2, len(sub_1_responses))
        self.assertEquals(3, len(sub_2_responses))
Пример #2
0
 def notify_closed_connection(self, response):
     """Let the process know not to send any more updates or deltas"""
     self.log_warning("Response %s cannot be sent as connection closed",
                      response)
     if isinstance(response, (Delta, Update)):
         request = Unsubscribe(response.context, self.q)
         request.set_id(response.id)
         self.send_to_process(request)
Пример #3
0
 def notify_closed_connection(self, response):
     """Let the process know not to send any more updates or deltas"""
     self.log_warning(
         "Response %s cannot be sent as connection closed", response)
     if isinstance(response, (Delta, Update)):
         request = Unsubscribe(response.context, self.q)
         request.set_id(response.id)
         self.send_to_process(request)
Пример #4
0
    def unsubscribe(self, id_):
        """Terminates the subscription to an attribute

            Args:
                id_ (Int): the identifier of the subscription to halt"""

        self._subscriptions.pop(id_)

        request = Unsubscribe(None, self.q)
        request.set_id(id_)
        self.process.q.put(request)
Пример #5
0
    def unsubscribe(self, id_):
        """Terminates the subscription to an attribute

            Args:
                id_ (Int): the identifier of the subscription to halt"""

        self._subscriptions.pop(id_)

        request = Unsubscribe(None, self.q)
        request.set_id(id_)
        self.process.q.put(request)
Пример #6
0
    def test_unsubscribe_error(self):
        p = Process("proc", MagicMock())
        unsub = Unsubscribe(MagicMock(), MagicMock())
        unsub.set_id(1234)
        unsub.response_queue.qsize.return_value = 0
        p.q.get = MagicMock(side_effect=[unsub, PROCESS_STOP])

        p.recv_loop()

        responses = unsub.response_queue.put.call_args_list
        self.assertEquals(1, len(responses))
        response = responses[0][0][0]
        self.assertEquals(Error, type(response))
Пример #7
0
    def test_unsubscribe_error(self):
        p = Process("proc", MagicMock())
        unsub = Unsubscribe(MagicMock(), MagicMock())
        unsub.set_id(1234)
        unsub.response_queue.qsize.return_value = 0
        p.q.get = MagicMock(side_effect=[unsub, PROCESS_STOP])

        p.recv_loop()

        responses = unsub.response_queue.put.call_args_list
        self.assertEquals(1, len(responses))
        response = responses[0][0][0]
        self.assertEquals(Error, type(response))
Пример #8
0
    def test_unsubscribe_error(self):
        p = Process("proc", MagicMock())
        unsub = Unsubscribe(MagicMock(), MagicMock())
        unsub.set_id(1234)
        p.q.get = MagicMock(side_effect=[unsub, PROCESS_STOP])

        p.recv_loop()

        responses = unsub.response_queue.put.call_args_list
        self.assertEquals(1, len(responses))
        response = responses[0][0][0]
        self.assertEquals(Error, type(response))
        self.assertEquals("No subscription found for id 1234",
                          response.message)
Пример #9
0
    def test_unsubscribe(self):
        # Test that we remove the relevant subscription only and that
        # updates are no longer sent
        block = MagicMock(to_dict=MagicMock(return_value={
            "attr": "0",
            "inner": {
                "attr2": "other"
            }
        }))
        p = Process("proc", MagicMock())
        sub_1 = Subscribe(MagicMock(), MagicMock(), ["block"], False)
        sub_1.response_queue.qsize.return_value = 0
        sub_2 = Subscribe(MagicMock(), MagicMock(), ["block"], False)
        sub_2.response_queue.qsize.return_value = 0
        sub_1.set_id(1234)
        sub_2.set_id(1234)
        change_1 = BlockChanges([[["block", "attr"], "1"]])
        change_2 = BlockChanges([[["block", "attr"], "2"]])
        unsub_1 = Unsubscribe(sub_1.context, sub_1.response_queue)
        unsub_1.set_id(sub_1.id)

        p.q.get = MagicMock(side_effect=[
            sub_1, sub_2, change_1, unsub_1, change_2, PROCESS_STOP
        ])
        p._handle_block_add(BlockAdd(block, "block", None))
        p.recv_loop()

        self.assertEqual([sub_2], list(p._subscriptions.values()))

        sub_1_responses = sub_1.response_queue.put.call_args_list
        sub_2_responses = sub_2.response_queue.put.call_args_list
        self.assertEquals(3, len(sub_1_responses))
        self.assertEquals(sub_1_responses[0][0][0].value["attr"], "0")
        self.assertEquals(sub_1_responses[1][0][0].value["attr"], "1")
        self.assertIsInstance(sub_1_responses[2][0][0], Return)
        self.assertEquals(3, len(sub_2_responses))
        self.assertEquals(sub_2_responses[0][0][0].value["attr"], "0")
        self.assertEquals(sub_2_responses[1][0][0].value["attr"], "1")
        self.assertEquals(sub_2_responses[2][0][0].value["attr"], "2")
Пример #10
0
    def test_unsubscribe(self):
        # Test that we remove the relevant subscription only and that
        # updates are no longer sent
        block = MagicMock(
            to_dict=MagicMock(
                return_value={"attr": "0", "inner": {"attr2": "other"}}))
        p = Process("proc", MagicMock())
        sub_1 = Subscribe(
            MagicMock(), MagicMock(), ["block"], False)
        sub_1.response_queue.qsize.return_value = 0
        sub_2 = Subscribe(
            MagicMock(), MagicMock(), ["block"], False)
        sub_2.response_queue.qsize.return_value = 0
        sub_1.set_id(1234)
        sub_2.set_id(1234)
        change_1 = BlockChanges([[["block", "attr"], "1"]])
        change_2 = BlockChanges([[["block", "attr"], "2"]])
        unsub_1 = Unsubscribe(sub_1.context, sub_1.response_queue)
        unsub_1.set_id(sub_1.id)

        p.q.get = MagicMock(side_effect=[sub_1, sub_2, change_1,
                                         unsub_1, change_2, PROCESS_STOP])
        p._handle_block_add(BlockAdd(block, "block", None))
        p.recv_loop()

        self.assertEqual([sub_2], list(p._subscriptions.values()))

        sub_1_responses = sub_1.response_queue.put.call_args_list
        sub_2_responses = sub_2.response_queue.put.call_args_list
        self.assertEquals(3, len(sub_1_responses))
        self.assertEquals(sub_1_responses[0][0][0].value["attr"], "0")
        self.assertEquals(sub_1_responses[1][0][0].value["attr"], "1")
        self.assertIsInstance(sub_1_responses[2][0][0], Return)
        self.assertEquals(3, len(sub_2_responses))
        self.assertEquals(sub_2_responses[0][0][0].value["attr"], "0")
        self.assertEquals(sub_2_responses[1][0][0].value["attr"], "1")
        self.assertEquals(sub_2_responses[2][0][0].value["attr"], "2")