test
This commit is contained in:
parent
fd8b5206e7
commit
99fee443fd
|
@ -13,7 +13,7 @@ import java.util.Optional;
|
|||
@Component
|
||||
public class SubscriptionChannelRegistry {
|
||||
private final SubscriptionChannelCache mySubscriptionChannelCache = new SubscriptionChannelCache();
|
||||
// This map is a reference count so we know to destroy the channel if there are no more active subscriptions using it
|
||||
// This map is a reference count so we know to destroy the channel when there are no more active subscriptions using it
|
||||
private final Multimap<String, ActiveSubscription> myActiveSubscriptionByChannelName = MultimapBuilder.hashKeys().arrayListValues().build();
|
||||
|
||||
@Autowired
|
||||
|
@ -48,11 +48,12 @@ public class SubscriptionChannelRegistry {
|
|||
public void remove(ActiveSubscription theActiveSubscription) {
|
||||
String channelName = theActiveSubscription.getChannelName();
|
||||
myActiveSubscriptionByChannelName.remove(channelName, theActiveSubscription);
|
||||
// FIXME KHS test
|
||||
|
||||
// This was the last one. Shut down the channel
|
||||
if (!myActiveSubscriptionByChannelName.containsKey(channelName)) {
|
||||
SubscriptionChannelWithHandlers channel = mySubscriptionChannelCache.get(channelName);
|
||||
channel.close();
|
||||
mySubscriptionChannelCache.remove(channelName);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -0,0 +1,57 @@
|
|||
package ca.uhn.fhir.jpa.subscription.module.channel;
|
||||
|
||||
import ca.uhn.fhir.jpa.model.entity.ModelConfig;
|
||||
import ca.uhn.fhir.jpa.subscription.module.CanonicalSubscription;
|
||||
import ca.uhn.fhir.jpa.subscription.module.cache.ActiveSubscription;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.boot.test.mock.mockito.MockBean;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.test.context.junit4.SpringRunner;
|
||||
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
import static org.junit.Assert.assertNull;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
@RunWith(SpringRunner.class)
|
||||
public class SubscriptionChannelRegistryTest {
|
||||
private static final String TEST_CHANNEL_NAME = "TEST_CHANNEL";
|
||||
@Autowired
|
||||
SubscriptionChannelRegistry mySubscriptionChannelRegistry;
|
||||
@MockBean
|
||||
SubscriptionDeliveryHandlerFactory mySubscriptionDeliveryHandlerFactory;
|
||||
@MockBean
|
||||
SubscriptionChannelFactory mySubscriptionDeliveryChannelFactory;
|
||||
@MockBean
|
||||
ModelConfig myModelConfig;
|
||||
|
||||
@Configuration
|
||||
static class SpringConfig {
|
||||
@Bean
|
||||
SubscriptionChannelRegistry subscriptionChannelRegistry() {
|
||||
return new SubscriptionChannelRegistry();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testAddAddRemoveRemove() {
|
||||
when(myModelConfig.isSubscriptionMatchingEnabled()).thenReturn(true);
|
||||
|
||||
CanonicalSubscription cansubA = new CanonicalSubscription();
|
||||
ActiveSubscription activeSubscriptionA = new ActiveSubscription(cansubA, TEST_CHANNEL_NAME);
|
||||
CanonicalSubscription cansubB = new CanonicalSubscription();
|
||||
ActiveSubscription activeSubscriptionB = new ActiveSubscription(cansubB, TEST_CHANNEL_NAME);
|
||||
|
||||
assertNull(mySubscriptionChannelRegistry.get(TEST_CHANNEL_NAME));
|
||||
mySubscriptionChannelRegistry.add(activeSubscriptionA);
|
||||
assertNotNull(mySubscriptionChannelRegistry.get(TEST_CHANNEL_NAME));
|
||||
mySubscriptionChannelRegistry.add(activeSubscriptionB);
|
||||
mySubscriptionChannelRegistry.remove(activeSubscriptionB);
|
||||
assertNotNull(mySubscriptionChannelRegistry.get(TEST_CHANNEL_NAME));
|
||||
mySubscriptionChannelRegistry.remove(activeSubscriptionA);
|
||||
assertNull(mySubscriptionChannelRegistry.get(TEST_CHANNEL_NAME));
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue