Skip to content

Commit

Permalink
fix: provide setters for min/max duration per ack ext (#1644)
Browse files Browse the repository at this point in the history
Fixes: #1643.
  • Loading branch information
meltsufin committed Mar 6, 2023
1 parent 4bfaebf commit cd3a75c
Show file tree
Hide file tree
Showing 2 changed files with 60 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -507,6 +507,15 @@ Duration getMinDurationPerAckExtension(String subscriptionName) {
return extension == null ? null : Duration.ofSeconds(extension);
}

/**
* Sets the min duration per ack extension override for all subscriptions.
*
* @param minDurationPerAckExtension the min duration per ack extension
*/
public void setMinDurationPerAckExtension(@Nullable Duration minDurationPerAckExtension) {
this.minDurationPerAckExtension = minDurationPerAckExtension;
}

@Nullable
Duration getMaxDurationPerAckExtension(String subscriptionName) {
if (this.maxDurationPerAckExtension != null) {
Expand All @@ -518,6 +527,15 @@ Duration getMaxDurationPerAckExtension(String subscriptionName) {
return extension == null ? null : Duration.ofSeconds(extension);
}

/**
* Sets the max duration per ack extension override for all subscriptions.
*
* @param maxDurationPerAckExtension the max duration per ack extension
*/
public void setMaxDurationPerAckExtension(@Nullable Duration maxDurationPerAckExtension) {
this.maxDurationPerAckExtension = maxDurationPerAckExtension;
}

Integer getPullCount(String subscriptionName) {
if (this.parallelPullCount != null) {
return this.parallelPullCount;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -542,6 +542,48 @@ void testGetMinDurationPerAckExtension_userSetValue() {
.isEqualTo(Duration.ofSeconds(1));
}

@Test
void testGetMinDurationPerAckExtension_factorySetValue() {
GcpProjectIdProvider projectIdProvider = () -> "project";
DefaultSubscriberFactory factory =
new DefaultSubscriberFactory(projectIdProvider, mockPubSubConfiguration);

when(mockPubSubConfiguration.computeMinDurationPerAckExtension("subscription-name",
projectIdProvider.getProjectId())).thenReturn(3L);

// subscription level setting is used when factory-level one is not provided
assertThat(factory.getMinDurationPerAckExtension("subscription-name"))
.isEqualTo(Duration.ofSeconds(3));

// this setting should override the subscription-level one
factory.setMinDurationPerAckExtension(Duration.ofSeconds(2));

// factory-level setting is used even when subscription level one is provided
assertThat(factory.getMinDurationPerAckExtension("subscription-name"))
.isEqualTo(Duration.ofSeconds(2));
}

@Test
void testGetMaxDurationPerAckExtension_factorySetValue() {
GcpProjectIdProvider projectIdProvider = () -> "project";
DefaultSubscriberFactory factory =
new DefaultSubscriberFactory(projectIdProvider, mockPubSubConfiguration);

when(mockPubSubConfiguration.computeMaxDurationPerAckExtension("subscription-name",
projectIdProvider.getProjectId())).thenReturn(3L);

// subscription level setting is used when factory-level one is not provided
assertThat(factory.getMaxDurationPerAckExtension("subscription-name"))
.isEqualTo(Duration.ofSeconds(3));

// this setting should override the subscription-level one
factory.setMaxDurationPerAckExtension(Duration.ofSeconds(2));

// factory-level setting is used even when subscription level one is provided
assertThat(factory.getMaxDurationPerAckExtension("subscription-name"))
.isEqualTo(Duration.ofSeconds(2));
}

@Test
void testGetMinDurationPerAckExtension_newConfiguration() {
GcpProjectIdProvider projectIdProvider = () -> "project";
Expand Down

0 comments on commit cd3a75c

Please sign in to comment.