Skip to content
Open
Show file tree
Hide file tree
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 @@ -723,31 +723,42 @@ public List<DashboardStatus> getChannelStatusList(Set<String> channelIds) {
}

private Map<String, Channel> getDashboardChannels(Set<String> channelIds) {
return getDashboardChannels(donkey.getDeployedChannels(), deployingChannels, undeployingChannels, channelIds);
}

/**
* Collects the deployed, deploying and undeploying channels, limited to {@code channelIds}
* when it is not empty. The deploying and undeploying channels must honor the same filter, or
* a request for one channel returns another channel that is mid-deploy or mid-undeploy. See
* OpenIntegrationEngine/engine#456.
*/
static Map<String, Channel> getDashboardChannels(Map<String, Channel> deployedChannels, Set<Channel> deployingChannels, Set<Channel> undeployingChannels, Set<String> channelIds) {
boolean filtered = CollectionUtils.isNotEmpty(channelIds);
Map<String, Channel> channels = null;

if (CollectionUtils.isNotEmpty(channelIds)) {
if (filtered) {
channels = new HashMap<String, Channel>();

for (Channel channel : donkey.getDeployedChannels().values()) {
for (Channel channel : deployedChannels.values()) {
if (channelIds.contains(channel.getChannelId())) {
channels.put(channel.getChannelId(), channel);
}
}
} else {
channels = new HashMap<String, Channel>(donkey.getDeployedChannels());
channels = new HashMap<String, Channel>(deployedChannels);
}

synchronized (deployingChannels) {
for (Channel channel : deployingChannels) {
if (!channels.containsKey(channel.getChannelId())) {
if ((!filtered || channelIds.contains(channel.getChannelId())) && !channels.containsKey(channel.getChannelId())) {
channels.put(channel.getChannelId(), channel);
}
}
}

synchronized (undeployingChannels) {
for (Channel channel : undeployingChannels) {
if (!channels.containsKey(channel.getChannelId())) {
if ((!filtered || channelIds.contains(channel.getChannelId())) && !channels.containsKey(channel.getChannelId())) {
channels.put(channel.getChannelId(), channel);
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
// SPDX-License-Identifier: MPL-2.0
// SPDX-FileCopyrightText: Open Integration Engine Contributors

package com.mirth.connect.server.controllers;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertSame;

import java.util.Arrays;
import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
import java.util.Set;

import org.junit.Test;

import com.mirth.connect.donkey.server.channel.Channel;

/**
* A request for specific channels must not return other channels that are mid-deploy or
* mid-undeploy. See OpenIntegrationEngine/engine#456.
*/
public class DonkeyEngineControllerDashboardChannelsTest {

private static Channel channel(String id) {
Channel channel = new Channel();
channel.setChannelId(id);
return channel;
}

private static Set<Channel> setOf(Channel... channels) {
return Collections.synchronizedSet(new HashSet<Channel>(Arrays.asList(channels)));
}

@Test
public void filteredRequestIgnoresOtherDeployingChannel() {
Channel a = channel("A");
Map<String, Channel> deployed = new HashMap<String, Channel>();
deployed.put("A", a);

Map<String, Channel> result = DonkeyEngineController.getDashboardChannels(deployed, setOf(channel("B")), setOf(), Collections.singleton("A"));

assertEquals(Collections.singleton("A"), result.keySet());
assertSame(a, result.get("A"));
}

@Test
public void filteredRequestIgnoresOtherUndeployingChannel() {
Map<String, Channel> result = DonkeyEngineController.getDashboardChannels(new HashMap<String, Channel>(), setOf(), setOf(channel("B")), Collections.singleton("A"));

assertEquals(Collections.<String> emptySet(), result.keySet());
}

@Test
public void filteredRequestIncludesRequestedChannelWhileItDeploys() {
Channel a = channel("A");

Map<String, Channel> result = DonkeyEngineController.getDashboardChannels(new HashMap<String, Channel>(), setOf(a, channel("B")), setOf(channel("C")), Collections.singleton("A"));

assertEquals(Collections.singleton("A"), result.keySet());
assertSame(a, result.get("A"));
}

@Test
public void unfilteredRequestIncludesDeployingAndUndeployingChannels() {
Map<String, Channel> deployed = new HashMap<String, Channel>();
deployed.put("A", channel("A"));

Map<String, Channel> result = DonkeyEngineController.getDashboardChannels(deployed, setOf(channel("B")), setOf(channel("C")), null);

assertEquals(new HashSet<String>(Arrays.asList("A", "B", "C")), result.keySet());
}

@Test
public void deployedChannelWinsOverSameIdInTransition() {
Channel deployedA = channel("A");
Map<String, Channel> deployed = new HashMap<String, Channel>();
deployed.put("A", deployedA);

Map<String, Channel> result = DonkeyEngineController.getDashboardChannels(deployed, setOf(channel("A")), setOf(), Collections.singleton("A"));

assertSame(deployedA, result.get("A"));
}
}