Пример #1
0
    def broadcast(self, message_type, payload):
        request = consensus_pb2.ConsensusBroadcastRequest(
            message_type=message_type, content=payload)

        response = self._send(
            request=request,
            message_type=Message.CONSENSUS_BROADCAST_REQUEST,
            response_type=consensus_pb2.ConsensusBroadcastResponse)

        if response.status != consensus_pb2.ConsensusBroadcastResponse.OK:
            raise exceptions.ReceiveError('Failed with status {}'.format(
                response.status))
Пример #2
0
    def test_broadcast(self):
        self.mock_stream.send.return_value = self._make_future(
            message_type=Message.CONSENSUS_BROADCAST_RESPONSE,
            content=consensus_pb2.ConsensusBroadcastResponse(
                status=consensus_pb2.ConsensusBroadcastResponse.OK).
            SerializeToString())

        self.service.broadcast(message_type='message_type', payload=b'payload')

        self.mock_stream.send.assert_called_with(
            message_type=Message.CONSENSUS_BROADCAST_REQUEST,
            content=consensus_pb2.ConsensusBroadcastRequest(
                message_type='message_type',
                content=b'payload').SerializeToString())