-
Notifications
You must be signed in to change notification settings - Fork 9.2k
HADOOP-18217. ExitUtil synchronized blocks reduced to avoid exit bloc… #4255
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 2 commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
55b71c8
HADOOP-18217. ExitUtil synchronized blocks reduced to avoid exit bloc…
f279d64
HADOOP-18217. use atomics, added tests, updated javadoc, fixed code s…
7d6468b
HADOOP-18217. added addSuppressed checks, fixed code style, tests use…
9e9dc76
HADOOP-18217. added addSuppressed helper + JUnit Before+After
518fefc
HADOOP-18217. fixed javadoc
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
122 changes: 122 additions & 0 deletions
122
hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/util/TestExitUtil.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,122 @@ | ||
| /** | ||
| * 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.util; | ||
|
|
||
| import static org.junit.Assert.*; | ||
|
|
||
| import org.apache.hadoop.util.ExitUtil.ExitException; | ||
| import org.apache.hadoop.util.ExitUtil.HaltException; | ||
|
|
||
| import org.junit.Test; | ||
|
|
||
| public class TestExitUtil { | ||
HerCath marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| @Test | ||
| public void testGetSetExitExceptions() { | ||
| // prepare states and exceptions | ||
| ExitUtil.disableSystemExit(); | ||
| ExitUtil.resetFirstExitException(); | ||
| ExitException ee1 = new ExitException(1, "TestExitUtil forged 1st ExitException"); | ||
| ExitException ee2 = new ExitException(2, "TestExitUtil forged 2nd ExitException"); | ||
| try { | ||
| // check proper initial settings | ||
| assertFalse(ExitUtil.terminateCalled()); | ||
steveloughran marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| assertNull(ExitUtil.getFirstExitException()); | ||
|
|
||
| // simulate/check 1st call | ||
| try { | ||
| ExitUtil.terminate(ee1); | ||
steveloughran marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| fail("ExitUtil.terminate should have rethrown its ExitException argument but it returned"); | ||
| } catch (ExitException ee) { | ||
| assertEquals("ExitUtil.terminate should have rethrown its ExitException argument but it " | ||
| +"had thrown something else", ee1, ee); | ||
| } | ||
| assertTrue(ExitUtil.terminateCalled()); | ||
| assertEquals("ExitUtil.terminate should store its 1st call's ExitException", | ||
steveloughran marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| ee1, ExitUtil.getFirstExitException()); | ||
|
|
||
| // simulate/check 2nd call not overwritting 1st one | ||
| try { | ||
| ExitUtil.terminate(ee2); | ||
steveloughran marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| fail("ExitUtil.terminate should have rethrown its ExitException argument but it returned"); | ||
| } catch (ExitException ee) { | ||
| assertEquals("ExitUtil.terminate should have rethrown its HaltException argument but it " | ||
| +"had thrown something else", ee2, ee); | ||
| } | ||
| assertTrue(ExitUtil.terminateCalled()); | ||
| // 2nd call rethrown the 2nd ExitException yet only the 1st only should have been stored | ||
| assertEquals("ExitUtil.terminate when called twice should only remember 1st call's " | ||
| +"ExitException", ee1, ExitUtil.getFirstExitException()); | ||
|
|
||
| // simulate cleanup, also tries to make sure state is ok for all junit still has to do | ||
| ExitUtil.resetFirstExitException(); | ||
| assertFalse(ExitUtil.terminateCalled()); | ||
| assertNull(ExitUtil.getFirstExitException()); | ||
| } finally { | ||
| // cleanup | ||
| ExitUtil.resetFirstExitException(); | ||
HerCath marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| } | ||
| } | ||
|
|
||
| @Test | ||
| public void testGetSetHaltExceptions() { | ||
steveloughran marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| // prepare states and exceptions | ||
| ExitUtil.disableSystemHalt(); | ||
| ExitUtil.resetFirstHaltException(); | ||
| HaltException he1 = new HaltException(1, "TestExitUtil forged 1st HaltException"); | ||
| HaltException he2 = new HaltException(2, "TestExitUtil forged 2nd HaltException"); | ||
| try { | ||
| // check proper initial settings | ||
| assertFalse(ExitUtil.haltCalled()); | ||
| assertNull(ExitUtil.getFirstHaltException()); | ||
|
|
||
| // simulate/check 1st call | ||
| try { | ||
| ExitUtil.halt(he1); | ||
| fail("ExitUtil.halt should have rethrown its HaltException argument but it returned"); | ||
| } catch (HaltException he) { | ||
| assertEquals("ExitUtil.halt should have rethrown its HaltException argument but it had " | ||
| +"thrown something else", he1, he); | ||
| } | ||
| assertTrue("ExitUtil.halt/haltCalled should remember halt has been called", | ||
| ExitUtil.haltCalled()); | ||
| assertEquals("ExitUtil.halt should store its 1st call's HaltException", | ||
| he1, ExitUtil.getFirstHaltException()); | ||
|
|
||
| // simulate/check 2nd call not overwritting 1st one | ||
| try { | ||
| ExitUtil.halt(he2); | ||
| fail("ExitUtil.halt should have rethrown its HaltException argument but it returned"); | ||
| } catch (HaltException he) { | ||
| assertEquals("ExitUtil.halt should have rethrown its HaltException argument but it had " | ||
| +"thrown something else", he2, he); | ||
| } | ||
| assertTrue(ExitUtil.haltCalled()); | ||
| assertEquals("ExitUtil.halt when called twice should only remember 1st call's HaltException", | ||
| he1, ExitUtil.getFirstHaltException()); | ||
|
|
||
| // simulate cleanup, also tries to make sure state is ok for all junit still has to do | ||
| ExitUtil.resetFirstHaltException(); | ||
| assertFalse(ExitUtil.haltCalled()); | ||
| assertNull(ExitUtil.getFirstHaltException()); | ||
| } finally { | ||
| // cleanup, useless if last test succeed, useful if not | ||
| ExitUtil.resetFirstHaltException(); | ||
| } | ||
| } | ||
| } | ||
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.