This is an automated email from the ASF dual-hosted git repository.
technoboy pushed a commit to branch branch-2.11
in repository https://gitbox.apache.org/repos/asf/pulsar.git
The following commit(s) were added to refs/heads/branch-2.11 by this push:
new 61e84634d51 [fix][broker] Skip loading broker interceptor when
disableBrokerInterceptors is true (#20422)
61e84634d51 is described below
commit 61e84634d51a23b1ccf20ee19f8defdcb68c5137
Author: Zixuan Liu <[email protected]>
AuthorDate: Tue May 30 17:57:08 2023 +0800
[fix][broker] Skip loading broker interceptor when
disableBrokerInterceptors is true (#20422)
Signed-off-by: Zixuan Liu <[email protected]>
---
.../apache/pulsar/broker/ServiceConfiguration.java | 2 +-
.../broker/intercept/BrokerInterceptors.java | 5 +++
.../broker/intercept/BrokerInterceptorTest.java | 51 ++++++++++++++++------
3 files changed, 43 insertions(+), 15 deletions(-)
diff --git
a/pulsar-broker-common/src/main/java/org/apache/pulsar/broker/ServiceConfiguration.java
b/pulsar-broker-common/src/main/java/org/apache/pulsar/broker/ServiceConfiguration.java
index 754c74ab3e7..965876fd0ab 100644
---
a/pulsar-broker-common/src/main/java/org/apache/pulsar/broker/ServiceConfiguration.java
+++
b/pulsar-broker-common/src/main/java/org/apache/pulsar/broker/ServiceConfiguration.java
@@ -1292,7 +1292,7 @@ public class ServiceConfiguration implements
PulsarConfiguration {
@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;
diff --git
a/pulsar-broker/src/main/java/org/apache/pulsar/broker/intercept/BrokerInterceptors.java
b/pulsar-broker/src/main/java/org/apache/pulsar/broker/intercept/BrokerInterceptors.java
index 6f71db312b7..229c32cd141 100644
---
a/pulsar-broker/src/main/java/org/apache/pulsar/broker/intercept/BrokerInterceptors.java
+++
b/pulsar-broker/src/main/java/org/apache/pulsar/broker/intercept/BrokerInterceptors.java
@@ -58,6 +58,11 @@ public class BrokerInterceptors implements BrokerInterceptor
{
* @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());
diff --git
a/pulsar-broker/src/test/java/org/apache/pulsar/broker/intercept/BrokerInterceptorTest.java
b/pulsar-broker/src/test/java/org/apache/pulsar/broker/intercept/BrokerInterceptorTest.java
index a2cff248f9f..1f53ac632d8 100644
---
a/pulsar-broker/src/test/java/org/apache/pulsar/broker/intercept/BrokerInterceptorTest.java
+++
b/pulsar-broker/src/test/java/org/apache/pulsar/broker/intercept/BrokerInterceptorTest.java
@@ -18,12 +18,28 @@
*/
package org.apache.pulsar.broker.intercept;
+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;
+import java.util.Map;
+import java.util.Set;
+import java.util.UUID;
+import java.util.concurrent.CompletableFuture;
import lombok.Cleanup;
import okhttp3.Call;
import okhttp3.Callback;
import okhttp3.OkHttpClient;
import okhttp3.Request;
import okhttp3.Response;
+import org.apache.pulsar.broker.ServiceConfiguration;
import org.apache.pulsar.client.admin.PulsarAdminException;
import org.apache.pulsar.client.api.Consumer;
import org.apache.pulsar.client.api.Message;
@@ -39,20 +55,6 @@ import org.testng.annotations.AfterMethod;
import org.testng.annotations.BeforeMethod;
import org.testng.annotations.Test;
-import java.io.IOException;
-import java.util.HashMap;
-import java.util.HashSet;
-import java.util.Map;
-import java.util.Set;
-import java.util.UUID;
-import java.util.concurrent.CompletableFuture;
-
-import static org.mockito.ArgumentMatchers.same;
-import static org.mockito.Mockito.mock;
-import static org.mockito.Mockito.times;
-import static org.mockito.Mockito.verify;
-import static org.testng.Assert.assertEquals;
-
@Test(groups = "broker")
public class BrokerInterceptorTest extends ProducerConsumerBase {
@@ -262,4 +264,25 @@ public class BrokerInterceptorTest extends
ProducerConsumerBase {
}
}
+ @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();
+ }
}