-
Notifications
You must be signed in to change notification settings - Fork 14.6k
KAFKA-19702: Move MetadataVersionConfigValidator and related test code to metadata module #20526
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
Open
DL1231
wants to merge
5
commits into
apache:trunk
Choose a base branch
from
DL1231:KAFKA-19702
base: trunk
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
d179a2b
Move MetadataVersionConfigValidator and related test code to metadata…
DL1231 d25e4f4
remove LogConfigTest#testValidateWithMetadataVersionJbodSupport
DL1231 5d1cabb
fix ci
DL1231 f5c5c9b
address comment
DL1231 792e417
Merge remote-tracking branch 'origin/trunk' into KAFKA-19702
DL1231 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
103 changes: 0 additions & 103 deletions
103
core/src/test/java/kafka/server/MetadataVersionConfigValidatorTest.java
This file was deleted.
Oops, something went wrong.
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
140 changes: 140 additions & 0 deletions
140
metadata/src/test/java/org/apache/kafka/metadata/MetadataVersionConfigValidatorTest.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,140 @@ | ||
/* | ||
* 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.kafka.metadata; | ||
|
||
import org.apache.kafka.common.metadata.FeatureLevelRecord; | ||
import org.apache.kafka.image.MetadataDelta; | ||
import org.apache.kafka.image.MetadataImage; | ||
import org.apache.kafka.image.MetadataProvenance; | ||
import org.apache.kafka.image.loader.LogDeltaManifest; | ||
import org.apache.kafka.raft.LeaderAndEpoch; | ||
import org.apache.kafka.server.common.MetadataVersion; | ||
import org.apache.kafka.server.fault.FaultHandler; | ||
|
||
import org.junit.jupiter.api.Test; | ||
|
||
import java.util.function.Supplier; | ||
|
||
import static org.mockito.ArgumentMatchers.any; | ||
import static org.mockito.ArgumentMatchers.eq; | ||
import static org.mockito.Mockito.mock; | ||
import static org.mockito.Mockito.times; | ||
import static org.mockito.Mockito.verify; | ||
import static org.mockito.Mockito.verifyNoMoreInteractions; | ||
import static org.mockito.Mockito.when; | ||
|
||
@SuppressWarnings({"unchecked", "ThrowableNotThrown"}) | ||
public class MetadataVersionConfigValidatorTest { | ||
|
||
private static final LogDeltaManifest TEST_MANIFEST = LogDeltaManifest.newBuilder() | ||
.provenance(MetadataProvenance.EMPTY) | ||
.leaderAndEpoch(LeaderAndEpoch.UNKNOWN) | ||
.numBatches(1) | ||
.elapsedNs(90) | ||
.numBytes(88) | ||
.build(); | ||
public static final MetadataProvenance TEST_PROVENANCE = | ||
new MetadataProvenance(50, 3, 8000, true); | ||
|
||
void executeMetadataUpdate( | ||
MetadataVersion metadataVersion, | ||
Supplier<Boolean> multiLogDirSupplier, | ||
FaultHandler faultHandler | ||
) throws Exception { | ||
try (MetadataVersionConfigValidator validator = new MetadataVersionConfigValidator(0, multiLogDirSupplier, faultHandler)) { | ||
MetadataDelta delta = new MetadataDelta.Builder() | ||
.setImage(MetadataImage.EMPTY) | ||
.build(); | ||
if (metadataVersion != null) { | ||
delta.replay(new FeatureLevelRecord(). | ||
setName(MetadataVersion.FEATURE_NAME). | ||
setFeatureLevel(metadataVersion.featureLevel())); | ||
} | ||
MetadataImage image = delta.apply(TEST_PROVENANCE); | ||
|
||
validator.onMetadataUpdate(delta, image, TEST_MANIFEST); | ||
} | ||
} | ||
|
||
@Test | ||
void testValidatesConfigOnMetadataChange() throws Exception { | ||
MetadataVersion metadataVersion = MetadataVersion.IBP_3_7_IV2; | ||
FaultHandler faultHandler = mock(FaultHandler.class); | ||
Supplier<Boolean> multiLogDirSupplier = mock(Supplier.class); | ||
when(multiLogDirSupplier.get()).thenReturn(false); | ||
|
||
executeMetadataUpdate(metadataVersion, multiLogDirSupplier, faultHandler); | ||
|
||
verify(multiLogDirSupplier, times(1)).get(); | ||
verifyNoMoreInteractions(faultHandler); | ||
} | ||
|
||
@Test | ||
void testInvokesFaultHandlerOnException() throws Exception { | ||
MetadataVersion metadataVersion = MetadataVersion.IBP_3_7_IV1; | ||
Supplier<Boolean> multiLogDirSupplier = mock(Supplier.class); | ||
FaultHandler faultHandler = mock(FaultHandler.class); | ||
|
||
when(multiLogDirSupplier.get()).thenReturn(true); | ||
|
||
executeMetadataUpdate(metadataVersion, multiLogDirSupplier, faultHandler); | ||
|
||
verify(multiLogDirSupplier, times(1)).get(); | ||
verify(faultHandler, times(1)).handleFault( | ||
eq("Broker configuration does not support the cluster MetadataVersion"), | ||
any(IllegalArgumentException.class)); | ||
} | ||
|
||
@Test | ||
void testValidateWithMetadataVersionJbodSupport() throws Exception { | ||
FaultHandler faultHandler = mock(FaultHandler.class); | ||
validate(MetadataVersion.IBP_3_6_IV2, false, faultHandler); | ||
verifyNoMoreInteractions(faultHandler); | ||
|
||
faultHandler = mock(FaultHandler.class); | ||
validate(MetadataVersion.IBP_3_7_IV0, false, faultHandler); | ||
verifyNoMoreInteractions(faultHandler); | ||
|
||
faultHandler = mock(FaultHandler.class); | ||
validate(MetadataVersion.IBP_3_7_IV2, false, faultHandler); | ||
verifyNoMoreInteractions(faultHandler); | ||
|
||
faultHandler = mock(FaultHandler.class); | ||
validate(MetadataVersion.IBP_3_6_IV2, true, faultHandler); | ||
verify(faultHandler, times(1)).handleFault( | ||
eq("Broker configuration does not support the cluster MetadataVersion"), | ||
any(IllegalArgumentException.class)); | ||
|
||
faultHandler = mock(FaultHandler.class); | ||
validate(MetadataVersion.IBP_3_7_IV0, true, faultHandler); | ||
verify(faultHandler, times(1)).handleFault( | ||
eq("Broker configuration does not support the cluster MetadataVersion"), | ||
any(IllegalArgumentException.class)); | ||
|
||
faultHandler = mock(FaultHandler.class); | ||
validate(MetadataVersion.IBP_3_7_IV2, true, faultHandler); | ||
verifyNoMoreInteractions(faultHandler); | ||
} | ||
|
||
private void validate(MetadataVersion metadataVersion, boolean jbodConfig, FaultHandler faultHandler) | ||
throws Exception { | ||
Supplier<Boolean> multiLogDirSupplier = () -> jbodConfig; | ||
|
||
executeMetadataUpdate(metadataVersion, multiLogDirSupplier, faultHandler); | ||
} | ||
} |
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.