Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[mqtt-homeassistant] test concurrency bug fixed #11161

Merged
merged 1 commit into from
Aug 26, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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