Skip to content
This repository has been archived by the owner on Feb 1, 2024. It is now read-only.

Commit

Permalink
fix: filter all bindings that are not sns (#15)
Browse files Browse the repository at this point in the history
hendrik-nibbrig-idealo authored and heiko.rothe committed May 12, 2021
1 parent 9245184 commit d2e9500
Showing 3 changed files with 31 additions and 2 deletions.
Original file line number Diff line number Diff line change
@@ -14,7 +14,6 @@
import com.amazonaws.auth.AWSCredentialsProvider;
import com.amazonaws.services.sns.AmazonSNSAsync;
import com.amazonaws.services.sns.AmazonSNSAsyncClient;

import io.awspring.cloud.autoconfigure.messaging.SnsProperties;
import io.awspring.cloud.context.annotation.ConditionalOnMissingAmazonClient;
import io.awspring.cloud.core.config.AmazonWebserviceClientFactoryBean;
Original file line number Diff line number Diff line change
@@ -33,7 +33,10 @@ public SnsBinderHealthIndicator(final SnsMessageHandlerBinder snsMessageHandlerB
@Override
protected void doHealthCheck(Health.Builder builder) {

final List<String> topicList = bindingServiceProperties.getBindings().values().stream().map(bindingProperties -> bindingProperties.getDestination()).collect(toList());
final List<String> topicList = bindingServiceProperties.getBindings().values().stream()
.filter(bindingProperties -> "sns".equalsIgnoreCase(bindingProperties.getBinder()))
.map(bindingProperties -> bindingProperties.getDestination())
.collect(toList());

if (!topicsAreReachable(topicList)) {
builder.down().withDetail("SNS", "topic is not reachable");
Original file line number Diff line number Diff line change
@@ -5,6 +5,8 @@
import static org.mockito.Mockito.when;

import java.util.Collections;
import java.util.HashMap;
import java.util.Map;

import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
@@ -49,6 +51,7 @@ void reportsTrueWhenAllTopicsCanBeListed() {
when(amazonSNS.listTopics()).thenReturn(new ListTopicsResult().withTopics(new Topic().withTopicArn("blablabla:somemorebla:topicName")));
final BindingProperties binderProperties = new BindingProperties();
binderProperties.setDestination("topicName");
binderProperties.setBinder("sns");
when(bindingServiceProperties.getBindings()).thenReturn(Collections.singletonMap("doesn't matter", binderProperties));

Health.Builder builder = new Health.Builder();
@@ -63,6 +66,7 @@ void reportsTrueWhenMoreTopicsThenDestinationsArePresent() {
when(amazonSNS.listTopics()).thenReturn(new ListTopicsResult().withTopics(new Topic().withTopicArn("blablabla:somemorebla:topicName1")), new ListTopicsResult().withTopics(new Topic().withTopicArn("blablabla:somemorebla:topicName2")));
final BindingProperties binderProperties = new BindingProperties();
binderProperties.setDestination("topicName1");
binderProperties.setBinder("sns");
when(bindingServiceProperties.getBindings()).thenReturn(Collections.singletonMap("doesn't matter", binderProperties));

Health.Builder builder = new Health.Builder();
@@ -72,11 +76,34 @@ void reportsTrueWhenMoreTopicsThenDestinationsArePresent() {
assertThat(builder.build().getStatus()).isEqualTo(Status.UP);
}

@Test
void filtersOutNonSnsBinders() {
when(amazonSNS.listTopics()).thenReturn(new ListTopicsResult().withTopics(new Topic().withTopicArn("blablabla:somemorebla:topicName1")), new ListTopicsResult().withTopics(new Topic().withTopicArn("blablabla:somemorebla:topicName2")));
Map<String, BindingProperties> bindings = new HashMap<>();
final BindingProperties binderPropertiesSns = new BindingProperties();
binderPropertiesSns.setDestination("topicName1");
binderPropertiesSns.setBinder("sns");
bindings.put("doesn't matter", binderPropertiesSns);

final BindingProperties binderPropertiesKafka = new BindingProperties();
binderPropertiesKafka.setDestination("topicName2");
binderPropertiesKafka.setBinder("kafka");
bindings.put("still doesn't matter", binderPropertiesKafka);
when(bindingServiceProperties.getBindings()).thenReturn(bindings);

Health.Builder builder = new Health.Builder();

healthIndicator.doHealthCheck(builder);

assertThat(builder.build().getStatus()).isEqualTo(Status.UP);
}

@Test
void reportsFalseWhenAnExpectedTopicIsNotPresent() {
when(amazonSNS.listTopics()).thenReturn(new ListTopicsResult().withTopics(new Topic().withTopicArn("blablabla:somemorebla:wrongTopicName")));
final BindingProperties binderProperties = new BindingProperties();
binderProperties.setDestination("topicName");
binderProperties.setBinder("sns");
when(bindingServiceProperties.getBindings()).thenReturn(Collections.singletonMap("doesn't matter", binderProperties));

Health.Builder builder = new Health.Builder();

0 comments on commit d2e9500

Please sign in to comment.