def test_send_event_sends_overlapped_events(self, device_transport): fake_msg_1 = create_fake_message() fake_msg_2 = Message(fake_event_2) mock_mqtt_provider = device_transport._pipeline.provider # connect device_transport.connect() mock_mqtt_provider.on_mqtt_connected() # send an event callback_1 = MagicMock() device_transport.send_event(fake_msg_1, callback_1) mock_mqtt_provider.publish.assert_called_once_with( topic=encoded_fake_topic, payload=fake_msg_1.data, callback=ANY) # while we're waiting for that send to complete, send another event callback_2 = MagicMock() device_transport.send_event(fake_msg_2, callback_2) # verify that we've called publish twice and verify that neither send_event # has completed (because we didn't do anything here to complete it). assert mock_mqtt_provider.publish.call_count == 2 callback_1.assert_not_called() callback_2.assert_not_called()
async def send_test_message(i): print("sending message #" + str(i)) msg = Message("test wind speed " + str(i)) msg.message_id = uuid.uuid4() msg.correlation_id = "correlation-1234" msg.custom_properties["tornado-warning"] = "yes" await device_client.send_d2c_message(msg) print("done sending message #" + str(i))
def get_fault_injection_message(fault_injection_type): fault_message = Message(" ") fault_message.custom_properties["AzIoTHub_FaultOperationType"] = fault_injection_type fault_message.custom_properties["AzIoTHub_FaultOperationCloseReason"] = fault_injection_types[ fault_injection_type ] fault_message.custom_properties["AzIoTHub_FaultOperationDelayInSecs"] = 5 return fault_message
def test_send_message_with_no_properties(self, device_transport): fake_msg = Message("Petrificus Totalus") mock_mqtt_provider = device_transport._pipeline.provider device_transport.connect() mock_mqtt_provider.on_mqtt_connected() device_transport.send_event(fake_msg) mock_mqtt_provider.connect.assert_called_once_with( device_transport._auth_provider.get_current_sas_token()) mock_mqtt_provider.publish.assert_called_once_with( topic=fake_topic, payload=fake_msg.data, callback=ANY)
def test_send_message_with_output_name(self, module_transport): fake_msg = Message("Petrificus Totalus") fake_msg.custom_properties[ custom_property_name] = custom_property_value fake_msg.output_name = "fake_output_name" fake_output_topic = ("devices/" + fake_device_id + "/modules/" + fake_module_id + "/messages/events/" + before_sys_key + "on" + after_sys_key + "fake_output_name" + topic_separator + custom_property_name + after_sys_key + custom_property_value) mock_mqtt_provider = module_transport._pipeline.provider module_transport.connect() mock_mqtt_provider.on_mqtt_connected() module_transport.send_event(fake_msg) mock_mqtt_provider.connect.assert_called_once_with( module_transport._auth_provider.get_current_sas_token()) mock_mqtt_provider.publish.assert_called_once_with( topic=fake_output_topic, payload=fake_msg.data, callback=ANY)
def get_random_message(total_payload_length=0): message = Message(json.dumps(get_random_dict(total_payload_length))) message.content_type = const.JSON_CONTENT_TYPE message.content_encoding = const.JSON_CONTENT_ENCODING message.message_id = str(uuid.uuid4()) return message
def get_random_message(): message = Message(json.dumps(get_random_dict())) message.content_type = const.JSON_CONTENT_TYPE message.content_encoding = const.JSON_CONTENT_ENCODING return message
def create_fake_output_message(): msg = Message(fake_event) msg.message_id = fake_message_id msg.output_name = "fake_output_name" return msg
def create_fake_message(): msg = Message(fake_event) msg.message_id = fake_message_id msg.custom_properties[custom_property_name] = custom_property_value return msg