Skip to content
Merged
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
5 changes: 5 additions & 0 deletions hadoop-hdds/common/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,11 @@ https://maven.apache.org/xsd/maven-4.0.0.xsd">
<artifactId>junit-jupiter-api</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-params</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-engine</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,75 +19,73 @@

import org.apache.hadoop.ozone.ClientVersion;
import org.apache.hadoop.ozone.OzoneManagerVersion;
import org.assertj.core.util.Arrays;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.Parameterized;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.Arguments;
import org.junit.jupiter.params.provider.MethodSource;

import static org.junit.Assert.assertEquals;
import java.util.stream.Stream;

import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.params.provider.Arguments.arguments;

/**
* Test to ensure Component version instances conform with invariants relied
* upon in other parts of the codebase.
*/
@RunWith(Parameterized.class)
public class TestComponentVersionInvariants {

@Parameterized.Parameters
public static Object[][] values() {
Object[][] values = new Object[3][];
values[0] =
Arrays.array(
public static Stream<Arguments> values() {
return Stream.of(
arguments(
DatanodeVersion.values(),
DatanodeVersion.DEFAULT_VERSION,
DatanodeVersion.FUTURE_VERSION);
values[1] =
Arrays.array(
DatanodeVersion.FUTURE_VERSION),
arguments(
ClientVersion.values(),
ClientVersion.DEFAULT_VERSION,
ClientVersion.FUTURE_VERSION);
values[2] =
Arrays.array(
ClientVersion.FUTURE_VERSION),
arguments(
OzoneManagerVersion.values(),
OzoneManagerVersion.DEFAULT_VERSION,
OzoneManagerVersion.FUTURE_VERSION);
return values;
}

private final ComponentVersion[] values;
private final ComponentVersion defaultValue;
private final ComponentVersion futureValue;

public TestComponentVersionInvariants(ComponentVersion[] values,
ComponentVersion defaultValue, ComponentVersion futureValue) {
this.values = new ComponentVersion[values.length];
System.arraycopy(values, 0, this.values, 0, values.length);
this.defaultValue = defaultValue;
this.futureValue = futureValue;
OzoneManagerVersion.FUTURE_VERSION)
);
}

// FUTURE_VERSION is the latest
@Test
public void testFutureVersionHasTheHighestOrdinal() {
@ParameterizedTest
@MethodSource("values")
public void testFutureVersionHasTheHighestOrdinal(
ComponentVersion[] values, ComponentVersion defaultValue,
ComponentVersion futureValue) {

assertEquals(values[values.length - 1], futureValue);
}

// FUTURE_VERSION's internal version id is -1
@Test
public void testFuturVersionHasMinusOneAsProtoRepresentation() {
@ParameterizedTest
@MethodSource("values")
public void testFuturVersionHasMinusOneAsProtoRepresentation(
ComponentVersion[] values, ComponentVersion defaultValue,
ComponentVersion futureValue) {
assertEquals(-1, futureValue.toProtoValue());

}

// DEFAULT_VERSION's internal version id is 0
@Test
public void testDefaultVersionHasZeroAsProtoRepresentation() {
@ParameterizedTest
@MethodSource("values")
public void testDefaultVersionHasZeroAsProtoRepresentation(
ComponentVersion[] values, ComponentVersion defaultValue,
ComponentVersion futureValue) {
assertEquals(0, defaultValue.toProtoValue());
}

// versions are increasing monotonically by one
@Test
public void testAssignedProtoRepresentations() {
@ParameterizedTest
@MethodSource("values")
public void testAssignedProtoRepresentations(
ComponentVersion[] values, ComponentVersion defaultValue,
ComponentVersion futureValue) {
int startValue = defaultValue.toProtoValue();
// we skip the future version at the last position
for (int i = 0; i < values.length - 1; i++) {
Expand Down
Loading