Skip to content
Merged
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 @@ -20,10 +20,10 @@

import java.io.IOException;
import java.util.Map;
import java.util.Random;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.atomic.AtomicInteger;

import org.apache.commons.lang3.RandomUtils;
import org.apache.hadoop.hdds.client.BlockID;
import org.apache.hadoop.hdds.protocol.DatanodeDetails;
import org.apache.hadoop.hdds.protocol.datanode.proto.ContainerProtos.ChecksumType;
Expand All @@ -42,9 +42,10 @@
import org.apache.hadoop.hdds.scm.XceiverClientSpi;
import org.apache.hadoop.hdds.scm.pipeline.MockPipeline;
import org.apache.hadoop.hdds.scm.pipeline.Pipeline;

import org.apache.hadoop.ozone.OzoneConsts;
import org.apache.ratis.thirdparty.com.google.protobuf.ByteString;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.ValueSource;

import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.mockito.Mockito.any;
Expand All @@ -56,37 +57,28 @@
* <p>
* Compares bytes written to the stream and received in the ChunkWriteRequests.
*/
public class TestBlockOutputStreamCorrectness {

private static final long SEED = 18480315L;
class TestBlockOutputStreamCorrectness {

private int writeUnitSize = 1;
private static final int DATA_SIZE = 256 * (int) OzoneConsts.MB;
private static final byte[] DATA = RandomUtils.nextBytes(DATA_SIZE);

@Test
public void test() throws IOException {
@ParameterizedTest
@ValueSource(ints = { 1, 1024, 1024 * 1024 })
void test(final int writeSize) throws IOException {
assertEquals(0, DATA_SIZE % writeSize);

final BufferPool bufferPool = new BufferPool(4 * 1024 * 1024, 32 / 4);

for (int block = 0; block < 10; block++) {
BlockOutputStream outputStream =
createBlockOutputStream(bufferPool);

Random random = new Random(SEED);

int max = 256 * 1024 * 1024 / writeUnitSize;

byte[] writeBuffer = new byte[writeUnitSize];
for (int t = 0; t < max; t++) {
if (writeUnitSize > 1) {
for (int i = 0; i < writeBuffer.length; i++) {
writeBuffer[i] = (byte) random.nextInt();
try (BlockOutputStream outputStream = createBlockOutputStream(bufferPool)) {
for (int i = 0; i < DATA_SIZE / writeSize; i++) {
if (writeSize > 1) {
outputStream.write(DATA, i * writeSize, writeSize);
} else {
outputStream.write(DATA[i]);
}
outputStream.write(writeBuffer, 0, writeBuffer.length);
} else {
outputStream.write((byte) random.nextInt());
}
}
outputStream.close();
}
}

Expand Down Expand Up @@ -126,9 +118,8 @@ private static class MockXceiverClientSpi extends XceiverClientSpi {

private final Pipeline pipeline;

private final Random expectedRandomStream = new Random(SEED);

private final AtomicInteger counter = new AtomicInteger();
private int i;

MockXceiverClientSpi(Pipeline pipeline) {
super();
Expand Down Expand Up @@ -175,8 +166,8 @@ public XceiverClientReply sendCommandAsync(
ByteString data = request.getWriteChunk().getData();
final byte[] writePayload = data.toByteArray();
for (byte b : writePayload) {
byte expectedByte = (byte) expectedRandomStream.nextInt();
assertEquals(expectedByte, b);
assertEquals(DATA[i], b);
++i;
}
break;
default:
Expand Down