Skip to content

Commit

Permalink
HDDS-10983. Add client version test
Browse files Browse the repository at this point in the history
Change-Id: I9a8905dad8f4db731b110644fa03e9e80e1df859
  • Loading branch information
swamirishi committed Jun 8, 2024
1 parent 8edc907 commit 1476d59
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
import org.apache.hadoop.hdds.scm.pipeline.MockPipeline;
import org.apache.hadoop.hdds.scm.pipeline.Pipeline;
import org.apache.hadoop.hdds.utils.UniqueId;
import org.apache.hadoop.ozone.ClientVersion;
import org.apache.hadoop.ozone.common.Checksum;
import org.apache.hadoop.ozone.common.ChunkBuffer;
import org.apache.hadoop.ozone.common.OzoneChecksumException;
Expand Down Expand Up @@ -543,7 +544,7 @@ public static byte[] generateData(int length, boolean random) {

public static ContainerCommandRequestProto getDummyCommandRequestProto(
ContainerProtos.Type cmdType) {
return getDummyCommandRequestProto(cmdType, 0);
return getDummyCommandRequestProto(ClientVersion.CURRENT, cmdType, 0);
}

/**
Expand All @@ -555,8 +556,8 @@ public static ContainerCommandRequestProto getDummyCommandRequestProto(
* @return
*/
public static ContainerCommandRequestProto getDummyCommandRequestProto(
ContainerProtos.Type cmdType, int replicaIndex) {
final Builder builder = getContainerCommandRequestProtoBuilder()
ClientVersion clientVersion, ContainerProtos.Type cmdType, int replicaIndex) {
final Builder builder = getContainerCommandRequestProtoBuilder(clientVersion.toProtoValue())
.setCmdType(cmdType)
.setContainerID(DUMMY_CONTAINER_ID)
.setDatanodeUuid(DATANODE_UUID);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import org.apache.hadoop.hdds.protocol.DatanodeDetails;
import org.apache.hadoop.hdds.protocol.datanode.proto.ContainerProtos;
import org.apache.hadoop.hdds.scm.pipeline.MockPipeline;
import org.apache.hadoop.ozone.ClientVersion;
import org.apache.hadoop.ozone.container.common.ContainerTestUtils;
import org.apache.hadoop.ozone.container.common.helpers.ContainerMetrics;
import org.apache.hadoop.ozone.container.common.impl.ContainerSet;
Expand All @@ -35,12 +36,16 @@
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.ValueSource;
import org.junit.jupiter.params.provider.Arguments;
import org.junit.jupiter.params.provider.MethodSource;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.io.IOException;
import java.util.Arrays;
import java.util.UUID;
import java.util.stream.IntStream;
import java.util.stream.Stream;

import static org.apache.hadoop.hdds.protocol.datanode.proto.ContainerProtos.Result.CONTAINER_INTERNAL_ERROR;
import static org.apache.hadoop.hdds.protocol.datanode.proto.ContainerProtos.Result.SUCCESS;
Expand Down Expand Up @@ -97,17 +102,25 @@ public void testGetBlock() {
assertEquals(UNKNOWN_BCSID, response.getResult());
}

private static Stream<Arguments> getAllClientVersions() {
return Arrays.stream(ClientVersion.values()).flatMap(client -> IntStream.range(0, 6)
.mapToObj(rid -> Arguments.of(client, rid)));
}


@ParameterizedTest
@ValueSource(ints = {0, 1, 2, 3, 4, 5})
public void testGetBlockWithReplicaIndexMismatch(int replicaIndex) {
@MethodSource("getAllClientVersions")
public void testGetBlockWithReplicaIndexMismatch(ClientVersion clientVersion, int replicaIndex) {
KeyValueContainer container = getMockContainerWithReplicaIndex(replicaIndex);
KeyValueHandler handler = getDummyHandler();
for (int rid = 0; rid <= 5; rid++) {
ContainerProtos.ContainerCommandResponseProto response =
handler.handleGetBlock(
getDummyCommandRequestProto(ContainerProtos.Type.GetBlock, rid),
getDummyCommandRequestProto(clientVersion, ContainerProtos.Type.GetBlock, rid),
container);
assertEquals(rid != replicaIndex ? ContainerProtos.Result.CONTAINER_NOT_FOUND : UNKNOWN_BCSID,
assertEquals((replicaIndex > 0 && rid != replicaIndex && clientVersion.toProtoValue() >=
ClientVersion.ERASURE_CODING_READ_CHUNK_CORRUPTION_FIX.toProtoValue()) ?
ContainerProtos.Result.CONTAINER_NOT_FOUND : UNKNOWN_BCSID,
response.getResult());
}

Expand Down Expand Up @@ -140,14 +153,17 @@ public void testReadChunk() {
}

@ParameterizedTest
@ValueSource(ints = {0, 1, 2, 3, 4, 5})
public void testReadChunkWithReplicaIndexMismatch(int replicaIndex) {
@MethodSource("getAllClientVersions")
public void testReadChunkWithReplicaIndexMismatch(ClientVersion clientVersion, int replicaIndex) {
KeyValueContainer container = getMockContainerWithReplicaIndex(replicaIndex);
KeyValueHandler handler = getDummyHandler();
for (int rid = 0; rid <= 5; rid++) {
ContainerProtos.ContainerCommandResponseProto response =
handler.handleReadChunk(getDummyCommandRequestProto(ContainerProtos.Type.ReadChunk, rid), container, null);
assertEquals(rid != replicaIndex ? ContainerProtos.Result.CONTAINER_NOT_FOUND : UNKNOWN_BCSID,
handler.handleReadChunk(getDummyCommandRequestProto(clientVersion, ContainerProtos.Type.ReadChunk, rid),
container, null);
assertEquals((replicaIndex > 0 && rid != replicaIndex &&
clientVersion.toProtoValue() >= ClientVersion.ERASURE_CODING_READ_CHUNK_CORRUPTION_FIX.toProtoValue()) ?
ContainerProtos.Result.CONTAINER_NOT_FOUND : UNKNOWN_BCSID,
response.getResult());
}

Expand Down

0 comments on commit 1476d59

Please sign in to comment.