Skip to content

Commit

Permalink
[fix][broker] Skip loading broker interceptor when disableBrokerInter…
Browse files Browse the repository at this point in the history
…ceptors is true (#20422)

Signed-off-by: Zixuan Liu <nodeces@gmail.com>
(cherry picked from commit 639c460)
  • Loading branch information
nodece authored and poorbarcode committed May 30, 2023
1 parent d09664a commit 1ce9cca
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -1353,7 +1353,7 @@ The delayed message index time step(in seconds) in per bucket snapshot segment,

@FieldContext(
category = CATEGORY_SERVER,
doc = "Enable or disable the broker interceptor, which is only used for testing for now"
doc = "Enable or disable the broker interceptor"
)
private boolean disableBrokerInterceptors = true;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,11 @@ public BrokerInterceptors(Map<String, BrokerInterceptorWithClassLoader> intercep
* @return the collection of broker event interceptor
*/
public static BrokerInterceptor load(ServiceConfiguration conf) throws IOException {
if (conf.isDisableBrokerInterceptors()) {
log.info("Skip loading the broker interceptors when disableBrokerInterceptors is true");
return null;
}

BrokerInterceptorDefinitions definitions =
BrokerInterceptorUtils.searchForInterceptors(conf.getBrokerInterceptorsDirectory(),
conf.getNarExtractionDirectory());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,12 @@

import static org.mockito.ArgumentMatchers.same;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.spy;
import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify;
import static org.testng.Assert.assertEquals;
import static org.testng.Assert.assertNull;

import java.io.IOException;
import java.util.HashMap;
import java.util.HashSet;
Expand All @@ -36,6 +39,7 @@
import okhttp3.OkHttpClient;
import okhttp3.Request;
import okhttp3.Response;
import org.apache.pulsar.broker.ServiceConfiguration;
import org.apache.pulsar.broker.testcontext.PulsarTestContext;
import org.apache.pulsar.client.admin.PulsarAdminException;
import org.apache.pulsar.client.api.Consumer;
Expand Down Expand Up @@ -307,4 +311,25 @@ public void requestInterceptorFailedTest() {
}
}

@Test
public void testLoadWhenDisableBrokerInterceptorsIsTrue() throws IOException {
ServiceConfiguration serviceConfiguration = spy(ServiceConfiguration.class);
serviceConfiguration.setDisableBrokerInterceptors(true);
BrokerInterceptor brokerInterceptor = BrokerInterceptors.load(serviceConfiguration);
assertNull(brokerInterceptor);

verify(serviceConfiguration, times(1)).isDisableBrokerInterceptors();
verify(serviceConfiguration, times(0)).getBrokerInterceptorsDirectory();
}

@Test
public void testLoadWhenDisableBrokerInterceptorsIsFalse() throws IOException {
ServiceConfiguration serviceConfiguration = spy(ServiceConfiguration.class);
serviceConfiguration.setDisableBrokerInterceptors(false);
BrokerInterceptor brokerInterceptor = BrokerInterceptors.load(serviceConfiguration);
assertNull(brokerInterceptor);

verify(serviceConfiguration, times(1)).isDisableBrokerInterceptors();
verify(serviceConfiguration, times(1)).getBrokerInterceptorsDirectory();
}
}

0 comments on commit 1ce9cca

Please sign in to comment.