Skip to content

Commit

Permalink
On second thought, get rid of the counting checks entirely; they're p…
Browse files Browse the repository at this point in the history
…ointless and unsafe
  • Loading branch information
Bret Ambrose committed Dec 19, 2024
1 parent c6eb4ff commit eb94c99
Showing 1 changed file with 8 additions and 19 deletions.
27 changes: 8 additions & 19 deletions src/test/java/software/amazon/awssdk/crt/test/SelfPubSubTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -64,37 +61,33 @@ public void testPubSub() {
};

CompletableFuture<Integer> 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<Integer> published = connection.publish(message).thenApply(unused -> pubsAcked++);
CompletableFuture<Integer> 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());
assertArrayEquals("Received", message.getPayload(), received.getPayload());
assertEquals("Received", message.getQos(), received.getQos());
assertEquals("Received", message.getRetain(), received.getRetain());

CompletableFuture<Integer> unsubscribed = connection.unsubscribe(TEST_TOPIC).thenApply(unused -> subsAcked--);
CompletableFuture<Integer> unsubscribed = connection.unsubscribe(TEST_TOPIC);
packetId = unsubscribed.get();

assertNotSame(0, packetId);
assertEquals("No Subscriptions", 0, subsAcked);
} catch (Exception ex) {
fail(ex.getMessage());
}
Expand Down Expand Up @@ -137,30 +130,26 @@ public void testPubSubOnMessage() {
null);

try {
CompletableFuture<Integer> subscribed = connection.subscribe(TEST_TOPIC, QualityOfService.AT_LEAST_ONCE).thenApply(unused -> subsAcked++);
CompletableFuture<Integer> 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<Integer> published = connection.publish(message).thenApply(unused -> pubsAcked++);
CompletableFuture<Integer> 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<Integer> unsubscribed = connection.unsubscribe(TEST_TOPIC).thenApply(unused -> subsAcked--);
CompletableFuture<Integer> unsubscribed = connection.unsubscribe(TEST_TOPIC);
packetId = unsubscribed.get();

assertNotSame(0, packetId);
assertEquals("No Subscriptions", 0, subsAcked);
} catch (Exception ex) {
fail(ex.getMessage());
}
Expand Down

0 comments on commit eb94c99

Please sign in to comment.