Skip to content

Commit

Permalink
HADOOP-19027. checkstyle and code review.
Browse files Browse the repository at this point in the history
Change-Id: I37f05880cad808db9f53035d4d49af48a333f2c7
  • Loading branch information
steveloughran committed Jan 10, 2024
1 parent bf275ed commit 2a517eb
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -294,6 +294,11 @@ private static long toSafeLong(final Number size) {

private static final String BYTES_PREFIX = "bytes=";

/**
* Given a range header, determine the size of the request.
* @param rangeHeader header string
* @return parsed size or -1 for problems
*/
private static Number sizeFromRangeHeader(String rangeHeader) {
if (rangeHeader != null && rangeHeader.startsWith(BYTES_PREFIX)) {
String[] values = rangeHeader
Expand All @@ -302,7 +307,7 @@ private static Number sizeFromRangeHeader(String rangeHeader) {
if (values.length == 2) {
try {
long start = Long.parseUnsignedLong(values[0]);
long end = Long.parseUnsignedLong(values[0]);
long end = Long.parseUnsignedLong(values[1]);
return end - start;
} catch(NumberFormatException e) {
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1760,7 +1760,7 @@ public static Pair<Long, Long> requestRange(String rangeHeader) {
if (values.length == 2) {
try {
long start = Long.parseUnsignedLong(values[0]);
long end = Long.parseUnsignedLong(values[0]);
long end = Long.parseUnsignedLong(values[1]);
return Pair.of(start, end);
} catch (NumberFormatException e) {
LOG.warn("Failed to parse range header {}", rangeHeader, e);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -278,7 +278,6 @@ public void testExtractInterruptedIO() throws Throwable {
.build()));
}


@Test
public void testTranslateCredentialException() throws Throwable {
verifyExceptionClass(AccessDeniedException.class,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@
import java.io.EOFException;
import java.nio.ByteBuffer;
import java.util.Arrays;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.TimeUnit;

import org.assertj.core.api.Assertions;
import org.junit.Test;
Expand All @@ -32,12 +34,14 @@
import org.apache.hadoop.fs.FileRange;
import org.apache.hadoop.fs.FileStatus;
import org.apache.hadoop.fs.Path;
import org.apache.hadoop.fs.contract.ContractTestUtils;
import org.apache.hadoop.fs.s3a.S3AFileSystem;
import org.apache.hadoop.fs.s3a.S3AInputStream;
import org.apache.hadoop.fs.s3a.S3ATestUtils;
import org.apache.hadoop.fs.s3a.Statistic;
import org.apache.hadoop.fs.statistics.IOStatistics;

import static org.apache.hadoop.fs.FSExceptionMessages.EOF_IN_READ_FULLY;
import static org.apache.hadoop.fs.Options.OpenFileOptions.FS_OPTION_OPENFILE_READ_POLICY;
import static org.apache.hadoop.fs.Options.OpenFileOptions.FS_OPTION_OPENFILE_READ_POLICY_RANDOM;
import static org.apache.hadoop.fs.Options.OpenFileOptions.FS_OPTION_OPENFILE_READ_POLICY_SEQUENTIAL;
Expand All @@ -54,6 +58,7 @@
import static org.apache.hadoop.fs.statistics.IOStatisticsLogging.demandStringifyIOStatistics;
import static org.apache.hadoop.fs.statistics.StoreStatisticNames.ACTION_FILE_OPENED;
import static org.apache.hadoop.test.LambdaTestUtils.intercept;
import static org.apache.hadoop.test.LambdaTestUtils.interceptFuture;

/**
* Cost of openFile().
Expand Down Expand Up @@ -311,9 +316,8 @@ public void testPositionedReadableReadFullyPastEOF() throws Throwable {
with(Statistic.ACTION_HTTP_GET_REQUEST, 1)); // no attempt to re-open
}


/**
* Test {@code PositionedReadable#read()} past EOF in a file.
* Test {@code PositionedReadable.read()} past EOF in a file.
*/
@Test
public void testPositionedReadableReadPastEOF() throws Throwable {
Expand Down Expand Up @@ -349,6 +353,7 @@ public void testPositionedReadableReadPastEOF() throws Throwable {

/**
* Test Vector Read past EOF in a file.
* See related tests in {@code ITestS3AContractVectoredRead}
*/
@Test
public void testVectorReadPastEOF() throws Throwable {
Expand All @@ -361,16 +366,21 @@ public void testVectorReadPastEOF() throws Throwable {
verifyMetrics(() -> {
try (FSDataInputStream in =
openFile(longLen, FS_OPTION_OPENFILE_READ_POLICY_RANDOM)) {
byte[] buf = new byte[(int) (longLen + 1)];
assertS3StreamClosed(in);
byte[] buf = new byte[(int) (longLen)];
ByteBuffer bb = ByteBuffer.wrap(buf);
final FileRange range = FileRange.createFileRange(0, longLen);
in.readVectored(Arrays.asList(range), (i) -> bb);
interceptFuture(EOFException.class,
EOF_IN_READ_FULLY,
ContractTestUtils.VECTORED_READ_OPERATION_TEST_TIMEOUT_SECONDS,
TimeUnit.SECONDS,
range.getData());
assertS3StreamClosed(in);
return "vector read past EOF";
}

},
with(Statistic.ACTION_HTTP_GET_REQUEST, 0)); // vector stats don't add this
with(Statistic.ACTION_HTTP_GET_REQUEST, 1));
}

/**
Expand Down

0 comments on commit 2a517eb

Please sign in to comment.