-
Notifications
You must be signed in to change notification settings - Fork 3.7k
[fix][broker] Fail fast if the extensible load manager failed to start #23297
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
BewareMyPower
merged 6 commits into
apache:master
from
BewareMyPower:bewaremypower/extensible-lm-fail-fast
Sep 13, 2024
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
4862fee
Revert "[improve][broker] Add retry for start service unit state chan…
BewareMyPower 2a8ecc0
Fail fast when starting the extensible load manager
BewareMyPower 9a97599
Add LoadManagerFailFastTest
BewareMyPower 8cb9f21
Assert the broker is unregistered
BewareMyPower 19e47af
Remove outdated code
BewareMyPower db8cf29
Fix checkstyle
codelipenghui File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
120 changes: 120 additions & 0 deletions
120
...rc/test/java/org/apache/pulsar/broker/loadbalance/extensions/LoadManagerFailFastTest.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,120 @@ | ||
| /* | ||
| * 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.pulsar.broker.loadbalance.extensions; | ||
|
|
||
| import java.util.Optional; | ||
| import lombok.Cleanup; | ||
| import org.apache.pulsar.broker.PulsarServerException; | ||
| import org.apache.pulsar.broker.PulsarService; | ||
| import org.apache.pulsar.broker.ServiceConfiguration; | ||
| import org.apache.pulsar.broker.loadbalance.LoadManager; | ||
| import org.apache.pulsar.broker.loadbalance.extensions.channel.ServiceUnitStateChannel; | ||
| import org.apache.pulsar.broker.loadbalance.extensions.channel.ServiceUnitStateChannelImpl; | ||
| import org.apache.pulsar.common.util.PortManager; | ||
| import org.apache.pulsar.zookeeper.LocalBookkeeperEnsemble; | ||
| import org.awaitility.Awaitility; | ||
| import org.mockito.Mockito; | ||
| import org.testng.Assert; | ||
| import org.testng.annotations.AfterClass; | ||
| import org.testng.annotations.BeforeClass; | ||
| import org.testng.annotations.Test; | ||
|
|
||
| public class LoadManagerFailFastTest { | ||
|
|
||
| private static final String cluster = "test"; | ||
| private final int zkPort = PortManager.nextLockedFreePort(); | ||
| private final LocalBookkeeperEnsemble bk = new LocalBookkeeperEnsemble(2, zkPort, PortManager::nextLockedFreePort); | ||
| private final ServiceConfiguration config = new ServiceConfiguration(); | ||
|
|
||
| @BeforeClass | ||
| protected void setup() throws Exception { | ||
| bk.start(); | ||
| config.setClusterName(cluster); | ||
| config.setAdvertisedAddress("localhost"); | ||
| config.setBrokerServicePort(Optional.of(0)); | ||
| config.setWebServicePort(Optional.of(0)); | ||
| config.setMetadataStoreUrl("zk:localhost:" + zkPort); | ||
| } | ||
|
|
||
| @AfterClass | ||
| protected void cleanup() throws Exception { | ||
| bk.stop(); | ||
| } | ||
|
|
||
| @Test(timeOut = 30000) | ||
| public void testBrokerRegistryFailure() throws Exception { | ||
| config.setLoadManagerClassName(BrokerRegistryLoadManager.class.getName()); | ||
| @Cleanup final var pulsar = new PulsarService(config); | ||
| try { | ||
| pulsar.start(); | ||
| Assert.fail(); | ||
| } catch (PulsarServerException e) { | ||
| Assert.assertNull(e.getCause()); | ||
| Assert.assertEquals(e.getMessage(), "Cannot start BrokerRegistry"); | ||
| } | ||
| Assert.assertTrue(pulsar.getLocalMetadataStore().getChildren(LoadManager.LOADBALANCE_BROKERS_ROOT).get() | ||
| .isEmpty()); | ||
| } | ||
|
|
||
| @Test(timeOut = 30000) | ||
| public void testServiceUnitStateChannelFailure() throws Exception { | ||
| config.setLoadManagerClassName(ChannelLoadManager.class.getName()); | ||
| @Cleanup final var pulsar = new PulsarService(config); | ||
| try { | ||
| pulsar.start(); | ||
| Assert.fail(); | ||
| } catch (PulsarServerException e) { | ||
| Assert.assertNull(e.getCause()); | ||
| Assert.assertEquals(e.getMessage(), "Cannot start ServiceUnitStateChannel"); | ||
| } | ||
| Awaitility.await().untilAsserted(() -> Assert.assertTrue(pulsar.getLocalMetadataStore() | ||
| .getChildren(LoadManager.LOADBALANCE_BROKERS_ROOT).get().isEmpty())); | ||
| } | ||
|
|
||
| private static class BrokerRegistryLoadManager extends ExtensibleLoadManagerImpl { | ||
|
|
||
| @Override | ||
| protected BrokerRegistry createBrokerRegistry(PulsarService pulsar) { | ||
| final var mockBrokerRegistry = Mockito.mock(BrokerRegistryImpl.class); | ||
| try { | ||
| Mockito.doThrow(new PulsarServerException("Cannot start BrokerRegistry")).when(mockBrokerRegistry) | ||
| .start(); | ||
| } catch (PulsarServerException e) { | ||
| throw new RuntimeException(e); | ||
| } | ||
| return mockBrokerRegistry; | ||
| } | ||
| } | ||
|
|
||
| private static class ChannelLoadManager extends ExtensibleLoadManagerImpl { | ||
|
|
||
| @Override | ||
| protected ServiceUnitStateChannel createServiceUnitStateChannel(PulsarService pulsar) { | ||
| final var channel = Mockito.mock(ServiceUnitStateChannelImpl.class); | ||
| try { | ||
| Mockito.doThrow(new PulsarServerException("Cannot start ServiceUnitStateChannel")).when(channel) | ||
| .start(); | ||
| } catch (PulsarServerException e) { | ||
| throw new RuntimeException(e); | ||
| } | ||
| Mockito.doAnswer(__ -> null).when(channel).listen(Mockito.any()); | ||
| return channel; | ||
| } | ||
| } | ||
| } |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.