Skip to content

Commit

Permalink
[mqtt-homeassistant] MQTT Homeassistant test concurrency bug fixed (o…
Browse files Browse the repository at this point in the history
…penhab#11161)

Signed-off-by: Anton Kharuzhy <antroids@gmail.com>

Co-authored-by: Anton Kharuzhy <antroids@gmail.com>
  • Loading branch information
2 people authored and frederictobiasc committed Oct 26, 2021
1 parent 24e9335 commit ca3004f
Showing 1 changed file with 5 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,11 @@
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
import java.util.Set;
import java.util.UUID;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ConcurrentMap;

import org.eclipse.jdt.annotation.NonNullByDefault;
import org.junit.jupiter.api.Assertions;
Expand Down Expand Up @@ -94,7 +93,7 @@ public abstract class AbstractHomeAssistantTests extends JavaTest {
protected final Bridge bridgeThing = BridgeBuilder.create(BRIDGE_TYPE_UID, BRIDGE_UID).build();
protected final BrokerHandler bridgeHandler = spy(new BrokerHandler(bridgeThing));
protected final Thing haThing = ThingBuilder.create(HA_TYPE_UID, HA_UID).withBridge(BRIDGE_UID).build();
protected final Map<String, Set<MqttMessageSubscriber>> subscriptions = new HashMap<>();
protected final ConcurrentMap<String, Set<MqttMessageSubscriber>> subscriptions = new ConcurrentHashMap<>();

private final JinjaTransformationService jinjaTransformationService = new JinjaTransformationService();

Expand Down Expand Up @@ -125,10 +124,9 @@ protected void setupConnection() {
doAnswer(invocation -> {
final var topic = (String) invocation.getArgument(0);
final var subscriber = (MqttMessageSubscriber) invocation.getArgument(1);
final var topicSubscriptions = subscriptions.getOrDefault(topic, new HashSet<>());

topicSubscriptions.add(subscriber);
subscriptions.put(topic, topicSubscriptions);
subscriptions.putIfAbsent(topic, ConcurrentHashMap.newKeySet());
subscriptions.get(topic).add(subscriber);
return CompletableFuture.completedFuture(true);
}).when(bridgeConnection).subscribe(any(), any());

Expand Down

0 comments on commit ca3004f

Please sign in to comment.