-
Notifications
You must be signed in to change notification settings - Fork 588
HDDS-4429. Create unit test for SimpleContainerDownloader. #1551
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 5 commits
Commits
Show all changes
16 commits
Select commit
Hold shift + click to select a range
9e15cf3
HDDS-4429. Create unit test for SimpleContainerDownloader
elek 1e96edd
Print out the right exception in LOG.error
elek 17e50ae
test both direct and future wrapped exceptions
elek c149ce4
test both direct and future wrapped exceptions
elek 125f8ee
Merge commit 'c149ce443e5c757ba451de7f837f5a829f12b220'; commit '17e5…
elek 9adbce2
trigger new CI check
adoroszlai 9eca410
Merge remote-tracking branch 'origin/master' into HDDS-4429
elek a7fc88b
Merge remote-tracking branch 'elek/HDDS-4429' into HDDS-4429
elek e8d07cc
Merge remote-tracking branch 'origin/master' into HDDS-4429
elek 62c34d7
fix retry test after HDDS-4453
elek c54424b
increased timeout
elek 38eee8a
trigger new CI check
adoroszlai e5ee7b6
trigger new CI check
adoroszlai 2b66437
trigger new CI check
adoroszlai a280682
fix unit test and error handling
elek 2cc31cf
Merge remote-tracking branch 'elek/HDDS-4429' into HDDS-4429
elek 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
150 changes: 150 additions & 0 deletions
150
...est/java/org/apache/hadoop/ozone/container/replication/TestSimpleContainerDownloader.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,150 @@ | ||
| /* | ||
| * 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.container.replication; | ||
|
|
||
| import java.io.IOException; | ||
| import java.nio.file.Path; | ||
| import java.nio.file.Paths; | ||
| import java.util.ArrayList; | ||
| import java.util.Arrays; | ||
| import java.util.List; | ||
| import java.util.concurrent.CompletableFuture; | ||
| import java.util.concurrent.TimeUnit; | ||
|
|
||
| import org.apache.hadoop.hdds.conf.ConfigurationSource; | ||
| import org.apache.hadoop.hdds.conf.OzoneConfiguration; | ||
| import org.apache.hadoop.hdds.protocol.DatanodeDetails; | ||
| import org.apache.hadoop.hdds.protocol.MockDatanodeDetails; | ||
|
|
||
| import org.junit.Assert; | ||
| import org.junit.Test; | ||
|
|
||
| /** | ||
| * Test SimpleContainerDownloader. | ||
| */ | ||
| public class TestSimpleContainerDownloader { | ||
|
|
||
| @Test | ||
| public void testGetContainerDataFromReplicasHappyPath() throws Exception { | ||
|
|
||
| //GIVEN | ||
| List<DatanodeDetails> datanodes = createDatanodes(); | ||
|
|
||
| SimpleContainerDownloader downloader = | ||
| createDownloaderWithPredefinedFailures(true); | ||
|
|
||
| //WHEN | ||
| final Path result = | ||
| downloader.getContainerDataFromReplicas(1L, datanodes) | ||
| .get(1L, TimeUnit.SECONDS); | ||
|
|
||
| //THEN | ||
| Assert.assertEquals(datanodes.get(0).getUuidString(), result.toString()); | ||
| } | ||
|
|
||
| @Test | ||
| public void testGetContainerDataFromReplicasDirectFailure() | ||
| throws Exception { | ||
|
|
||
| //GIVEN | ||
| List<DatanodeDetails> datanodes = createDatanodes(); | ||
|
|
||
| SimpleContainerDownloader downloader = | ||
| createDownloaderWithPredefinedFailures(true, datanodes.get(0)); | ||
|
|
||
| //WHEN | ||
| final Path result = | ||
| downloader.getContainerDataFromReplicas(1L, datanodes) | ||
| .get(1L, TimeUnit.SECONDS); | ||
|
|
||
| //THEN | ||
| //first datanode is failed, second worked | ||
| Assert.assertEquals(datanodes.get(1).getUuidString(), result.toString()); | ||
| } | ||
|
|
||
| @Test | ||
| public void testGetContainerDataFromReplicasAsyncFailure() throws Exception { | ||
|
|
||
| //GIVEN | ||
| List<DatanodeDetails> datanodes = createDatanodes(); | ||
|
|
||
| SimpleContainerDownloader downloader = | ||
| createDownloaderWithPredefinedFailures(false, datanodes.get(0)); | ||
|
|
||
| //WHEN | ||
| final Path result = | ||
| downloader.getContainerDataFromReplicas(1L, datanodes) | ||
| .get(1L, TimeUnit.SECONDS); | ||
|
|
||
| //THEN | ||
| //first datanode is failed, second worked | ||
| Assert.assertEquals(datanodes.get(1).getUuidString(), result.toString()); | ||
| } | ||
|
|
||
| /** | ||
| * Creates downloader which fails with datanodes in the arguments. | ||
| * | ||
| * @param directException if false the exception will be wrapped in the | ||
| * returning future. | ||
| */ | ||
| private SimpleContainerDownloader createDownloaderWithPredefinedFailures( | ||
| boolean directException, | ||
| DatanodeDetails... failedDatanodes | ||
| ) { | ||
|
|
||
| ConfigurationSource conf = new OzoneConfiguration(); | ||
|
|
||
| final List<DatanodeDetails> datanodes = | ||
| Arrays.asList(failedDatanodes); | ||
|
|
||
| return new SimpleContainerDownloader(conf, null) { | ||
|
|
||
| @Override | ||
| protected CompletableFuture<Path> downloadContainer( | ||
| long containerId, | ||
| DatanodeDetails datanode | ||
| ) throws IOException { | ||
|
|
||
| if (datanodes.contains(datanode)) { | ||
| if (directException) { | ||
| throw new IOException("Unavailable datanode"); | ||
| } else { | ||
| return CompletableFuture.supplyAsync(() -> { | ||
| throw new RuntimeException("Unavailable datanode"); | ||
| }); | ||
| } | ||
| } else { | ||
|
|
||
| //path includes the dn id to make it possible to assert. | ||
| return CompletableFuture.completedFuture( | ||
| Paths.get(datanode.getUuidString())); | ||
| } | ||
|
|
||
| } | ||
| }; | ||
| } | ||
|
|
||
| private List<DatanodeDetails> createDatanodes() { | ||
| List<DatanodeDetails> datanodes = new ArrayList<>(); | ||
| datanodes.add(MockDatanodeDetails.randomDatanodeDetails()); | ||
| datanodes.add(MockDatanodeDetails.randomDatanodeDetails()); | ||
| datanodes.add(MockDatanodeDetails.randomDatanodeDetails()); | ||
| return datanodes; | ||
| } | ||
| } | ||
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.
Actually, these checks are no longer valid after 5e8aaee since
SimpleContainerDownloadershuffles the datanodes.ozone/hadoop-hdds/container-service/src/main/java/org/apache/hadoop/ozone/container/replication/SimpleContainerDownloader.java
Lines 79 to 84 in 0aca5c7
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.
Looking into it. Seems I stepped in my own trap ;-)