This is an automated email from the ASF dual-hosted git repository.

jt2594838 pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/iotdb.git


The following commit(s) were added to refs/heads/master by this push:
     new 574aa691f0e [Subscription] Add a switch for consensus fallback polling 
(#19062)
574aa691f0e is described below

commit 574aa691f0e68f769f26440f8c2ce9b05652f141
Author: Caideyipi <[email protected]>
AuthorDate: Mon Nov 2 10:31:20 2026 +0800

    [Subscription] Add a switch for consensus fallback polling (#19062)
    
    * [Subscription] Add a switch for consensus fallback polling
    
    * [Subscription] Add cluster coverage for disabled fallback polling
---
 ...oTDBConsensusSubscriptionFallbackPollingIT.java | 204 +++++++++++++++++++++
 .../broker/ConsensusSubscriptionBroker.java        |   4 +-
 ...onsensusSubscriptionBrokerPayloadLimitTest.java |  68 +++++++
 .../conf/iotdb-system.properties.template          |   6 +
 .../apache/iotdb/commons/conf/CommonConfig.java    |  12 ++
 .../iotdb/commons/conf/CommonDescriptor.java       |   5 +
 .../subscription/config/SubscriptionConfig.java    |   4 +
 ...nDescriptorSubscriptionFallbackPollingTest.java |  60 ++++++
 8 files changed, 362 insertions(+), 1 deletion(-)

diff --git 
a/integration-test/src/test/java/org/apache/iotdb/subscription/it/consensus/local/IoTDBConsensusSubscriptionFallbackPollingIT.java
 
b/integration-test/src/test/java/org/apache/iotdb/subscription/it/consensus/local/IoTDBConsensusSubscriptionFallbackPollingIT.java
new file mode 100644
index 00000000000..a8486c6a313
--- /dev/null
+++ 
b/integration-test/src/test/java/org/apache/iotdb/subscription/it/consensus/local/IoTDBConsensusSubscriptionFallbackPollingIT.java
@@ -0,0 +1,204 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.iotdb.subscription.it.consensus.local;
+
+import org.apache.iotdb.consensus.ConsensusFactory;
+import org.apache.iotdb.it.env.EnvFactory;
+import org.apache.iotdb.it.env.cluster.config.MppBaseConfig;
+import org.apache.iotdb.it.framework.IoTDBTestRunner;
+import org.apache.iotdb.itbase.category.ClusterIT;
+import org.apache.iotdb.session.subscription.SubscriptionTreeSession;
+import 
org.apache.iotdb.session.subscription.consumer.tree.SubscriptionTreePullConsumer;
+import org.apache.iotdb.session.subscription.model.Subscription;
+import org.apache.iotdb.subscription.it.AbstractSubscriptionIT;
+
+import org.awaitility.Awaitility;
+import org.junit.After;
+import org.junit.Assert;
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.experimental.categories.Category;
+import org.junit.runner.RunWith;
+
+import java.time.Duration;
+import java.util.Properties;
+import java.util.Set;
+import java.util.concurrent.TimeUnit;
+
+@RunWith(IoTDBTestRunner.class)
+@Category({ClusterIT.class})
+public class IoTDBConsensusSubscriptionFallbackPollingIT extends 
AbstractSubscriptionIT {
+
+  private static final int ROWS_PER_REGION = 6;
+  private static final Duration POLL_TIMEOUT = Duration.ofSeconds(1);
+
+  @Override
+  @Before
+  public void setUp() throws Exception {
+    super.setUp();
+    EnvFactory.getEnv()
+        .getConfig()
+        .getCommonConfig()
+        .setConfigNodeConsensusProtocolClass(ConsensusFactory.RATIS_CONSENSUS)
+        
.setSchemaRegionConsensusProtocolClass(ConsensusFactory.RATIS_CONSENSUS)
+        .setDataRegionConsensusProtocolClass(ConsensusFactory.IOT_CONSENSUS)
+        .setDataRegionGroupExtensionPolicy("CUSTOM")
+        .setDefaultDataRegionGroupNumPerDatabase(1)
+        .setSchemaReplicationFactor(1)
+        .setDataReplicationFactor(3)
+        .setAutoCreateSchemaEnabled(true)
+        .setPipeMemoryManagementEnabled(false)
+        .setIsPipeEnableMemoryCheck(false);
+
+    final Properties subscriptionProperties = new Properties();
+    subscriptionProperties.setProperty("subscription_enabled", "true");
+    
subscriptionProperties.setProperty("subscription_consensus_fallback_polling_enabled",
 "false");
+    ((MppBaseConfig) EnvFactory.getEnv().getConfig().getDataNodeCommonConfig())
+        .updateProperties(subscriptionProperties);
+    ((MppBaseConfig) 
EnvFactory.getEnv().getConfig().getConfigNodeCommonConfig())
+        .updateProperties(subscriptionProperties);
+
+    EnvFactory.getEnv().initClusterEnvironment(1, 3);
+  }
+
+  @Override
+  @After
+  public void tearDown() throws Exception {
+    try {
+      EnvFactory.getEnv().cleanClusterEnvironment();
+    } finally {
+      super.tearDown();
+    }
+  }
+
+  @Test
+  public void testConsumerWithoutAssignedRegionDoesNotBorrowFallbackEvents() 
throws Exception {
+    final ConsensusSubscriptionITSupport.TestIdentifiers ids =
+        
ConsensusSubscriptionITSupport.newIdentifiers("fallback_polling_disabled");
+    SubscriptionTreePullConsumer consumerA = null;
+    SubscriptionTreePullConsumer consumerB = null;
+
+    try {
+      ConsensusSubscriptionITSupport.bootstrapDatabase(ids.getDatabase());
+      ConsensusSubscriptionITSupport.createConsensusTopic(
+          ids.getTopic(), ids.getDatabase() + ".**");
+      consumerA =
+          ConsensusSubscriptionITSupport.createConsumer(
+              ids.consumer("a"), ids.getConsumerGroupId());
+      consumerA.subscribe(ids.getTopic());
+      // Receiving a seed row proves that A owns the region before B starts 
polling.
+      final Set<String> seedRowKeys =
+          ConsensusSubscriptionITSupport.insertRows(ids.getDatabase(), "d0", 
1L, 1, true);
+      assertEventuallyConsumed(consumerA, seedRowKeys);
+      consumerB =
+          ConsensusSubscriptionITSupport.createConsumer(
+              ids.consumer("b"), ids.getConsumerGroupId());
+      consumerB.subscribe(ids.getTopic());
+      awaitBothConsumersRegistered(ids);
+      // Keep A's existing ownership while making both consumers active on the 
broker.
+      consumerA.poll(POLL_TIMEOUT);
+      consumerB.poll(POLL_TIMEOUT);
+
+      final Set<String> expectedRowKeys =
+          ConsensusSubscriptionITSupport.insertRows(
+              ids.getDatabase(), "d0", 100L, ROWS_PER_REGION, true);
+
+      // Leave the owner idle while B polls so that enabled fallback would 
borrow the ready rows.
+      final SubscriptionTreePullConsumer borrower = consumerB;
+      Awaitility.await()
+          .pollInSameThread()
+          .pollInterval(100, TimeUnit.MILLISECONDS)
+          .during(5, TimeUnit.SECONDS)
+          .atMost(10, TimeUnit.SECONDS)
+          .until(
+              () -> {
+                Assert.assertTrue(
+                    "A consumer without an assigned region borrowed 
subscription messages",
+                    borrower.poll(POLL_TIMEOUT).isEmpty());
+                return true;
+              });
+      assertEventuallyConsumed(consumerA, expectedRowKeys);
+    } finally {
+      closeConsumer(consumerB, ids);
+      closeConsumer(consumerA, ids);
+      ConsensusSubscriptionITSupport.cleanup(null, ids.getTopic(), 
ids.getDatabase());
+    }
+  }
+
+  private static void assertEventuallyConsumed(
+      final SubscriptionTreePullConsumer consumer, final Set<String> 
expectedRowKeys) {
+    final ConsensusSubscriptionITSupport.ConsumedRecords consumed =
+        new ConsensusSubscriptionITSupport.ConsumedRecords();
+    Awaitility.await()
+        .pollInSameThread()
+        .pollInterval(100, TimeUnit.MILLISECONDS)
+        .atMost(30, TimeUnit.SECONDS)
+        .untilAsserted(
+            () -> {
+              final ConsensusSubscriptionITSupport.PolledMessageBatch batch =
+                  
ConsensusSubscriptionITSupport.pollFirstNonEmptyBatchWithoutCommit(
+                      consumer, 1, POLL_TIMEOUT);
+              consumed.merge(batch.getConsumedRecords());
+              consumer.commitSync(batch.getMessages());
+              
ConsensusSubscriptionITSupport.assertExactRowKeys(expectedRowKeys, consumed);
+            });
+  }
+
+  private static void awaitBothConsumersRegistered(
+      final ConsensusSubscriptionITSupport.TestIdentifiers ids) throws 
Exception {
+    try (final SubscriptionTreeSession session =
+        new SubscriptionTreeSession(
+            EnvFactory.getEnv().getIP(), 
Integer.parseInt(EnvFactory.getEnv().getPort()))) {
+      session.open();
+      Awaitility.await()
+          .pollInSameThread()
+          .atMost(30, TimeUnit.SECONDS)
+          .pollInterval(100, TimeUnit.MILLISECONDS)
+          .untilAsserted(
+              () -> {
+                final Set<Subscription> subscriptions = 
session.getSubscriptions(ids.getTopic());
+                Assert.assertEquals(subscriptions.toString(), 1, 
subscriptions.size());
+                final Subscription subscription = 
subscriptions.iterator().next();
+                Assert.assertEquals(ids.getConsumerGroupId(), 
subscription.getConsumerGroupId());
+                final String consumers = subscription.getConsumerIds();
+                Assert.assertTrue(consumers, 
consumers.contains(ids.consumer("a")));
+                Assert.assertTrue(consumers, 
consumers.contains(ids.consumer("b")));
+              });
+    }
+  }
+
+  private static void closeConsumer(
+      final SubscriptionTreePullConsumer consumer,
+      final ConsensusSubscriptionITSupport.TestIdentifiers ids) {
+    if (consumer == null) {
+      return;
+    }
+    try {
+      consumer.unsubscribe(ids.getTopic());
+    } catch (final Exception ignored) {
+      // Best effort cleanup after a failed assertion.
+    }
+    try {
+      consumer.close();
+    } catch (final Exception ignored) {
+      // Best effort cleanup after a failed assertion.
+    }
+  }
+}
diff --git 
a/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/subscription/broker/ConsensusSubscriptionBroker.java
 
b/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/subscription/broker/ConsensusSubscriptionBroker.java
index 22c79ac7303..1d3f371e31e 100644
--- 
a/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/subscription/broker/ConsensusSubscriptionBroker.java
+++ 
b/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/subscription/broker/ConsensusSubscriptionBroker.java
@@ -143,7 +143,9 @@ public class ConsensusSubscriptionBroker implements 
ISubscriptionBroker {
       final List<ConsensusPrefetchingQueue> pollQueues =
           new ArrayList<>(buildPollOrderForAssignedQueues(assignedQueues, 
topicName));
       final int assignedQueueCount = pollQueues.size();
-      pollQueues.addAll(buildFallbackPollOrder(queues, assignedQueues));
+      if 
(SubscriptionConfig.getInstance().isSubscriptionConsensusFallbackPollingEnabled())
 {
+        pollQueues.addAll(buildFallbackPollOrder(queues, assignedQueues));
+      }
       if (pollQueues.isEmpty()) {
         continue;
       }
diff --git 
a/iotdb-core/datanode/src/test/java/org/apache/iotdb/db/subscription/broker/ConsensusSubscriptionBrokerPayloadLimitTest.java
 
b/iotdb-core/datanode/src/test/java/org/apache/iotdb/db/subscription/broker/ConsensusSubscriptionBrokerPayloadLimitTest.java
index c2cb73d8fd2..4ee58155f91 100644
--- 
a/iotdb-core/datanode/src/test/java/org/apache/iotdb/db/subscription/broker/ConsensusSubscriptionBrokerPayloadLimitTest.java
+++ 
b/iotdb-core/datanode/src/test/java/org/apache/iotdb/db/subscription/broker/ConsensusSubscriptionBrokerPayloadLimitTest.java
@@ -19,11 +19,15 @@
 
 package org.apache.iotdb.db.subscription.broker;
 
+import org.apache.iotdb.commons.conf.CommonConfig;
+import org.apache.iotdb.commons.conf.CommonDescriptor;
 import org.apache.iotdb.commons.consensus.DataRegionId;
 import 
org.apache.iotdb.db.subscription.broker.consensus.ConsensusPrefetchingQueue;
 import org.apache.iotdb.db.subscription.event.SubscriptionEvent;
 import 
org.apache.iotdb.rpc.subscription.payload.poll.SubscriptionCommitContext;
 
+import org.junit.After;
+import org.junit.Before;
 import org.junit.Test;
 
 import java.lang.reflect.Field;
@@ -34,6 +38,7 @@ import java.util.Map;
 
 import static org.junit.Assert.assertEquals;
 import static org.junit.Assert.assertSame;
+import static org.junit.Assert.assertTrue;
 import static org.mockito.Mockito.mock;
 import static org.mockito.Mockito.never;
 import static org.mockito.Mockito.verify;
@@ -46,6 +51,20 @@ public class ConsensusSubscriptionBrokerPayloadLimitTest {
   private static final String OTHER_CONSUMER_ID = "otherConsumer";
   private static final String TOPIC_NAME = "topic";
 
+  private final CommonConfig config = 
CommonDescriptor.getInstance().getConfig();
+  private boolean originalFallbackPollingEnabled;
+
+  @Before
+  public void setUp() {
+    originalFallbackPollingEnabled = 
config.isSubscriptionConsensusFallbackPollingEnabled();
+    config.setSubscriptionConsensusFallbackPollingEnabled(true);
+  }
+
+  @After
+  public void tearDown() {
+    
config.setSubscriptionConsensusFallbackPollingEnabled(originalFallbackPollingEnabled);
+  }
+
   @Test
   public void testPollRequeuesEventThatWouldExceedPayloadLimit() throws 
Exception {
     final ConsensusSubscriptionBroker broker = new 
ConsensusSubscriptionBroker(CONSUMER_GROUP_ID);
@@ -126,6 +145,55 @@ public class ConsensusSubscriptionBrokerPayloadLimitTest {
     verify(fallbackQueue, never()).poll(CONSUMER_ID, null);
   }
 
+  @Test
+  public void testPollDoesNotBorrowReadyEventWhenFallbackDisabled() throws 
Exception {
+    config.setSubscriptionConsensusFallbackPollingEnabled(false);
+    final ConsensusSubscriptionBroker broker = new 
ConsensusSubscriptionBroker(CONSUMER_GROUP_ID);
+    final ConsensusPrefetchingQueue fallbackQueue = 
mock(ConsensusPrefetchingQueue.class);
+    final ConsensusPrefetchingQueue assignedQueue = 
mock(ConsensusPrefetchingQueue.class);
+    final SubscriptionEvent fallbackEvent = mock(SubscriptionEvent.class);
+
+    when(fallbackQueue.getConsensusGroupId()).thenReturn(new DataRegionId(1));
+    when(assignedQueue.getConsensusGroupId()).thenReturn(new DataRegionId(2));
+    when(fallbackQueue.getPrefetchedEventCount()).thenReturn(1);
+    when(fallbackQueue.poll(CONSUMER_ID, null)).thenReturn(fallbackEvent);
+    when(fallbackEvent.getCurrentResponseSize()).thenReturn(30);
+    bindQueues(broker, Arrays.asList(fallbackQueue, assignedQueue));
+
+    broker.poll(OTHER_CONSUMER_ID, Collections.singleton(TOPIC_NAME), 60L);
+    final List<SubscriptionEvent> events =
+        broker.poll(CONSUMER_ID, Collections.singleton(TOPIC_NAME), 60L);
+
+    assertTrue(events.isEmpty());
+    verify(assignedQueue).poll(CONSUMER_ID, null);
+    verify(fallbackQueue, never()).poll(CONSUMER_ID, null);
+
+    // The ready event remains available to the region's owner.
+    when(fallbackQueue.poll(OTHER_CONSUMER_ID, 
null)).thenReturn(fallbackEvent);
+    final List<SubscriptionEvent> ownerEvents =
+        broker.poll(OTHER_CONSUMER_ID, Collections.singleton(TOPIC_NAME), 60L);
+    assertEquals(1, ownerEvents.size());
+    assertSame(fallbackEvent, ownerEvents.get(0));
+  }
+
+  @Test
+  public void testPollWithoutAssignedRegionDoesNotBorrowWhenFallbackDisabled() 
throws Exception {
+    config.setSubscriptionConsensusFallbackPollingEnabled(false);
+    final ConsensusSubscriptionBroker broker = new 
ConsensusSubscriptionBroker(CONSUMER_GROUP_ID);
+    final ConsensusPrefetchingQueue queue = 
mock(ConsensusPrefetchingQueue.class);
+    final SubscriptionEvent event = mock(SubscriptionEvent.class);
+
+    when(queue.getConsensusGroupId()).thenReturn(new DataRegionId(1));
+    when(queue.getPrefetchedEventCount()).thenReturn(1);
+    when(queue.poll(CONSUMER_ID, null)).thenReturn(event);
+    bindQueues(broker, Collections.singletonList(queue));
+
+    broker.poll(OTHER_CONSUMER_ID, Collections.singleton(TOPIC_NAME), 60L);
+    assertTrue(broker.poll(CONSUMER_ID, Collections.singleton(TOPIC_NAME), 
60L).isEmpty());
+
+    verify(queue, never()).poll(CONSUMER_ID, null);
+  }
+
   @Test
   public void testRequeueInFlightEventsAcrossRegionQueues() throws Exception {
     final ConsensusSubscriptionBroker broker = new 
ConsensusSubscriptionBroker(CONSUMER_GROUP_ID);
diff --git 
a/iotdb-core/node-commons/src/assembly/resources/conf/iotdb-system.properties.template
 
b/iotdb-core/node-commons/src/assembly/resources/conf/iotdb-system.properties.template
index 4db46c0cdbf..a3fe0970318 100644
--- 
a/iotdb-core/node-commons/src/assembly/resources/conf/iotdb-system.properties.template
+++ 
b/iotdb-core/node-commons/src/assembly/resources/conf/iotdb-system.properties.template
@@ -2179,6 +2179,12 @@ subscription_cache_memory_usage_percentage=0.2
 # Datatype: int
 subscription_consensus_prefetch_executor_max_thread_num=2
 
+# Whether consumers can poll ready events from regions assigned to other 
consumers when their own
+# assigned regions are empty. Disable this to preserve per-region consumer 
affinity.
+# effectiveMode: restart
+# Datatype: boolean
+subscription_consensus_fallback_polling_enabled=true
+
 # Maximum materialized consensus-subscription batch size. This is a batching 
target, not a hard
 # limit on one WAL entry/tablet. For large-field workloads, choose a value at 
least as large as a
 # typical single tablet if batching is desired, and provide enough 
materialization memory per queue.
diff --git 
a/iotdb-core/node-commons/src/main/java/org/apache/iotdb/commons/conf/CommonConfig.java
 
b/iotdb-core/node-commons/src/main/java/org/apache/iotdb/commons/conf/CommonConfig.java
index d307e8bfa36..517cce0a117 100644
--- 
a/iotdb-core/node-commons/src/main/java/org/apache/iotdb/commons/conf/CommonConfig.java
+++ 
b/iotdb-core/node-commons/src/main/java/org/apache/iotdb/commons/conf/CommonConfig.java
@@ -445,6 +445,9 @@ public class CommonConfig {
 
   private boolean subscriptionConsensusLagBasedPriority = true;
 
+  // Disable fallback polling to keep each region's events with its assigned 
consumer.
+  private boolean subscriptionConsensusFallbackPollingEnabled = true;
+
   private int subscriptionConsensusPrefetchingQueueCapacity = 256;
 
   private boolean subscriptionConsensusWatermarkEnabled = false;
@@ -2876,6 +2879,15 @@ public class CommonConfig {
     this.subscriptionConsensusLagBasedPriority = 
subscriptionConsensusLagBasedPriority;
   }
 
+  public boolean isSubscriptionConsensusFallbackPollingEnabled() {
+    return subscriptionConsensusFallbackPollingEnabled;
+  }
+
+  public void setSubscriptionConsensusFallbackPollingEnabled(
+      final boolean subscriptionConsensusFallbackPollingEnabled) {
+    this.subscriptionConsensusFallbackPollingEnabled = 
subscriptionConsensusFallbackPollingEnabled;
+  }
+
   public int getSubscriptionConsensusPrefetchingQueueCapacity() {
     return subscriptionConsensusPrefetchingQueueCapacity;
   }
diff --git 
a/iotdb-core/node-commons/src/main/java/org/apache/iotdb/commons/conf/CommonDescriptor.java
 
b/iotdb-core/node-commons/src/main/java/org/apache/iotdb/commons/conf/CommonDescriptor.java
index 5b54eb74b4e..8c05cff0c57 100644
--- 
a/iotdb-core/node-commons/src/main/java/org/apache/iotdb/commons/conf/CommonDescriptor.java
+++ 
b/iotdb-core/node-commons/src/main/java/org/apache/iotdb/commons/conf/CommonDescriptor.java
@@ -541,6 +541,11 @@ public class CommonDescriptor {
             properties.getProperty(
                 "subscription_consensus_lag_based_priority",
                 
String.valueOf(config.isSubscriptionConsensusLagBasedPriority()))));
+    config.setSubscriptionConsensusFallbackPollingEnabled(
+        Boolean.parseBoolean(
+            properties.getProperty(
+                "subscription_consensus_fallback_polling_enabled",
+                
String.valueOf(config.isSubscriptionConsensusFallbackPollingEnabled()))));
     config.setSubscriptionConsensusPrefetchingQueueCapacity(
         Integer.parseInt(
             properties.getProperty(
diff --git 
a/iotdb-core/node-commons/src/main/java/org/apache/iotdb/commons/subscription/config/SubscriptionConfig.java
 
b/iotdb-core/node-commons/src/main/java/org/apache/iotdb/commons/subscription/config/SubscriptionConfig.java
index a611bb9b22b..64e48b7d18e 100644
--- 
a/iotdb-core/node-commons/src/main/java/org/apache/iotdb/commons/subscription/config/SubscriptionConfig.java
+++ 
b/iotdb-core/node-commons/src/main/java/org/apache/iotdb/commons/subscription/config/SubscriptionConfig.java
@@ -179,6 +179,10 @@ public class SubscriptionConfig {
     return COMMON_CONFIG.isSubscriptionConsensusLagBasedPriority();
   }
 
+  public boolean isSubscriptionConsensusFallbackPollingEnabled() {
+    return COMMON_CONFIG.isSubscriptionConsensusFallbackPollingEnabled();
+  }
+
   public int getSubscriptionConsensusPrefetchingQueueCapacity() {
     return COMMON_CONFIG.getSubscriptionConsensusPrefetchingQueueCapacity();
   }
diff --git 
a/iotdb-core/node-commons/src/test/java/org/apache/iotdb/commons/conf/CommonDescriptorSubscriptionFallbackPollingTest.java
 
b/iotdb-core/node-commons/src/test/java/org/apache/iotdb/commons/conf/CommonDescriptorSubscriptionFallbackPollingTest.java
new file mode 100644
index 00000000000..f9e08f9c021
--- /dev/null
+++ 
b/iotdb-core/node-commons/src/test/java/org/apache/iotdb/commons/conf/CommonDescriptorSubscriptionFallbackPollingTest.java
@@ -0,0 +1,60 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.iotdb.commons.conf;
+
+import org.junit.Test;
+
+import java.lang.reflect.Constructor;
+
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertTrue;
+
+public class CommonDescriptorSubscriptionFallbackPollingTest {
+
+  @Test
+  public void testFallbackPollingEnabledByDefault() throws Exception {
+    final CommonDescriptor descriptor = newDescriptor();
+    descriptor.loadCommonProps(new TrimProperties());
+
+    
assertTrue(descriptor.getConfig().isSubscriptionConsensusFallbackPollingEnabled());
+  }
+
+  @Test
+  public void testLoadFallbackPollingSwitch() throws Exception {
+    final CommonDescriptor descriptor = newDescriptor();
+    final TrimProperties properties = new TrimProperties();
+    properties.setProperty("subscription_consensus_fallback_polling_enabled", 
"false");
+    descriptor.loadCommonProps(properties);
+
+    
assertFalse(descriptor.getConfig().isSubscriptionConsensusFallbackPollingEnabled());
+
+    properties.setProperty("subscription_consensus_fallback_polling_enabled", 
"true");
+    descriptor.loadCommonProps(properties);
+
+    
assertTrue(descriptor.getConfig().isSubscriptionConsensusFallbackPollingEnabled());
+  }
+
+  private static CommonDescriptor newDescriptor() throws Exception {
+    final Constructor<CommonDescriptor> constructor =
+        CommonDescriptor.class.getDeclaredConstructor();
+    constructor.setAccessible(true);
+    return constructor.newInstance();
+  }
+}

Reply via email to