Skip to content

Commit 14ce938

Browse files
fix: GoogleCloudPlatform#3694: Producer destination: ensure topic exists or create one, only if auto create resource is true
1 parent cabb7a5 commit 14ce938

File tree

2 files changed

+4
-14
lines changed

2 files changed

+4
-14
lines changed

spring-cloud-gcp-pubsub-stream-binder/src/main/java/com/google/cloud/spring/stream/binder/pubsub/provisioning/PubSubChannelProvisioner.java

+4-1
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,10 @@ public PubSubChannelProvisioner(PubSubAdmin pubSubAdmin) {
5858
@Override
5959
public ProducerDestination provisionProducerDestination(
6060
String topic, ExtendedProducerProperties<PubSubProducerProperties> properties) {
61-
ensureTopicExists(topic, properties.getExtension().isAutoCreateResources());
61+
boolean autoCreate = properties.getExtension().isAutoCreateResources();
62+
if (autoCreate) {
63+
ensureTopicExists(topic, autoCreate);
64+
}
6265

6366
return new PubSubProducerDestination(topic);
6467
}

spring-cloud-gcp-pubsub-stream-binder/src/test/java/com/google/cloud/spring/stream/binder/pubsub/provisioning/PubSubChannelProvisionerTests.java

-13
Original file line numberDiff line numberDiff line change
@@ -390,17 +390,4 @@ void testProvisionProducerDestination_createTopic() {
390390

391391
assertThat(destination.getName()).isEqualTo("topic_A");
392392
}
393-
394-
@Test
395-
void testProvisionProducerDestination_dontCreateTopic() {
396-
when(this.pubSubProducerProperties.isAutoCreateResources()).thenReturn(false);
397-
when(this.pubSubAdminMock.getTopic(any())).thenReturn(null);
398-
399-
assertThatExceptionOfType(ProvisioningException.class)
400-
.isThrownBy(
401-
() ->
402-
this.pubSubChannelProvisioner.provisionProducerDestination(
403-
"not_yet_created", extendedProducerProperties))
404-
.withMessageContaining("Non-existing");
405-
}
406393
}

0 commit comments

Comments
 (0)