|
75 | 75 | import org.apache.commons.lang3.tuple.Pair;
|
76 | 76 | import org.apache.pulsar.broker.PulsarService;
|
77 | 77 | import org.apache.pulsar.broker.ServiceConfiguration;
|
78 |
| -import org.apache.pulsar.broker.auth.MockedPulsarServiceBaseTest; |
79 | 78 | import org.apache.pulsar.broker.loadbalance.BrokerFilterException;
|
80 | 79 | import org.apache.pulsar.broker.loadbalance.LeaderBroker;
|
81 | 80 | import org.apache.pulsar.broker.loadbalance.LeaderElectionService;
|
|
101 | 100 | import org.apache.pulsar.broker.namespace.NamespaceEphemeralData;
|
102 | 101 | import org.apache.pulsar.broker.namespace.NamespaceService;
|
103 | 102 | import org.apache.pulsar.broker.service.BrokerServiceException;
|
104 |
| -import org.apache.pulsar.broker.testcontext.PulsarTestContext; |
105 | 103 | import org.apache.pulsar.client.admin.PulsarAdminException;
|
106 | 104 | import org.apache.pulsar.client.impl.TableViewImpl;
|
107 | 105 | import org.apache.pulsar.common.naming.NamespaceBundle;
|
108 | 106 | import org.apache.pulsar.common.naming.NamespaceName;
|
109 | 107 | import org.apache.pulsar.common.naming.ServiceUnitId;
|
110 |
| -import org.apache.pulsar.common.naming.SystemTopicNames; |
111 | 108 | import org.apache.pulsar.common.naming.TopicName;
|
112 | 109 | import org.apache.pulsar.common.naming.TopicVersion;
|
113 | 110 | import org.apache.pulsar.common.policies.data.BrokerAssignment;
|
114 | 111 | import org.apache.pulsar.common.policies.data.BundlesData;
|
115 |
| -import org.apache.pulsar.common.policies.data.ClusterData; |
116 | 112 | import org.apache.pulsar.common.policies.data.NamespaceOwnershipStatus;
|
117 |
| -import org.apache.pulsar.common.policies.data.TenantInfoImpl; |
118 |
| -import org.apache.pulsar.common.policies.data.TopicType; |
119 | 113 | import org.apache.pulsar.common.stats.Metrics;
|
120 | 114 | import org.apache.pulsar.common.util.FutureUtil;
|
121 | 115 | import org.apache.pulsar.policies.data.loadbalancer.ResourceUsage;
|
122 | 116 | import org.apache.pulsar.policies.data.loadbalancer.SystemResourceUsage;
|
123 | 117 | import org.awaitility.Awaitility;
|
124 | 118 | import org.mockito.MockedStatic;
|
125 | 119 | import org.testng.AssertJUnit;
|
126 |
| -import org.testng.annotations.AfterClass; |
127 |
| -import org.testng.annotations.BeforeClass; |
128 |
| -import org.testng.annotations.BeforeMethod; |
129 | 120 | import org.testng.annotations.Test;
|
130 | 121 |
|
131 | 122 | /**
|
132 | 123 | * Unit test for {@link ExtensibleLoadManagerImpl}.
|
133 | 124 | */
|
134 | 125 | @Slf4j
|
135 | 126 | @Test(groups = "broker")
|
136 |
| -public class ExtensibleLoadManagerImplTest extends MockedPulsarServiceBaseTest { |
| 127 | +@SuppressWarnings("unchecked") |
| 128 | +public class ExtensibleLoadManagerImplTest extends ExtensibleLoadManagerImplBaseTest { |
137 | 129 |
|
138 |
| - private PulsarService pulsar1; |
139 |
| - private PulsarService pulsar2; |
140 |
| - |
141 |
| - private PulsarTestContext additionalPulsarTestContext; |
142 |
| - |
143 |
| - private ExtensibleLoadManagerImpl primaryLoadManager; |
144 |
| - |
145 |
| - private ExtensibleLoadManagerImpl secondaryLoadManager; |
146 |
| - |
147 |
| - private ServiceUnitStateChannelImpl channel1; |
148 |
| - private ServiceUnitStateChannelImpl channel2; |
149 |
| - |
150 |
| - private final String defaultTestNamespace = "public/test"; |
151 |
| - |
152 |
| - private static void initConfig(ServiceConfiguration conf){ |
153 |
| - conf.setForceDeleteNamespaceAllowed(true); |
154 |
| - conf.setAllowAutoTopicCreationType(TopicType.NON_PARTITIONED); |
155 |
| - conf.setAllowAutoTopicCreation(true); |
156 |
| - conf.setLoadManagerClassName(ExtensibleLoadManagerImpl.class.getName()); |
157 |
| - conf.setLoadBalancerLoadSheddingStrategy(TransferShedder.class.getName()); |
158 |
| - conf.setLoadBalancerSheddingEnabled(false); |
159 |
| - conf.setLoadBalancerDebugModeEnabled(true); |
160 |
| - conf.setTopicLevelPoliciesEnabled(true); |
161 |
| - } |
162 |
| - |
163 |
| - @BeforeClass |
164 |
| - @Override |
165 |
| - public void setup() throws Exception { |
166 |
| - // Set the inflight state waiting time and ownership monitor delay time to 5 seconds to avoid |
167 |
| - // stuck when doing unload. |
168 |
| - initConfig(conf); |
169 |
| - super.internalSetup(conf); |
170 |
| - pulsar1 = pulsar; |
171 |
| - ServiceConfiguration defaultConf = getDefaultConf(); |
172 |
| - initConfig(defaultConf); |
173 |
| - additionalPulsarTestContext = createAdditionalPulsarTestContext(defaultConf); |
174 |
| - pulsar2 = additionalPulsarTestContext.getPulsarService(); |
175 |
| - |
176 |
| - setPrimaryLoadManager(); |
177 |
| - |
178 |
| - setSecondaryLoadManager(); |
179 |
| - |
180 |
| - admin.clusters().createCluster(this.conf.getClusterName(), |
181 |
| - ClusterData.builder().serviceUrl(pulsar.getWebServiceAddress()).build()); |
182 |
| - admin.tenants().createTenant("public", |
183 |
| - new TenantInfoImpl(Sets.newHashSet("appid1", "appid2"), |
184 |
| - Sets.newHashSet(this.conf.getClusterName()))); |
185 |
| - admin.namespaces().createNamespace("public/default"); |
186 |
| - admin.namespaces().setNamespaceReplicationClusters("public/default", |
187 |
| - Sets.newHashSet(this.conf.getClusterName())); |
188 |
| - |
189 |
| - admin.namespaces().createNamespace(defaultTestNamespace); |
190 |
| - admin.namespaces().setNamespaceReplicationClusters(defaultTestNamespace, |
191 |
| - Sets.newHashSet(this.conf.getClusterName())); |
192 |
| - } |
193 |
| - |
194 |
| - @Override |
195 |
| - @AfterClass(alwaysRun = true) |
196 |
| - protected void cleanup() throws Exception { |
197 |
| - this.additionalPulsarTestContext.close(); |
198 |
| - super.internalCleanup(); |
199 |
| - } |
200 |
| - |
201 |
| - @BeforeMethod(alwaysRun = true) |
202 |
| - protected void initializeState() throws PulsarAdminException { |
203 |
| - admin.namespaces().unload(defaultTestNamespace); |
204 |
| - reset(primaryLoadManager, secondaryLoadManager); |
| 130 | + public ExtensibleLoadManagerImplTest() { |
| 131 | + super("public/test"); |
205 | 132 | }
|
206 | 133 |
|
207 | 134 | @Test
|
@@ -459,7 +386,7 @@ public boolean test(NamespaceBundle namespaceBundle) {
|
459 | 386 | public void testSplitBundleWithSpecificPositionAdminAPI() throws Exception {
|
460 | 387 | String namespace = defaultTestNamespace;
|
461 | 388 | String topic = "persistent://" + namespace + "/test-split-with-specific-position";
|
462 |
| - admin.topics().createPartitionedTopic(topic, 10); |
| 389 | + admin.topics().createPartitionedTopic(topic, 1024); |
463 | 390 | BundlesData bundles = admin.namespaces().getBundles(namespace);
|
464 | 391 | int numBundles = bundles.getNumBundles();
|
465 | 392 |
|
@@ -1320,44 +1247,4 @@ public String name() {
|
1320 | 1247 | }
|
1321 | 1248 |
|
1322 | 1249 | }
|
1323 |
| - |
1324 |
| - private void setPrimaryLoadManager() throws IllegalAccessException { |
1325 |
| - ExtensibleLoadManagerWrapper wrapper = |
1326 |
| - (ExtensibleLoadManagerWrapper) pulsar1.getLoadManager().get(); |
1327 |
| - primaryLoadManager = spy((ExtensibleLoadManagerImpl) |
1328 |
| - FieldUtils.readField(wrapper, "loadManager", true)); |
1329 |
| - FieldUtils.writeField(wrapper, "loadManager", primaryLoadManager, true); |
1330 |
| - channel1 = (ServiceUnitStateChannelImpl) |
1331 |
| - FieldUtils.readField(primaryLoadManager, "serviceUnitStateChannel", true); |
1332 |
| - } |
1333 |
| - |
1334 |
| - private void setSecondaryLoadManager() throws IllegalAccessException { |
1335 |
| - ExtensibleLoadManagerWrapper wrapper = |
1336 |
| - (ExtensibleLoadManagerWrapper) pulsar2.getLoadManager().get(); |
1337 |
| - secondaryLoadManager = spy((ExtensibleLoadManagerImpl) |
1338 |
| - FieldUtils.readField(wrapper, "loadManager", true)); |
1339 |
| - FieldUtils.writeField(wrapper, "loadManager", secondaryLoadManager, true); |
1340 |
| - channel2 = (ServiceUnitStateChannelImpl) |
1341 |
| - FieldUtils.readField(secondaryLoadManager, "serviceUnitStateChannel", true); |
1342 |
| - } |
1343 |
| - |
1344 |
| - private CompletableFuture<NamespaceBundle> getBundleAsync(PulsarService pulsar, TopicName topic) { |
1345 |
| - return pulsar.getNamespaceService().getBundleAsync(topic); |
1346 |
| - } |
1347 |
| - |
1348 |
| - private Pair<TopicName, NamespaceBundle> getBundleIsNotOwnByChangeEventTopic(String topicNamePrefix) |
1349 |
| - throws Exception { |
1350 |
| - TopicName changeEventsTopicName = |
1351 |
| - TopicName.get(defaultTestNamespace + "/" + SystemTopicNames.NAMESPACE_EVENTS_LOCAL_NAME); |
1352 |
| - NamespaceBundle changeEventsBundle = getBundleAsync(pulsar1, changeEventsTopicName).get(); |
1353 |
| - int i = 0; |
1354 |
| - while (true) { |
1355 |
| - TopicName topicName = TopicName.get(defaultTestNamespace + "/" + topicNamePrefix + "-" + i); |
1356 |
| - NamespaceBundle bundle = getBundleAsync(pulsar1, topicName).get(); |
1357 |
| - if (!bundle.equals(changeEventsBundle)) { |
1358 |
| - return Pair.of(topicName, bundle); |
1359 |
| - } |
1360 |
| - i++; |
1361 |
| - } |
1362 |
| - } |
1363 | 1250 | }
|
0 commit comments