Skip to content

Commit

Permalink
[fix][client] ConsumerBuilderImpl can not set null to deadLetterPolicy (
Browse files Browse the repository at this point in the history
apache#14980)

### Motivation

`ConsumerBuilderImpl` can not set null to deadLetterPolicy if it's already assigned a non-null value.

### Modifications

Calls `conf.setDeadLetterPolicy` if `deadLetterPolicy` is null.
  • Loading branch information
Jason918 authored Apr 2, 2022
1 parent 5acdfdd commit 2f53071
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -437,10 +437,9 @@ public ConsumerBuilder<T> deadLetterPolicy(DeadLetterPolicy deadLetterPolicy) {
if (conf.getAckTimeoutMillis() == 0) {
conf.setAckTimeoutMillis(DEFAULT_ACK_TIMEOUT_MILLIS_FOR_DEAD_LETTER);
}

checkArgument(deadLetterPolicy.getMaxRedeliverCount() > 0, "MaxRedeliverCount must be > 0.");
conf.setDeadLetterPolicy(deadLetterPolicy);
}
conf.setDeadLetterPolicy(deadLetterPolicy);
return this;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,17 @@
*/
package org.apache.pulsar.client.impl;

import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
import static org.testng.Assert.assertNotNull;
import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.TimeUnit;
import java.util.regex.Pattern;
import org.apache.pulsar.client.api.BatchReceivePolicy;
import org.apache.pulsar.client.api.Consumer;
import org.apache.pulsar.client.api.DeadLetterPolicy;
Expand All @@ -29,19 +40,6 @@
import org.testng.annotations.BeforeTest;
import org.testng.annotations.Test;

import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.TimeUnit;
import java.util.regex.Pattern;

import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
import static org.testng.Assert.assertNotNull;

/**
* Unit tests of {@link ConsumerBuilderImpl}.
*/
Expand Down Expand Up @@ -299,6 +297,12 @@ public void testRedeliverCountOfDeadLetterPolicy() {
.build());
}

@Test
public void testNullDeadLetterPolicy() {
consumerBuilderImpl.deadLetterPolicy(null);
verify(consumerBuilderImpl.getConf()).setDeadLetterPolicy(null);
}

@Test
public void testConsumerBuilderImplWhenNumericPropertiesAreValid() {
consumerBuilderImpl.negativeAckRedeliveryDelay(1, TimeUnit.MILLISECONDS);
Expand Down

0 comments on commit 2f53071

Please sign in to comment.