Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ public class ContainerScanError {
/**
* Represents the reason a container scan failed and a container should
* be marked unhealthy.
* Note: When adding a new FailureType, ensure a corresponding test is added to
* TestContainerCorruptions, or explicitly exclude in getExcludedFailureTypes().
*/
public enum FailureType {
MISSING_CONTAINER_DIR,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -185,4 +185,16 @@ public static File getBlock(Container<?> container, long blockID) {
assertTrue(blockFile.exists());
return blockFile;
}

/**
* Set of {@link ContainerScanError.FailureType} values that are excluded from testing.
* When adding a FailureType to this set, add a comment explaining why it's excluded.
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@errose28 The below FailureType constants currently don’t have corresponding test coverage. Do we have any specific reason or context for their exclusion so I can document it here?

*/
public static Set<ContainerScanError.FailureType> getExcludedFailureTypes() {
return EnumSet.of(
ContainerScanError.FailureType.WRITE_FAILURE,
ContainerScanError.FailureType.INACCESSIBLE_DB,
ContainerScanError.FailureType.INCONSISTENT_CHUNK_LENGTH
);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
/*
* 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.keyvalue;

import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.junit.jupiter.api.Assertions.assertTrue;

import java.util.EnumSet;
import java.util.Set;
import org.apache.hadoop.ozone.container.ozoneimpl.ContainerScanError;
import org.junit.jupiter.api.Test;

/**
* Validates test coverage for all {@link ContainerScanError.FailureType} values.
*/
public class TestFailureTypeCoverage {

@Test
public void testEveryFailureTypeIsTestedOrExcluded() {
Set<ContainerScanError.FailureType> testedFailureTypes = EnumSet.noneOf(ContainerScanError.FailureType.class);

for (TestContainerCorruptions types : TestContainerCorruptions.values()) {
ContainerScanError.FailureType failureType = types.getExpectedResult();
assertNotNull(failureType);
testedFailureTypes.add(failureType);
}

Set<ContainerScanError.FailureType> allFailureTypes = EnumSet.allOf(ContainerScanError.FailureType.class);
Set<ContainerScanError.FailureType> failureTypesMissingTests = EnumSet.copyOf(allFailureTypes);

//Remove types that are tested
failureTypesMissingTests.removeAll(testedFailureTypes);
//Remove explicitly excluded types
failureTypesMissingTests.removeAll(TestContainerCorruptions.getExcludedFailureTypes());

assertTrue(failureTypesMissingTests.isEmpty(),
"The following FailureType values do not have corresponding test corruptions in "
+ "TestContainerCorruptions: " + failureTypesMissingTests + ". Either add test cases for these "
+ "failure types or exclude them with an explanation (via getExcludedFailureTypes()).");
}
}