HDDS-15913. Extract common Kerberos/MiniKDC setup from serveral tests#10873
Open
shuan1026 wants to merge 1 commit into
Open
HDDS-15913. Extract common Kerberos/MiniKDC setup from serveral tests#10873shuan1026 wants to merge 1 commit into
shuan1026 wants to merge 1 commit into
Conversation
Author
|
PTAL @chungen0126 Thank you! |
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
What changes were proposed in this pull request?
Currently,
TestSecretKeySnapshot,TestSecretKeysApi,TestDelegationToken, andTestSecureOzoneClusterare independent integration test classes testing SecretKey functionalities in a secure cluster environment. However, they share a significant amount of duplicated boilerplate for setting up the secure environment.This PR extracts the duplicated Kerberos and MiniKDC initialization logic into a shared abstract base class,
AbstractKerberosTest(org.apache.hadoop.ozone), and migrates all four test classes to extend it. To ensure behavior remains identical to before the migration, the base owns the MiniKdc lifecycle (startMiniKdc/stopMiniKdc),setSecureConfig(), andcreateCredentialsInKDC(), exposing four protected hooks so subclasses can describe how their setup differs instead of duplicating the whole thing:useSharedServicePrincipal()— SCM/OM share onescm/...principal+keytab (TestSecretKeysApi,TestSecretKeySnapshot) vs. separatescm/.../om/...principals (TestDelegationToken,TestSecureOzoneCluster)createTestUserPrincipal()— whether atest@REALMprincipal is createdenableSecurityAuthorizationByDefault()— whetherhadoop.security.authorizationdefaults totruekerberosAuthenticationValue()— preserves a pre-existing inconsistency where two classes sethadoop.security.authenticationto the literal lowercase"kerberos"instead of the enum's"KERBEROS"The trickiest part was
TestSecureOzoneCluster: it sets up the KDC once per class (@BeforeAll/@AfterAll, static fields), while the other three do it fresh per test method. JUnit 5's@TempDiron an instance field is scoped per-test-method regardless of@TestInstancelifecycle, so the base class'sworkDirwas changed from a JUnit-managed@TempDirfield to a manually created and cleaned directory usingFiles.createTempDirectoryandFileUtils.deleteQuietly, both already-established patterns elsewhere in this test module. This letsTestSecureOzoneClusteruse@TestInstance(Lifecycle.PER_CLASS)with instance-level@BeforeAll/@AfterAllwhile the other three keep their existing per-test behavior unchanged. Under JUnit Jupiter's defaultPER_METHODlifecycle, each test method runs on a fresh instance of the test class, soworkDirisnullagain each time.What is the link to the Apache JIRA
https://issues.apache.org/jira/browse/HDDS-15913
How was this patch tested?
mvn -pl :ozone-integration-test test-compile; compile succeeded.mvn -pl :ozone-integration-test test -Dtest=TestSecretKeysApi,TestSecretKeySnapshot,TestDelegationToken,TestSecureOzoneCluster; all 4 classes passed../hadoop-ozone/dev-support/checks/checkstyle.sh; no violations.