From eb94c9929e75f3d9f474d4a19225032068e8ab17 Mon Sep 17 00:00:00 2001 From: Bret Ambrose Date: Thu, 19 Dec 2024 12:15:48 -0800 Subject: [PATCH] On second thought, get rid of the counting checks entirely; they're pointless and unsafe --- .../awssdk/crt/test/SelfPubSubTest.java | 27 ++++++------------- 1 file changed, 8 insertions(+), 19 deletions(-) diff --git a/src/test/java/software/amazon/awssdk/crt/test/SelfPubSubTest.java b/src/test/java/software/amazon/awssdk/crt/test/SelfPubSubTest.java index 5cae3a5e8..5de86f2ed 100644 --- a/src/test/java/software/amazon/awssdk/crt/test/SelfPubSubTest.java +++ b/src/test/java/software/amazon/awssdk/crt/test/SelfPubSubTest.java @@ -34,9 +34,6 @@ public SelfPubSubTest() { static final String TEST_TOPIC = "publish/me/senpai/" + UUID.randomUUID().toString(); static final String TEST_PAYLOAD = "PUBLISH ME! SHINY AND CHROME!"; - int pubsAcked = 0; - int subsAcked = 0; - @Test public void testPubSub() { skipIfNetworkUnavailable(); @@ -64,25 +61,22 @@ public void testPubSub() { }; CompletableFuture subscribed = connection.subscribe(TEST_TOPIC, QualityOfService.AT_LEAST_ONCE, - messageHandler).thenApply(unused -> subsAcked++); + messageHandler); int packetId = subscribed.get(); assertNotSame(0, packetId); - assertEquals("Single subscription", 1, subsAcked); MqttMessage message = new MqttMessage(TEST_TOPIC, TEST_PAYLOAD.getBytes(), QualityOfService.AT_LEAST_ONCE, false); - CompletableFuture published = connection.publish(message).thenApply(unused -> pubsAcked++); + CompletableFuture published = connection.publish(message); packetId = published.get(); assertNotSame(0, packetId); - assertEquals("Published", 1, pubsAcked); - published = connection.publish(message).thenApply(unused -> pubsAcked++); + published = connection.publish(message); packetId = published.get(); assertNotSame(0, packetId); - assertEquals("Published", 2, pubsAcked); MqttMessage received = receivedFuture.get(); assertEquals("Received", message.getTopic(), received.getTopic()); @@ -90,11 +84,10 @@ public void testPubSub() { assertEquals("Received", message.getQos(), received.getQos()); assertEquals("Received", message.getRetain(), received.getRetain()); - CompletableFuture unsubscribed = connection.unsubscribe(TEST_TOPIC).thenApply(unused -> subsAcked--); + CompletableFuture unsubscribed = connection.unsubscribe(TEST_TOPIC); packetId = unsubscribed.get(); assertNotSame(0, packetId); - assertEquals("No Subscriptions", 0, subsAcked); } catch (Exception ex) { fail(ex.getMessage()); } @@ -137,30 +130,26 @@ public void testPubSubOnMessage() { null); try { - CompletableFuture subscribed = connection.subscribe(TEST_TOPIC, QualityOfService.AT_LEAST_ONCE).thenApply(unused -> subsAcked++); + CompletableFuture subscribed = connection.subscribe(TEST_TOPIC, QualityOfService.AT_LEAST_ONCE); int packetId = subscribed.get(); assertNotSame(0, packetId); - assertEquals("Single subscription", 1, subsAcked); MqttMessage message = new MqttMessage(TEST_TOPIC, TEST_PAYLOAD.getBytes(), QualityOfService.AT_LEAST_ONCE); - CompletableFuture published = connection.publish(message).thenApply(unused -> pubsAcked++); + CompletableFuture published = connection.publish(message); packetId = published.get(); assertNotSame(0, packetId); - assertEquals("Published", 1, pubsAcked); - published = connection.publish(message).thenApply(unused -> pubsAcked++); + published = connection.publish(message); packetId = published.get(); assertNotSame(0, packetId); - assertEquals("Published", 2, pubsAcked); - CompletableFuture unsubscribed = connection.unsubscribe(TEST_TOPIC).thenApply(unused -> subsAcked--); + CompletableFuture unsubscribed = connection.unsubscribe(TEST_TOPIC); packetId = unsubscribed.get(); assertNotSame(0, packetId); - assertEquals("No Subscriptions", 0, subsAcked); } catch (Exception ex) { fail(ex.getMessage()); }