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

fix: Ensure topic exists in consumer only if autoCreateResources is true #2295

Merged
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 @@ -77,6 +77,9 @@ public ConsumerDestination provisionConsumerDestination(
// topicName may be either the short or fully-qualified version.
String topicShortName =
TopicName.isParsableFrom(topicName) ? TopicName.parse(topicName).getTopic() : topicName;
if (autoCreate) {
ensureTopicExists(topicShortName, autoCreate);
}

String subscriptionName = null;
if (StringUtils.hasText(customName)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import static org.assertj.core.api.Assertions.assertThatExceptionOfType;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.Mockito.doAnswer;
import static org.mockito.Mockito.doReturn;
import static org.mockito.Mockito.never;
import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify;
Expand Down Expand Up @@ -286,6 +287,33 @@ void testProvisionConsumerDestination_createSubscription() {
assertThat(subscription.getTopic()).isEqualTo("topic_A");
}


@Test
void testProvisionConsumerDestination_createTopic_whenAutoCreateResources_isTrue() {
doReturn(null).when(this.pubSubAdminMock).getTopic("not_yet_created");

PubSubConsumerDestination result =
(PubSubConsumerDestination)
this.pubSubChannelProvisioner.provisionConsumerDestination(
"not_yet_created", "group_A", this.extendedConsumerProperties);

verify(pubSubAdminMock).getTopic("not_yet_created");
verify(pubSubAdminMock).createTopic("not_yet_created");
}

@Test
void testProvisionConsumerDestination_dontCreateTopic_whenAutoCreateResources_isFalse() {
when(this.pubSubConsumerProperties.isAutoCreateResources()).thenReturn(false);

PubSubConsumerDestination result =
(PubSubConsumerDestination)
this.pubSubChannelProvisioner.provisionConsumerDestination(
"not_yet_created", "group_A", this.extendedConsumerProperties);

verify(pubSubAdminMock, never()).getTopic("not_yet_created");
verify(pubSubAdminMock, never()).createTopic("not_yet_created");
}

@Test
void testProvisionProducerDestination_createTopic() {
ProducerDestination destination = this.pubSubChannelProvisioner.provisionProducerDestination(
Expand Down
Loading