From 3b555bb0321a78c4919ef59dc12ccaef7793b394 Mon Sep 17 00:00:00 2001 From: Michael Dombrowski Date: Tue, 20 Jun 2023 16:13:29 -0700 Subject: [PATCH] fix(mqtt5): catch mqtt builder fails with mqtt exception (#1492) --- pom.xml | 2 +- .../aws/greengrass/deployment/IotJobsHelper.java | 14 +++++++++----- .../deployment/ShadowDeploymentListener.java | 14 ++++++++++---- .../greengrass/mqttclient/AwsIotMqtt5Client.java | 4 ++++ .../com/aws/greengrass/mqttclient/MqttClient.java | 4 +++- .../aws/greengrass/mqttclient/MqttClientTest.java | 2 +- .../testutilities/ExceptionLogProtector.java | 2 ++ 7 files changed, 30 insertions(+), 12 deletions(-) diff --git a/pom.xml b/pom.xml index a3397e3116..8bc63e0c7b 100644 --- a/pom.xml +++ b/pom.xml @@ -234,7 +234,7 @@ software.amazon.awssdk.iotdevicesdk aws-iot-device-sdk - 1.12.2-CLI-SNAPSHOT + 1.13.2-CLI-SNAPSHOT org.bouncycastle diff --git a/src/main/java/com/aws/greengrass/deployment/IotJobsHelper.java b/src/main/java/com/aws/greengrass/deployment/IotJobsHelper.java index cdecc2bcab..e41feb6d15 100644 --- a/src/main/java/com/aws/greengrass/deployment/IotJobsHelper.java +++ b/src/main/java/com/aws/greengrass/deployment/IotJobsHelper.java @@ -512,6 +512,7 @@ public void unsubscribeFromIotJobsTopics() { * @throws InterruptedException if the thread gets interrupted * @throws TimeoutException if the operation does not complete within the given time */ + @SuppressWarnings("PMD.AvoidCatchingThrowable") protected void subscribeToGetNextJobDescription(Consumer consumerAccept, Consumer consumerReject) throws InterruptedException { @@ -523,10 +524,12 @@ protected void subscribeToGetNextJobDescription(Consumer subscribed = iotJobsClientWrapper - .SubscribeToDescribeJobExecutionAccepted(describeJobExecutionSubscriptionRequest, - QualityOfService.AT_LEAST_ONCE, consumerAccept); + CompletableFuture subscribed; try { + subscribed = iotJobsClientWrapper + .SubscribeToDescribeJobExecutionAccepted(describeJobExecutionSubscriptionRequest, + QualityOfService.AT_LEAST_ONCE, consumerAccept); + subscribed.get(mqttClient.getMqttOperationTimeoutMillis(), TimeUnit.MILLISECONDS); subscribed = iotJobsClientWrapper .SubscribeToDescribeJobExecutionRejected(describeJobExecutionSubscriptionRequest, @@ -544,11 +547,12 @@ protected void subscribeToGetNextJobDescription(Consumer except for the first connection which will just be thingName @@ -988,6 +988,8 @@ protected IndividualMqttClient getNewMqttClient() { return new AwsIotMqtt5Client(() -> { try { return builderProvider.apply(clientBootstrap).toAwsIotMqtt5ClientBuilder(); + } catch (RuntimeException e) { + throw e; } catch (Exception e) { throw new RuntimeException(e); } diff --git a/src/test/java/com/aws/greengrass/mqttclient/MqttClientTest.java b/src/test/java/com/aws/greengrass/mqttclient/MqttClientTest.java index 19cbe974fe..a7a30a5a47 100644 --- a/src/test/java/com/aws/greengrass/mqttclient/MqttClientTest.java +++ b/src/test/java/com/aws/greengrass/mqttclient/MqttClientTest.java @@ -197,7 +197,7 @@ void GIVEN_ping_timeout_gte_keep_alive_WHEN_mqtt_client_connects_THEN_throws_exc mqttNamespace.lookup(MqttClient.MQTT_PING_TIMEOUT_KEY).withValue(pingTimeout); MqttClient mqttClient = new MqttClient(deviceConfiguration, ses, executorService, mock(SecurityService.class), kernel); - RuntimeException e = assertThrows(RuntimeException.class, () -> mqttClient.getNewMqttClient().connect().get()); + ExecutionException e = assertThrows(ExecutionException.class, () -> mqttClient.getNewMqttClient().connect().get()); assertEquals(MqttException.class, e.getCause().getClass()); } diff --git a/src/test/java/com/aws/greengrass/testcommons/testutilities/ExceptionLogProtector.java b/src/test/java/com/aws/greengrass/testcommons/testutilities/ExceptionLogProtector.java index 090b4eb50b..1744bdc652 100644 --- a/src/test/java/com/aws/greengrass/testcommons/testutilities/ExceptionLogProtector.java +++ b/src/test/java/com/aws/greengrass/testcommons/testutilities/ExceptionLogProtector.java @@ -147,6 +147,8 @@ public void beforeEach(ExtensionContext context) throws Exception { ignoreExceptionOfType(context, ClosedByInterruptException.class); ignoreExceptionWithStackTraceContaining(context, IllegalAccessException.class, ProvisioningPluginFactory.class.getName()); + ignoreExceptionWithStackTraceContaining(context, NullPointerException.class, + "subscribeToGetNextJobDescription"); } @Override