-
Notifications
You must be signed in to change notification settings - Fork 614
HDDS-10559. Add a warning or a check to run repair tool as System user #6574
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
Merged
Changes from 3 commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
327d054
HDDS-10559. Add a warning or a check to run repair tool as System user
fae7cef
Update command message, removed unnecessary tracing
67fb31f
fix checkstyle
8781efa
Use Scanner to scan terminal input, make sure the prompt goes to stderr
52cf3db
remove unused import
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
86 changes: 86 additions & 0 deletions
86
hadoop-ozone/tools/src/test/java/org/apache/hadoop/ozone/repair/TestOzoneRepair.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,86 @@ | ||
| /* | ||
| * 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.hadoop.ozone.repair; | ||
|
|
||
| import org.junit.jupiter.api.AfterEach; | ||
| import org.junit.jupiter.api.BeforeEach; | ||
| import org.junit.jupiter.api.Test; | ||
|
|
||
| import java.io.ByteArrayOutputStream; | ||
| import java.io.PrintStream; | ||
|
|
||
| import static java.nio.charset.StandardCharsets.UTF_8; | ||
| import static org.assertj.core.api.Assertions.assertThat; | ||
| import static org.junit.jupiter.api.Assertions.assertEquals; | ||
| import static org.mockito.ArgumentMatchers.anyString; | ||
| import static org.mockito.Mockito.doReturn; | ||
| import static org.mockito.Mockito.spy; | ||
|
|
||
| /** | ||
| * Tests the ozone repair command. | ||
| */ | ||
| public class TestOzoneRepair { | ||
|
|
||
| private final ByteArrayOutputStream out = new ByteArrayOutputStream(); | ||
| private final ByteArrayOutputStream err = new ByteArrayOutputStream(); | ||
| private static final PrintStream OLD_OUT = System.out; | ||
| private static final PrintStream OLD_ERR = System.err; | ||
| private static final String DEFAULT_ENCODING = UTF_8.name(); | ||
|
|
||
| private static final String OZONE_USER = "ozone"; | ||
| private static final String OLD_USER = System.getProperty("user.name"); | ||
|
|
||
| @BeforeEach | ||
| public void setup() throws Exception { | ||
| System.setOut(new PrintStream(out, false, DEFAULT_ENCODING)); | ||
| System.setErr(new PrintStream(err, false, DEFAULT_ENCODING)); | ||
| System.setProperty("user.name", OZONE_USER); | ||
| } | ||
|
|
||
| @AfterEach | ||
| public void reset() { | ||
| // reset stream after each unit test | ||
| out.reset(); | ||
| err.reset(); | ||
|
|
||
| // restore system streams | ||
| System.setOut(OLD_OUT); | ||
| System.setErr(OLD_ERR); | ||
| System.setProperty("user.name", OLD_USER); | ||
| } | ||
|
|
||
| @Test | ||
| void testOzoneRepairWhenUserIsRemindedSystemUserAndDeclinesToProceed() throws Exception { | ||
| OzoneRepair ozoneRepair = spy(new OzoneRepair()); | ||
| doReturn("N").when(ozoneRepair).getConsoleReadLineWithFormat(anyString()); | ||
|
|
||
| int res = ozoneRepair.execute(new String[]{}); | ||
| assertEquals(1, res); | ||
| assertThat(out.toString(DEFAULT_ENCODING)).contains("Aborting command."); | ||
| } | ||
|
|
||
| @Test | ||
| void testOzoneRepairWhenUserIsRemindedSystemUserAndAgreesToProceed() throws Exception { | ||
| OzoneRepair ozoneRepair = spy(new OzoneRepair()); | ||
| doReturn("y").when(ozoneRepair).getConsoleReadLineWithFormat(anyString()); | ||
|
|
||
| ozoneRepair.execute(new String[]{}); | ||
| assertThat(out.toString(DEFAULT_ENCODING)).contains("Run as user: " + OZONE_USER); | ||
| } | ||
|
|
||
| } |
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.