Debian Codegraph @

test/test_mqtt_request_response.py

raw symbols SCIP
1 # Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
2 # SPDX-License-Identifier: Apache-2.0.
3 from awscrt.mqtt_request_response import StreamingOperationOptions
4 from test import test_retry_wrapper, NativeResourceTest
5 from awscrt import io, mqtt5, mqtt_request_response, mqtt
6
7 from concurrent.futures import Future
8 import os
9 import time
10 import unittest
11 import uuid
12
13 TIMEOUT = 30.0
14
15
16 def create_client_id():
17 return f"aws-crt-python-unit-test-{uuid.uuid4()}"
18
19
20 def _get_env_variable(env_name):
21 env_data = os.environ.get(env_name)
22 if not env_data:
23 raise unittest.SkipTest(f"test requires env var: {env_name}")
24 return env_data
25
26
27 class MqttRequestResponse5TestCallbacks():
28 def __init__(self):
29 self.future_connection_success = Future()
30 self.future_stopped = Future()
31
32 def ws_handshake_transform(self, transform_args):
33 transform_args.set_done()
34
35 def on_publish_received(self, publish_received_data: mqtt5.PublishReceivedData):
36 pass
37
38 def on_lifecycle_stopped(self, lifecycle_stopped: mqtt5.LifecycleStoppedData):
39 if self.future_stopped:
40 self.future_stopped.set_result(None)
41
42 def on_lifecycle_attempting_connect(self, lifecycle_attempting_connect: mqtt5.LifecycleAttemptingConnectData):
43 pass
44
45 def on_lifecycle_connection_success(self, lifecycle_connection_success: mqtt5.LifecycleConnectSuccessData):
46 if self.future_connection_success:
47 if self.future_connection_success.done():
48 pass
49 else:
50 self.future_connection_success.set_result(lifecycle_connection_success)
51
52 def on_lifecycle_connection_failure(self, lifecycle_connection_failure: mqtt5.LifecycleConnectFailureData):
53 if self.future_connection_success:
54 if self.future_connection_success.done():
55 pass
56 else:
57 self.future_connection_success.set_exception(lifecycle_connection_failure.exception)
58
59 def on_lifecycle_disconnection(self, lifecycle_disconnect_data: mqtt5.LifecycleDisconnectData):
60 pass
61
62
63 def _empty_response_paths(options):
64 options.response_paths = []
65
66
67 def _invalidate_response_path_topic(options):
68 options.response_paths[0].topic = "a/#/b"
69
70
71 def _none_response_path_topic(options):
72 options.response_paths[0].topic = None
73
74
75 def _missing_response_path_topic(options):
76 del options.response_paths[0].topic
77
78
79 def _type_mismatch_response_path_topic(options):
80 options.response_paths[0].topic = 57.3
81
82
83 def _type_mismatch_response_path_correlation_token_json_path(options):
84 options.response_paths[0].correlation_token_json_path = []
85
86
87 def _type_mismatch_response_paths(options):
88 options.response_paths = "hello"
89
90
91 def _invalidate_subscription_topic_filter(options):
92 options.subscription_topic_filters[0] = "a/#/c"
93
94
95 def _type_mismatch_subscription_topic_filter(options):
96 options.subscription_topic_filters[0] = ["thirty", 30]
97
98
99 def _type_mismatch_subscriptions(options):
100 options.subscription_topic_filters = 50
101
102
103 def _empty_subscription_topic_filters(options):
104 options.subscription_topic_filters = []
105
106
107 def _none_publish_topic(options):
108 options.publish_topic = None
109
110
111 def _bad_publish_topic(options):
112 options.publish_topic = "#/b/c"
113
114
115 def _type_mismatch_publish_topic(options):
116 options.publish_topic = [["oof"]]
117
118
119 def _type_mismatch_correlation_token(options):
120 options.correlation_token = [-1]
121
122
123 def _subscription_topic_filter_none(options):
124 options.subscription_topic_filter = None
125
126
127 def _type_mismatch_stream_subscription_topic_filter(options):
128 options.subscription_topic_filter = 6
129
130
131 def _type_mismatch_subscription_status_listener(options):
132 options.subscription_status_listener = "string"
133
134
135 def _type_mismatch_incoming_publish_listener(options):
136 options.incoming_publish_listener = "string"
137
138
139 class MqttRequestResponseClientTest(NativeResourceTest):
140
141 def _create_client5(self):
142
143 input_host_name = _get_env_variable("AWS_TEST_MQTT5_IOT_CORE_HOST")
144 input_cert = _get_env_variable("AWS_TEST_MQTT5_IOT_CORE_RSA_CERT")
145 input_key = _get_env_variable("AWS_TEST_MQTT5_IOT_CORE_RSA_KEY")
146
147 client_options = mqtt5.ClientOptions(
148 host_name=input_host_name,
149 port=8883
150 )
151
152 tls_ctx_options = io.TlsContextOptions.create_client_with_mtls_from_path(
153 input_cert,
154 input_key
155 )
156 client_options.tls_ctx = io.ClientTlsContext(tls_ctx_options)
157
158 client_options.connect_options = mqtt5.ConnectPacket()
159 client_options.connect_options.client_id = create_client_id()
160
161 callbacks = MqttRequestResponse5TestCallbacks()
162 client_options.on_lifecycle_event_stopped_fn = callbacks.on_lifecycle_stopped
163 client_options.on_lifecycle_event_connection_success_fn = callbacks.on_lifecycle_connection_success
164 client_options.on_lifecycle_event_connection_failure_fn = callbacks.on_lifecycle_connection_failure
165 client_options.on_lifecycle_event_stopped_fn = callbacks.on_lifecycle_stopped
166
167 protocol_client = mqtt5.Client(client_options)
168 protocol_client.start()
169
170 callbacks.future_connection_success.result(TIMEOUT)
171
172 return protocol_client, callbacks
173
174 def _shutdown5(self, protocol_client, callbacks):
175
176 protocol_client.stop()
177 callbacks.future_stopped.result(TIMEOUT)
178
179 def _create_client311(self):
180
181 input_host_name = _get_env_variable("AWS_TEST_MQTT5_IOT_CORE_HOST")
182 input_cert = _get_env_variable("AWS_TEST_MQTT5_IOT_CORE_RSA_CERT")
183 input_key = _get_env_variable("AWS_TEST_MQTT5_IOT_CORE_RSA_KEY")
184
185 tls_ctx_options = io.TlsContextOptions.create_client_with_mtls_from_path(
186 input_cert,
187 input_key
188 )
189 tls_ctx = io.ClientTlsContext(tls_ctx_options)
190
191 client = mqtt.Client(None, tls_ctx)
192
193 protocol_client = mqtt.Connection(
194 client=client,
195 client_id=create_client_id(),
196 host_name=input_host_name,
197 port=8883,
198 ping_timeout_ms=10000,
199 keep_alive_secs=30
200 )
201 protocol_client.connect().result(TIMEOUT)
202
203 return protocol_client
204
205 def _shutdown311(self, protocol_client):
206 protocol_client.disconnect().result(TIMEOUT)
207
208 def _create_rr_client(
209 self,
210 protocol_client,
211 max_request_response_subscriptions,
212 max_streaming_subscriptions,
213 operation_timeout_seconds):
214 rr_client_options = mqtt_request_response.ClientOptions(
215 max_request_response_subscriptions, max_streaming_subscriptions)
216 rr_client_options.operation_timeout_in_seconds = operation_timeout_seconds
217
218 rr_client = mqtt_request_response.Client(protocol_client, rr_client_options)
219
220 return rr_client
221
222 def _do_mqtt5_test(self, test_callable):
223 (protocol_client, callbacks) = self._create_client5()
224
225 test_callable(protocol_client)
226
227 self._shutdown5(protocol_client, callbacks)
228
229 def _do_mqtt311_test(self, test_callable):
230 protocol_client = self._create_client311()
231
232 test_callable(protocol_client)
233
234 self._shutdown311(protocol_client)
235
236 def _create_get_shadow_request(self, thing_name, use_correlation_token):
237 topic_prefix = f"$aws/things/{thing_name}/shadow/get"
238
239 request_options = mqtt_request_response.RequestOptions(
240 subscription_topic_filters=[f"{topic_prefix}/+"],
241 response_paths=[
242 mqtt_request_response.ResponsePath(topic=f"{topic_prefix}/accepted"),
243 mqtt_request_response.ResponsePath(topic=f"{topic_prefix}/rejected")
244 ],
245 publish_topic=topic_prefix,
246 payload="{}".encode()
247 )
248
249 if use_correlation_token:
250 correlation_token = f"{uuid.uuid4()}"
251 request_options.response_paths[0].correlation_token_json_path = "clientToken"
252 request_options.response_paths[1].correlation_token_json_path = "clientToken"
253 request_options.payload = f'{{"clientToken":"{correlation_token}"}}'.encode()
254 request_options.correlation_token = correlation_token
255
256 return request_options
257
258 def _do_get_shadow_success_no_such_shadow(self, rr_client, thing_name, use_correlation_token):
259 request_options = self._create_get_shadow_request(thing_name, use_correlation_token)
260
261 request_future = rr_client.make_request(request_options)
262 response = request_future.result()
263
264 self.assertEqual(request_options.response_paths[1].topic, response.topic,
265 "Expected response to come in on rejected topic")
266 payload = str(response.payload)
267
268 self.assertIn("No shadow exists with name", payload)
269
270 def _do_get_shadow_success_no_such_shadow_test(self, protocol_client, use_correlation_token):
271 rr_client = self._create_rr_client(protocol_client, 2, 2, 30)
272
273 thing_name = f"tn-{uuid.uuid4()}"
274 self._do_get_shadow_success_no_such_shadow(rr_client, thing_name, use_correlation_token)
275
276 def _do_get_shadow_success(self, rr_client, thing_name, use_correlation_token):
277 request_options = self._create_get_shadow_request(thing_name, use_correlation_token)
278
279 request_future = rr_client.make_request(request_options)
280 response = request_future.result()
281
282 self.assertEqual(request_options.response_paths[0].topic, response.topic,
283 "Expected response to come in on accepted topic")
284
285 payload = str(response.payload)
286 self.assertIn("magic", payload)
287
288 def _do_update_shadow_success(self, rr_client, thing_name, use_correlation_token):
289 topic_prefix = f"$aws/things/{thing_name}/shadow/update"
290
291 request_options = mqtt_request_response.RequestOptions(
292 subscription_topic_filters=[f"{topic_prefix}/accepted", f"{topic_prefix}/rejected"],
293 response_paths=[
294 mqtt_request_response.ResponsePath(topic=f"{topic_prefix}/accepted"),
295 mqtt_request_response.ResponsePath(topic=f"{topic_prefix}/rejected")
296 ],
297 publish_topic=topic_prefix,
298 payload="".encode()
299 )
300
301 desired_state = f'{{"magic":"value"}}'
302
303 if use_correlation_token:
304 correlation_token = f"{uuid.uuid4()}"
305 payload = f'{{"clientToken": "{correlation_token}","state": {{"desired": {desired_state}}}}}'
306 request_options.response_paths[0].correlation_token_json_path = "clientToken"
307 request_options.response_paths[1].correlation_token_json_path = "clientToken"
308 request_options.payload = payload.encode()
309 request_options.correlation_token = correlation_token
310 else:
311 request_options.payload = f'{{"state":{{"desired":{desired_state}}}}}'.encode()
312
313 request_future = rr_client.make_request(request_options)
314 response = request_future.result()
315
316 self.assertEqual(request_options.response_paths[0].topic, response.topic,
317 "Expected response to come in on accepted topic")
318
319 payload = str(response.payload)
320 self.assertIn("magic", payload)
321
322 def _do_delete_shadow_success(self, rr_client, thing_name, use_correlation_token):
323 topic_prefix = f"$aws/things/{thing_name}/shadow/delete"
324
325 request_options = mqtt_request_response.RequestOptions(
326 subscription_topic_filters=[f"{topic_prefix}/+"],
327 response_paths=[
328 mqtt_request_response.ResponsePath(topic=f"{topic_prefix}/accepted"),
329 mqtt_request_response.ResponsePath(topic=f"{topic_prefix}/rejected")
330 ],
331 publish_topic=topic_prefix,
332 payload="{}".encode()
333 )
334
335 if use_correlation_token:
336 correlation_token = f"{uuid.uuid4()}"
337 request_options.response_paths[0].correlation_token_json_path = "clientToken"
338 request_options.response_paths[1].correlation_token_json_path = "clientToken"
339 request_options.payload = f'{{"clientToken":"{correlation_token}"}}'.encode()
340 request_options.correlation_token = correlation_token
341
342 request_future = rr_client.make_request(request_options)
343 response = request_future.result()
344
345 self.assertEqual(request_options.response_paths[0].topic, response.topic,
346 "Expected response to come in on accepted topic")
347
348 payload = str(response.payload)
349 self.assertIn("version", payload)
350
351 def _do_update_delete_shadow_success_test(self, protocol_client, use_correlation_token):
352 rr_client = self._create_rr_client(protocol_client, 2, 2, 30)
353
354 # get should return non-existence
355 thing_name = f"tn-{uuid.uuid4()}"
356
357 try:
358 self._do_get_shadow_success_no_such_shadow(rr_client, thing_name, use_correlation_token)
359
360 # update shadow to create
361 self._do_update_shadow_success(rr_client, thing_name, use_correlation_token)
362
363 # eventual consistency worries
364 time.sleep(2)
365
366 # get should now return the shadow state
367 self._do_get_shadow_success(rr_client, thing_name, use_correlation_token)
368 finally:
369 # delete shadow
370 self._do_delete_shadow_success(rr_client, thing_name, use_correlation_token)
371
372 def _do_stream_success_test(self, protocol_client):
373 rr_client = self._create_rr_client(protocol_client, 2, 2, 30)
374
375 thing_name = f"tn-{uuid.uuid4()}"
376 topic = f"not/a/valid/topic/{thing_name}"
377 payload = b'hello'
378
379 subscribed_future = Future()
380 publish_received_future = Future()
381
382 def on_subscription_status_changed(event):
383 if event.type == mqtt_request_response.SubscriptionStatusEventType.SUBSCRIPTION_ESTABLISHED:
384 subscribed_future.set_result(True)
385
386 def on_incoming_publish(event):
387 if event.topic == topic and event.payload == payload:
388 publish_received_future.set_result(True)
389
390 stream_options = StreamingOperationOptions(topic, on_subscription_status_changed, on_incoming_publish)
391 stream = rr_client.create_stream(stream_options)
392
393 stream.open()
394
395 assert subscribed_future.result(30)
396
397 if isinstance(protocol_client, mqtt5.Client):
398 publish = mqtt5.PublishPacket(
399 payload=payload,
400 qos=mqtt5.QoS.AT_LEAST_ONCE,
401 topic=topic
402 )
403 protocol_client.publish(publish)
404 else:
405 protocol_client.publish(topic, payload, mqtt.QoS.AT_LEAST_ONCE)
406
407 assert publish_received_future.result(30)
408
409 def _do_get_shadow_failure_test(self, protocol_client, options_transform):
410 rr_client = self._create_rr_client(protocol_client, 2, 2, 30)
411
412 thing_name = f"tn-{uuid.uuid4()}"
413 request_options = self._create_get_shadow_request(thing_name, True)
414 options_transform(request_options)
415
416 self.assertRaises(Exception, lambda: rr_client.make_request(request_options))
417
418 def _do_get_shadow_future_failure_test(self, protocol_client, options_transform):
419 rr_client = self._create_rr_client(protocol_client, 2, 2, 30)
420
421 thing_name = f"tn-{uuid.uuid4()}"
422 request_options = self._create_get_shadow_request(thing_name, True)
423 options_transform(request_options)
424
425 response_future = rr_client.make_request(request_options)
426
427 self.assertRaises(Exception, lambda: response_future.result())
428
429 def _do_create_stream_failure_test(self, protocol_client, options_transform):
430 rr_client = self._create_rr_client(protocol_client, 2, 2, 30)
431
432 thing_name = f"tn-{uuid.uuid4()}"
433 stream_options = mqtt_request_response.StreamingOperationOptions(f"not/a/real/thing/{thing_name}")
434 options_transform(stream_options)
435
436 self.assertRaises(Exception, lambda: rr_client.create_stream(stream_options))
437
438 # ==============================================================
439 # CREATION SUCCESS TEST CASES
440 # ==============================================================
441
442 def _test_client_creation_success5(self):
443 self._do_mqtt5_test(lambda protocol_client: self._create_rr_client(protocol_client, 2, 2, 30))
444
445 def test_client_creation_success5(self):
446 test_retry_wrapper(self._test_client_creation_success5)
447
448 def _test_client_creation_success311(self):
449 self._do_mqtt311_test(lambda protocol_client: self._create_rr_client(protocol_client, 2, 2, 30))
450
451 def test_client_creation_success311(self):
452 test_retry_wrapper(self._test_client_creation_success311)
453
454 # ==============================================================
455 # CREATION FAILURE TEST CASES
456 # ==============================================================
457
458 def test_client_creation_failure_no_protocol_client(self):
459 self.assertRaises(Exception, self._create_rr_client, None, 2, 2, 30)
460
461 def test_client_creation_failure_zero_request_response_subscriptions5(self):
462 self._do_mqtt5_test(lambda protocol_client: self.assertRaises(
463 Exception, self._create_rr_client, protocol_client, 0, 2, 30))
464
465 def test_client_creation_failure_zero_request_response_subscriptions311(self):
466 self._do_mqtt311_test(lambda protocol_client: self.assertRaises(
467 Exception, self._create_rr_client, protocol_client, 0, 2, 30))
468
469 def test_client_creation_failure_negative_request_response_subscriptions5(self):
470 self._do_mqtt5_test(lambda protocol_client: self.assertRaises(
471 Exception, self._create_rr_client, protocol_client, -2, 2, 30))
472
473 def test_client_creation_failure_negative_request_response_subscriptions311(self):
474 self._do_mqtt311_test(lambda protocol_client: self.assertRaises(
475 Exception, self._create_rr_client, protocol_client, -2, 2, 30))
476
477 def test_client_creation_failure_no_request_response_subscriptions5(self):
478 self._do_mqtt5_test(lambda protocol_client: self.assertRaises(
479 Exception, self._create_rr_client, protocol_client, None, 2, 30))
480
481 def test_client_creation_failure_no_request_response_subscriptions311(self):
482 self._do_mqtt311_test(lambda protocol_client: self.assertRaises(
483 Exception, self._create_rr_client, protocol_client, None, 2, 30))
484
485 def test_client_creation_failure_request_response_subscriptions_type_mismatch5(self):
486 self._do_mqtt5_test(
487 lambda protocol_client: self.assertRaises(
488 Exception,
489 self._create_rr_client,
490 protocol_client,
491 "None",
492 2,
493 30))
494
495 def test_client_creation_failure_request_response_subscriptions_type_mismatch311(self):
496 self._do_mqtt311_test(lambda protocol_client: self.assertRaises(
497 Exception, self._create_rr_client, protocol_client, "None", 2, 30))
498
499 def test_client_creation_failure_negative_streaming_subscriptions5(self):
500 self._do_mqtt5_test(lambda protocol_client: self.assertRaises(
501 Exception, self._create_rr_client, protocol_client, 2, -2, 30))
502
503 def test_client_creation_failure_negative_streaming_subscriptions311(self):
504 self._do_mqtt311_test(lambda protocol_client: self.assertRaises(
505 Exception, self._create_rr_client, protocol_client, 2, -2, 30))
506
507 def test_client_creation_failure_no_streaming_subscriptions5(self):
508 self._do_mqtt5_test(lambda protocol_client: self.assertRaises(
509 Exception, self._create_rr_client, protocol_client, 2, None, 30))
510
511 def test_client_creation_failure_no_streaming_subscriptions311(self):
512 self._do_mqtt311_test(lambda protocol_client: self.assertRaises(
513 Exception, self._create_rr_client, protocol_client, 2, None, 30))
514
515 def test_client_creation_failure_streaming_subscriptions_type_mismatch5(self):
516 self._do_mqtt5_test(lambda protocol_client: self.assertRaises(
517 Exception, self._create_rr_client, protocol_client, 2, [], 30))
518
519 def test_client_creation_failure_streaming_subscriptions_type_mismatch311(self):
520 self._do_mqtt311_test(lambda protocol_client: self.assertRaises(
521 Exception, self._create_rr_client, protocol_client, 2, {}, 30))
522
523 def test_client_creation_failure_negative_operation_timeout5(self):
524 self._do_mqtt5_test(lambda protocol_client: self.assertRaises(
525 Exception, self._create_rr_client, protocol_client, 2, 2, -30))
526
527 def test_client_creation_failure_negative_operation_timeout311(self):
528 self._do_mqtt311_test(lambda protocol_client: self.assertRaises(
529 Exception, self._create_rr_client, protocol_client, 2, 2, -30))
530
531 def test_client_creation_failure_no_operation_timeout5(self):
532 self._do_mqtt5_test(lambda protocol_client: self.assertRaises(
533 Exception, self._create_rr_client, protocol_client, 2, 2, None))
534
535 def test_client_creation_failure_no_operation_timeout311(self):
536 self._do_mqtt311_test(lambda protocol_client: self.assertRaises(
537 Exception, self._create_rr_client, protocol_client, 2, 2, None))
538
539 def test_client_creation_failure_operation_timeout_invalid5(self):
540 self._do_mqtt5_test(lambda protocol_client: self.assertRaises(
541 Exception, self._create_rr_client, protocol_client, 2, 2, ["uffdah"]))
542
543 def test_client_creation_failure_operation_timeout_invalid311(self):
544 self._do_mqtt311_test(
545 lambda protocol_client: self.assertRaises(
546 Exception,
547 self._create_rr_client,
548 protocol_client,
549 2,
550 2,
551 777777777777777777777777777777777777))
552
553 # ==============================================================
554 # make_request SUCCESS TEST CASES
555 # ==============================================================
556
557 def _test_get_shadow_success_no_such_shadow5(self):
558 self._do_mqtt5_test(
559 lambda protocol_client: self._do_get_shadow_success_no_such_shadow_test(
560 protocol_client, True))
561
562 def test_get_shadow_success_no_such_shadow5(self):
563 test_retry_wrapper(self._test_get_shadow_success_no_such_shadow5)
564
565 def _test_get_shadow_success_no_such_shadow311(self):
566 self._do_mqtt311_test(
567 lambda protocol_client: self._do_get_shadow_success_no_such_shadow_test(
568 protocol_client, True))
569
570 def test_get_shadow_success_no_such_shadow311(self):
571 test_retry_wrapper(self._test_get_shadow_success_no_such_shadow311)
572
573 def _test_get_shadow_success_no_such_shadow_no_correlation_token5(self):
574 self._do_mqtt5_test(
575 lambda protocol_client: self._do_get_shadow_success_no_such_shadow_test(
576 protocol_client, False))
577
578 def test_get_shadow_success_no_such_shadow_no_correlation_token5(self):
579 test_retry_wrapper(self._test_get_shadow_success_no_such_shadow_no_correlation_token5)
580
581 def _test_get_shadow_success_no_such_shadow_no_correlation_token311(self):
582 self._do_mqtt311_test(
583 lambda protocol_client: self._do_get_shadow_success_no_such_shadow_test(
584 protocol_client, False))
585
586 def test_get_shadow_success_no_such_shadow_no_correlation_token311(self):
587 test_retry_wrapper(self._test_get_shadow_success_no_such_shadow_no_correlation_token311)
588
589 def _test_update_delete_shadow_success5(self):
590 self._do_mqtt5_test(lambda protocol_client: self._do_update_delete_shadow_success_test(protocol_client, True))
591
592 def test_update_delete_shadow_success5(self):
593 test_retry_wrapper(self._test_update_delete_shadow_success5)
594
595 def _test_update_delete_shadow_success311(self):
596 self._do_mqtt311_test(lambda protocol_client: self._do_update_delete_shadow_success_test(protocol_client, True))
597
598 def test_update_delete_shadow_success311(self):
599 test_retry_wrapper(self._test_update_delete_shadow_success311)
600
601 def _test_update_delete_shadow_success_no_correlation_token5(self):
602 self._do_mqtt5_test(lambda protocol_client: self._do_update_delete_shadow_success_test(protocol_client, False))
603
604 def test_update_delete_shadow_success_no_correlation_token5(self):
605 test_retry_wrapper(self._test_update_delete_shadow_success_no_correlation_token5)
606
607 def _test_update_delete_shadow_success_no_correlation_token311(self):
608 self._do_mqtt311_test(
609 lambda protocol_client: self._do_update_delete_shadow_success_test(
610 protocol_client, False))
611
612 def test_update_delete_shadow_success_no_correlation_token311(self):
613 test_retry_wrapper(self._test_update_delete_shadow_success_no_correlation_token311)
614
615 # ==============================================================
616 # make_request FAILURE TEST CASES
617 # ==============================================================
618
619 def _test_get_shadow_failure_no_response_paths5(self):
620 self._do_mqtt5_test(lambda protocol_client: self._do_get_shadow_failure_test(
621 protocol_client, lambda options: _empty_response_paths(options)))
622
623 def test_get_shadow_failure_no_response_paths5(self):
624 test_retry_wrapper(self._test_get_shadow_failure_no_response_paths5)
625
626 def _test_get_shadow_failure_no_response_paths311(self):
627 self._do_mqtt311_test(lambda protocol_client: self._do_get_shadow_failure_test(
628 protocol_client, lambda options: _empty_response_paths(options)))
629
630 def test_get_shadow_failure_no_response_paths311(self):
631 test_retry_wrapper(self._test_get_shadow_failure_no_response_paths311)
632
633 def _test_get_shadow_failure_invalid_response_path_topic5(self):
634 self._do_mqtt5_test(lambda protocol_client: self._do_get_shadow_future_failure_test(
635 protocol_client, lambda options: _invalidate_response_path_topic(options)))
636
637 def test_get_shadow_failure_invalid_response_path_topic5(self):
638 test_retry_wrapper(self._test_get_shadow_failure_invalid_response_path_topic5)
639
640 def _test_get_shadow_failure_invalid_response_path_topic311(self):
641 self._do_mqtt311_test(lambda protocol_client: self._do_get_shadow_future_failure_test(
642 protocol_client, lambda options: _invalidate_response_path_topic(options)))
643
644 def test_get_shadow_failure_invalid_response_path_topic311(self):
645 test_retry_wrapper(self._test_get_shadow_failure_invalid_response_path_topic311)
646
647 def _test_get_shadow_failure_none_response_path_topic5(self):
648 self._do_mqtt5_test(lambda protocol_client: self._do_get_shadow_failure_test(
649 protocol_client, lambda options: _none_response_path_topic(options)))
650
651 def test_get_shadow_failure_none_response_path_topic5(self):
652 test_retry_wrapper(self._test_get_shadow_failure_none_response_path_topic5)
653
654 def _test_get_shadow_failure_none_response_path_topic311(self):
655 self._do_mqtt311_test(lambda protocol_client: self._do_get_shadow_failure_test(
656 protocol_client, lambda options: _none_response_path_topic(options)))
657
658 def test_get_shadow_failure_none_response_path_topic311(self):
659 test_retry_wrapper(self._test_get_shadow_failure_none_response_path_topic311)
660
661 def _test_get_shadow_failure_missing_response_path_topic5(self):
662 self._do_mqtt5_test(lambda protocol_client: self._do_get_shadow_failure_test(
663 protocol_client, lambda options: _missing_response_path_topic(options)))
664
665 def test_get_shadow_failure_missing_response_path_topic5(self):
666 test_retry_wrapper(self._test_get_shadow_failure_missing_response_path_topic5)
667
668 def _test_get_shadow_failure_missing_response_path_topic311(self):
669 self._do_mqtt311_test(lambda protocol_client: self._do_get_shadow_failure_test(
670 protocol_client, lambda options: _missing_response_path_topic(options)))
671
672 def test_get_shadow_failure_missing_response_path_topic311(self):
673 test_retry_wrapper(self._test_get_shadow_failure_missing_response_path_topic311)
674
675 def _test_get_shadow_failure_response_path_topic_type_mismatch5(self):
676 self._do_mqtt5_test(lambda protocol_client: self._do_get_shadow_failure_test(
677 protocol_client, lambda options: _type_mismatch_response_path_topic(options)))
678
679 def test_get_shadow_failure_response_path_topic_type_mismatch5(self):
680 test_retry_wrapper(self._test_get_shadow_failure_response_path_topic_type_mismatch5)
681
682 def _test_get_shadow_failure_response_path_topic_type_mismatch311(self):
683 self._do_mqtt311_test(lambda protocol_client: self._do_get_shadow_failure_test(
684 protocol_client, lambda options: _type_mismatch_response_path_topic(options)))
685
686 def test_get_shadow_failure_response_path_topic_type_mismatch311(self):
687 test_retry_wrapper(self._test_get_shadow_failure_response_path_topic_type_mismatch311)
688
689 def _test_get_shadow_failure_response_path_correlation_token_json_path_type_mismatch5(self):
690 self._do_mqtt5_test(lambda protocol_client: self._do_get_shadow_failure_test(
691 protocol_client, lambda options: _type_mismatch_response_path_correlation_token_json_path(options)))
692
693 def test_get_shadow_failure_response_path_correlation_token_json_path_type_mismatch5(self):
694 test_retry_wrapper(self._test_get_shadow_failure_response_path_correlation_token_json_path_type_mismatch5)
695
696 def _test_get_shadow_failure_response_path_correlation_token_json_path_type_mismatch311(self):
697 self._do_mqtt311_test(lambda protocol_client: self._do_get_shadow_failure_test(
698 protocol_client, lambda options: _type_mismatch_response_path_correlation_token_json_path(options)))
699
700 def test_get_shadow_failure_response_path_correlation_token_json_path_type_mismatch311(self):
701 test_retry_wrapper(self._test_get_shadow_failure_response_path_correlation_token_json_path_type_mismatch311)
702
703 def _test_get_shadow_failure_response_paths_type_mismatch5(self):
704 self._do_mqtt5_test(lambda protocol_client: self._do_get_shadow_failure_test(
705 protocol_client, lambda options: _type_mismatch_response_paths(options)))
706
707 def test_get_shadow_failure_response_paths_type_mismatch5(self):
708 test_retry_wrapper(self._test_get_shadow_failure_response_paths_type_mismatch5)
709
710 def _test_get_shadow_failure_response_paths_type_mismatch311(self):
711 self._do_mqtt311_test(lambda protocol_client: self._do_get_shadow_failure_test(
712 protocol_client, lambda options: _type_mismatch_response_paths(options)))
713
714 def test_get_shadow_failure_response_paths_type_mismatch311(self):
715 test_retry_wrapper(self._test_get_shadow_failure_response_paths_type_mismatch311)
716
717 def _test_get_shadow_failure_invalid_subscription_topic5(self):
718 self._do_mqtt5_test(lambda protocol_client: self._do_get_shadow_future_failure_test(
719 protocol_client, lambda options: _invalidate_subscription_topic_filter(options)))
720
721 def test_get_shadow_failure_invalid_subscription_topic5(self):
722 test_retry_wrapper(self._test_get_shadow_failure_invalid_subscription_topic5)
723
724 def _test_get_shadow_failure_invalid_subscription_topic311(self):
725 self._do_mqtt311_test(lambda protocol_client: self._do_get_shadow_future_failure_test(
726 protocol_client, lambda options: _invalidate_subscription_topic_filter(options)))
727
728 def test_get_shadow_failure_invalid_subscription_topic311(self):
729 test_retry_wrapper(self._test_get_shadow_failure_invalid_subscription_topic311)
730
731 def _test_get_shadow_failure_subscription_topic_type_mismatch5(self):
732 self._do_mqtt5_test(lambda protocol_client: self._do_get_shadow_failure_test(
733 protocol_client, lambda options: _type_mismatch_subscription_topic_filter(options)))
734
735 def test_get_shadow_failure_subscription_topic_type_mismatch5(self):
736 test_retry_wrapper(self._test_get_shadow_failure_subscription_topic_type_mismatch5)
737
738 def _test_get_shadow_failure_subscription_topic_type_mismatch311(self):
739 self._do_mqtt311_test(lambda protocol_client: self._do_get_shadow_failure_test(
740 protocol_client, lambda options: _type_mismatch_subscription_topic_filter(options)))
741
742 def test_get_shadow_failure_subscription_topic_type_mismatch311(self):
743 test_retry_wrapper(self._test_get_shadow_failure_subscription_topic_type_mismatch311)
744
745 def _test_get_shadow_failure_subscriptions_type_mismatch5(self):
746 self._do_mqtt5_test(lambda protocol_client: self._do_get_shadow_failure_test(
747 protocol_client, lambda options: _type_mismatch_subscriptions(options)))
748
749 def test_get_shadow_failure_subscriptions_type_mismatch5(self):
750 test_retry_wrapper(self._test_get_shadow_failure_subscriptions_type_mismatch5)
751
752 def _test_get_shadow_failure_subscriptions_type_mismatch311(self):
753 self._do_mqtt311_test(lambda protocol_client: self._do_get_shadow_failure_test(
754 protocol_client, lambda options: _type_mismatch_subscriptions(options)))
755
756 def test_get_shadow_failure_subscriptions_type_mismatch311(self):
757 test_retry_wrapper(self._test_get_shadow_failure_subscriptions_type_mismatch311)
758
759 def _test_get_shadow_failure_empty_subscriptions5(self):
760 self._do_mqtt5_test(lambda protocol_client: self._do_get_shadow_failure_test(
761 protocol_client, lambda options: _empty_subscription_topic_filters(options)))
762
763 def test_get_shadow_failure_empty_subscriptions5(self):
764 test_retry_wrapper(self._test_get_shadow_failure_empty_subscriptions5)
765
766 def _test_get_shadow_failure_empty_subscriptions311(self):
767 self._do_mqtt311_test(lambda protocol_client: self._do_get_shadow_failure_test(
768 protocol_client, lambda options: _empty_subscription_topic_filters(options)))
769
770 def test_get_shadow_failure_empty_subscriptions311(self):
771 test_retry_wrapper(self._test_get_shadow_failure_empty_subscriptions311)
772
773 def _test_get_shadow_failure_none_publish_topic5(self):
774 self._do_mqtt5_test(lambda protocol_client: self._do_get_shadow_failure_test(
775 protocol_client, lambda options: _none_publish_topic(options)))
776
777 def test_get_shadow_failure_none_publish_topic5(self):
778 test_retry_wrapper(self._test_get_shadow_failure_none_publish_topic5)
779
780 def _test_get_shadow_failure_none_publish_topic311(self):
781 self._do_mqtt311_test(lambda protocol_client: self._do_get_shadow_failure_test(
782 protocol_client, lambda options: _none_publish_topic(options)))
783
784 def test_get_shadow_failure_none_publish_topic311(self):
785 test_retry_wrapper(self._test_get_shadow_failure_none_publish_topic311)
786
787 def _test_get_shadow_failure_bad_publish_topic5(self):
788 self._do_mqtt5_test(lambda protocol_client: self._do_get_shadow_future_failure_test(
789 protocol_client, lambda options: _bad_publish_topic(options)))
790
791 def test_get_shadow_failure_bad_publish_topic5(self):
792 test_retry_wrapper(self._test_get_shadow_failure_bad_publish_topic5)
793
794 def _test_get_shadow_failure_bad_publish_topic311(self):
795 self._do_mqtt311_test(
796 lambda protocol_client: self._do_get_shadow_future_failure_test(
797 protocol_client,
798 lambda options: _bad_publish_topic(options)))
799
800 def test_get_shadow_failure_bad_publish_topic311(self):
801 test_retry_wrapper(self._test_get_shadow_failure_bad_publish_topic311)
802
803 def _test_get_shadow_failure_publish_topic_type_mismatch5(self):
804 self._do_mqtt5_test(lambda protocol_client: self._do_get_shadow_failure_test(
805 protocol_client, lambda options: _type_mismatch_publish_topic(options)))
806
807 def test_get_shadow_failure_publish_topic_type_mismatch5(self):
808 test_retry_wrapper(self._test_get_shadow_failure_publish_topic_type_mismatch5)
809
810 def _test_get_shadow_failure_publish_topic_type_mismatch311(self):
811 self._do_mqtt311_test(lambda protocol_client: self._do_get_shadow_failure_test(
812 protocol_client, lambda options: _type_mismatch_publish_topic(options)))
813
814 def test_get_shadow_failure_publish_topic_type_mismatch311(self):
815 test_retry_wrapper(self._test_get_shadow_failure_publish_topic_type_mismatch311)
816
817 def _test_get_shadow_failure_correlation_token_type_mismatch5(self):
818 self._do_mqtt5_test(lambda protocol_client: self._do_get_shadow_failure_test(
819 protocol_client, lambda options: _type_mismatch_correlation_token(options)))
820
821 def test_get_shadow_failure_correlation_token_type_mismatch5(self):
822 test_retry_wrapper(self._test_get_shadow_failure_correlation_token_type_mismatch5)
823
824 def _test_get_shadow_failure_correlation_token_type_mismatch311(self):
825 self._do_mqtt311_test(lambda protocol_client: self._do_get_shadow_failure_test(
826 protocol_client, lambda options: _type_mismatch_correlation_token(options)))
827
828 def test_get_shadow_failure_correlation_token_type_mismatch311(self):
829 test_retry_wrapper(self._test_get_shadow_failure_correlation_token_type_mismatch311)
830
831 # ==============================================================
832 # streaming operation SUCCESS TEST CASES
833 # ==============================================================
834
835 def _test_streaming_operation_success5(self):
836 self._do_mqtt5_test(lambda protocol_client: self._do_stream_success_test(protocol_client))
837
838 def test_streaming_operation_success5(self):
839 test_retry_wrapper(self._test_streaming_operation_success5)
840
841 def _test_streaming_operation_success311(self):
842 self._do_mqtt311_test(lambda protocol_client: self._do_stream_success_test(protocol_client))
843
844 def test_streaming_operation_success311(self):
845 test_retry_wrapper(self._test_streaming_operation_success311)
846
847 # ==============================================================
848 # create_stream FAILURE TEST CASES
849 # ==============================================================
850 def _test_create_stream_failure_subscription_topic_filter_none5(self):
851 self._do_mqtt5_test(lambda protocol_client: self._do_create_stream_failure_test(
852 protocol_client, lambda options: _subscription_topic_filter_none(options)))
853
854 def test_create_stream_failure_subscription_topic_filter_none5(self):
855 test_retry_wrapper(self._test_create_stream_failure_subscription_topic_filter_none5)
856
857 def _test_create_stream_failure_subscription_topic_filter_none311(self):
858 self._do_mqtt311_test(lambda protocol_client: self._do_create_stream_failure_test(
859 protocol_client, lambda options: _subscription_topic_filter_none(options)))
860
861 def test_create_stream_failure_subscription_topic_filter_none311(self):
862 test_retry_wrapper(self._test_create_stream_failure_subscription_topic_filter_none311)
863
864 def _test_create_stream_failure_subscription_topic_filter_type_mismatch5(self):
865 self._do_mqtt5_test(lambda protocol_client: self._do_create_stream_failure_test(
866 protocol_client, lambda options: _type_mismatch_stream_subscription_topic_filter(options)))
867
868 def test_create_stream_failure_subscription_topic_filter_type_mismatch5(self):
869 test_retry_wrapper(self._test_create_stream_failure_subscription_topic_filter_type_mismatch5)
870
871 def _test_create_stream_failure_subscription_topic_filter_type_mismatch311(self):
872 self._do_mqtt311_test(lambda protocol_client: self._do_create_stream_failure_test(
873 protocol_client, lambda options: _type_mismatch_stream_subscription_topic_filter(options)))
874
875 def test_create_stream_failure_subscription_topic_filter_type_mismatch311(self):
876 test_retry_wrapper(self._test_create_stream_failure_subscription_topic_filter_type_mismatch311)
877
878 def _test_create_stream_failure_subscription_status_listener_type_mismatch5(self):
879 self._do_mqtt5_test(lambda protocol_client: self._do_create_stream_failure_test(
880 protocol_client, lambda options: _type_mismatch_subscription_status_listener(options)))
881
882 def test_create_stream_failure_subscription_status_listener_type_mismatch5(self):
883 test_retry_wrapper(self._test_create_stream_failure_subscription_status_listener_type_mismatch5)
884
885 def _test_create_stream_failure_subscription_status_listener_type_mismatch311(self):
886 self._do_mqtt311_test(lambda protocol_client: self._do_create_stream_failure_test(
887 protocol_client, lambda options: _type_mismatch_subscription_status_listener(options)))
888
889 def test_create_stream_failure_subscription_status_listener_type_mismatch311(self):
890 test_retry_wrapper(self._test_create_stream_failure_subscription_status_listener_type_mismatch311)
891
892 def _test_create_stream_failure_incoming_publish_listener_type_mismatch5(self):
893 self._do_mqtt5_test(lambda protocol_client: self._do_create_stream_failure_test(
894 protocol_client, lambda options: _type_mismatch_incoming_publish_listener(options)))
895
896 def test_create_stream_failure_incoming_publish_listener_type_mismatch5(self):
897 test_retry_wrapper(self._test_create_stream_failure_incoming_publish_listener_type_mismatch5)
898
899 def _test_create_stream_failure_incoming_publish_listener_type_mismatch311(self):
900 self._do_mqtt311_test(lambda protocol_client: self._do_create_stream_failure_test(
901 protocol_client, lambda options: _type_mismatch_incoming_publish_listener(options)))
902
903 def test_create_stream_failure_incoming_publish_listener_type_mismatch311(self):
904 test_retry_wrapper(self._test_create_stream_failure_incoming_publish_listener_type_mismatch311)
905
906
907 if __name__ == 'main':
908 unittest.main()