-
Notifications
You must be signed in to change notification settings - Fork 8.9k
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
HDFS-17546. Implementing HostsFileReader timeout #6873
Merged
Merged
Changes from 7 commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
f01dea0
Implementing ReadTimeouts for HostFileReader on config
8ed85ca
javadoc indentation fix
e28fe7e
Fixing Linting
3709034
more lint fixing!
dc61e2d
fixing NPE in TestCombinedHostsFileReader
9157025
Trigger Build
555c098
updating test case to use Test Exception decorator
9a683b0
cleaning up unused imports for Unit tests
5571616
Trigger Build
c3cb689
Trigger Build
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 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 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 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 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 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 |
---|---|---|
|
@@ -19,14 +19,23 @@ | |
|
||
import java.io.File; | ||
import java.io.FileWriter; | ||
import java.io.IOException; | ||
import java.util.concurrent.Callable; | ||
|
||
import org.apache.hadoop.hdfs.protocol.DatanodeAdminProperties; | ||
import org.apache.hadoop.test.GenericTestUtils; | ||
import org.junit.Before; | ||
import org.junit.Rule; | ||
import org.junit.After; | ||
import org.junit.Test; | ||
import org.mockito.invocation.InvocationOnMock; | ||
import org.mockito.stubbing.Answer; | ||
import org.junit.rules.ExpectedException; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Unnecessary import. |
||
import org.mockito.Mock; | ||
import org.mockito.Mockito; | ||
|
||
import static org.junit.Assert.assertEquals; | ||
import static org.mockito.Mockito.when; | ||
|
||
/** | ||
* Test for JSON based HostsFileReader. | ||
|
@@ -44,8 +53,15 @@ public class TestCombinedHostsFileReader { | |
private final File legacyFile = | ||
new File(TESTCACHEDATADIR, "legacy.dfs.hosts.json"); | ||
|
||
@Rule | ||
public final ExpectedException exception = ExpectedException.none(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This variable is not used anywhere. |
||
|
||
@Mock | ||
private Callable<DatanodeAdminProperties[]> callable; | ||
|
||
@Before | ||
public void setUp() throws Exception { | ||
callable = Mockito.mock(Callable.class); | ||
} | ||
|
||
@After | ||
|
@@ -87,4 +103,50 @@ public void testEmptyCombinedHostsFileReader() throws Exception { | |
CombinedHostsFileReader.readFile(newFile.getAbsolutePath()); | ||
assertEquals(0, all.length); | ||
} | ||
|
||
/* | ||
* When timeout is enabled, test for success when reading file within timeout | ||
* limits | ||
*/ | ||
@Test | ||
public void testReadFileWithTimeoutSuccess() throws Exception { | ||
|
||
DatanodeAdminProperties[] all = CombinedHostsFileReader.readFileWithTimeout( | ||
jsonFile.getAbsolutePath(), 1000); | ||
assertEquals(7, all.length); | ||
} | ||
|
||
/* | ||
* When timeout is enabled, test for IOException when reading file exceeds | ||
* timeout limits | ||
*/ | ||
@Test(expected = IOException.class) | ||
public void testReadFileWithTimeoutTimeoutException() throws Exception { | ||
when(callable.call()).thenAnswer(new Answer<Void>() { | ||
@Override | ||
public Void answer(InvocationOnMock invocation) throws Throwable { | ||
Thread.sleep(2000); | ||
return null; | ||
} | ||
}); | ||
|
||
CombinedHostsFileReader.readFileWithTimeout( | ||
jsonFile.getAbsolutePath(), 1); | ||
} | ||
|
||
/* | ||
* When timeout is enabled, test for IOException when execution is interrupted | ||
*/ | ||
@Test(expected = IOException.class) | ||
public void testReadFileWithTimeoutInterruptedException() throws Exception { | ||
when(callable.call()).thenAnswer(new Answer<Void>() { | ||
@Override | ||
public Void answer(InvocationOnMock invocation) throws Throwable { | ||
throw new InterruptedException(); | ||
} | ||
}); | ||
|
||
CombinedHostsFileReader.readFileWithTimeout( | ||
jsonFile.getAbsolutePath(), 1); | ||
} | ||
} |
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Unnecessary import.