|
@@ -18,21 +18,24 @@
|
|
|
|
|
|
package org.apache.hadoop.fs.s3a;
|
|
package org.apache.hadoop.fs.s3a;
|
|
|
|
|
|
-import org.apache.hadoop.fs.FSDataOutputStream;
|
|
|
|
-import org.apache.hadoop.fs.FileAlreadyExistsException;
|
|
|
|
-import org.apache.hadoop.fs.Path;
|
|
|
|
-import org.apache.hadoop.fs.contract.ContractTestUtils;
|
|
|
|
-import org.apache.hadoop.test.LambdaTestUtils;
|
|
|
|
|
|
+import java.io.ByteArrayInputStream;
|
|
|
|
+import java.io.FileNotFoundException;
|
|
|
|
+import java.io.IOException;
|
|
|
|
+import java.nio.charset.StandardCharsets;
|
|
|
|
|
|
import com.amazonaws.services.s3.model.ObjectMetadata;
|
|
import com.amazonaws.services.s3.model.ObjectMetadata;
|
|
import com.amazonaws.services.s3.model.PutObjectRequest;
|
|
import com.amazonaws.services.s3.model.PutObjectRequest;
|
|
-import com.amazonaws.services.s3.model.PutObjectResult;
|
|
|
|
|
|
+import org.junit.Assume;
|
|
import org.junit.Test;
|
|
import org.junit.Test;
|
|
|
|
|
|
-import java.io.ByteArrayInputStream;
|
|
|
|
-import java.io.FileNotFoundException;
|
|
|
|
-import java.io.IOException;
|
|
|
|
-import java.util.concurrent.Callable;
|
|
|
|
|
|
+import org.apache.hadoop.fs.FSDataOutputStream;
|
|
|
|
+import org.apache.hadoop.fs.FileAlreadyExistsException;
|
|
|
|
+import org.apache.hadoop.fs.Path;
|
|
|
|
+import org.apache.hadoop.fs.store.EtagChecksum;
|
|
|
|
+import org.apache.hadoop.test.LambdaTestUtils;
|
|
|
|
+
|
|
|
|
+import static org.apache.hadoop.fs.contract.ContractTestUtils.createFile;
|
|
|
|
+import static org.apache.hadoop.fs.contract.ContractTestUtils.touch;
|
|
|
|
|
|
/**
|
|
/**
|
|
* Tests of the S3A FileSystem which don't have a specific home and can share
|
|
* Tests of the S3A FileSystem which don't have a specific home and can share
|
|
@@ -40,6 +43,8 @@ import java.util.concurrent.Callable;
|
|
*/
|
|
*/
|
|
public class ITestS3AMiscOperations extends AbstractS3ATestBase {
|
|
public class ITestS3AMiscOperations extends AbstractS3ATestBase {
|
|
|
|
|
|
|
|
+ private static final byte[] HELLO = "hello".getBytes(StandardCharsets.UTF_8);
|
|
|
|
+
|
|
@Test
|
|
@Test
|
|
public void testCreateNonRecursiveSuccess() throws IOException {
|
|
public void testCreateNonRecursiveSuccess() throws IOException {
|
|
Path shouldWork = path("nonrecursivenode");
|
|
Path shouldWork = path("nonrecursivenode");
|
|
@@ -58,7 +63,7 @@ public class ITestS3AMiscOperations extends AbstractS3ATestBase {
|
|
@Test(expected = FileAlreadyExistsException.class)
|
|
@Test(expected = FileAlreadyExistsException.class)
|
|
public void testCreateNonRecursiveParentIsFile() throws IOException {
|
|
public void testCreateNonRecursiveParentIsFile() throws IOException {
|
|
Path parent = path("/file.txt");
|
|
Path parent = path("/file.txt");
|
|
- ContractTestUtils.touch(getFileSystem(), parent);
|
|
|
|
|
|
+ touch(getFileSystem(), parent);
|
|
createNonRecursive(new Path(parent, "fail"));
|
|
createNonRecursive(new Path(parent, "fail"));
|
|
}
|
|
}
|
|
|
|
|
|
@@ -73,12 +78,7 @@ public class ITestS3AMiscOperations extends AbstractS3ATestBase {
|
|
new ByteArrayInputStream("PUT".getBytes()),
|
|
new ByteArrayInputStream("PUT".getBytes()),
|
|
metadata);
|
|
metadata);
|
|
LambdaTestUtils.intercept(IllegalStateException.class,
|
|
LambdaTestUtils.intercept(IllegalStateException.class,
|
|
- new Callable<PutObjectResult>() {
|
|
|
|
- @Override
|
|
|
|
- public PutObjectResult call() throws Exception {
|
|
|
|
- return fs.putObjectDirect(put);
|
|
|
|
- }
|
|
|
|
- });
|
|
|
|
|
|
+ () -> fs.putObjectDirect(put));
|
|
assertPathDoesNotExist("put object was created", path);
|
|
assertPathDoesNotExist("put object was created", path);
|
|
}
|
|
}
|
|
|
|
|
|
@@ -87,4 +87,103 @@ public class ITestS3AMiscOperations extends AbstractS3ATestBase {
|
|
(short) 3, (short) 4096,
|
|
(short) 3, (short) 4096,
|
|
null);
|
|
null);
|
|
}
|
|
}
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ * Touch a path, return the full path.
|
|
|
|
+ * @param name relative name
|
|
|
|
+ * @return the path
|
|
|
|
+ * @throws IOException IO failure
|
|
|
|
+ */
|
|
|
|
+ Path touchFile(String name) throws IOException {
|
|
|
|
+ Path path = path(name);
|
|
|
|
+ touch(getFileSystem(), path);
|
|
|
|
+ return path;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ * Create a file with the data, return the path.
|
|
|
|
+ * @param name relative name
|
|
|
|
+ * @param data data to write
|
|
|
|
+ * @return the path
|
|
|
|
+ * @throws IOException IO failure
|
|
|
|
+ */
|
|
|
|
+ Path mkFile(String name, byte[] data) throws IOException {
|
|
|
|
+ final Path f = path(name);
|
|
|
|
+ createFile(getFileSystem(), f, true, data);
|
|
|
|
+ return f;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ * The assumption here is that 0-byte files uploaded in a single PUT
|
|
|
|
+ * always have the same checksum, including stores with encryption.
|
|
|
|
+ * @throws Throwable on a failure
|
|
|
|
+ */
|
|
|
|
+ @Test
|
|
|
|
+ public void testEmptyFileChecksums() throws Throwable {
|
|
|
|
+ final S3AFileSystem fs = getFileSystem();
|
|
|
|
+ Path file1 = touchFile("file1");
|
|
|
|
+ EtagChecksum checksum1 = fs.getFileChecksum(file1, 0);
|
|
|
|
+ LOG.info("Checksum for {}: {}", file1, checksum1);
|
|
|
|
+ assertNotNull("file 1 checksum", checksum1);
|
|
|
|
+ assertNotEquals("file 1 checksum", 0, checksum1.getLength());
|
|
|
|
+ assertEquals("checksums", checksum1,
|
|
|
|
+ fs.getFileChecksum(touchFile("file2"), 0));
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ * Verify that different file contents have different
|
|
|
|
+ * checksums, and that that they aren't the same as the empty file.
|
|
|
|
+ * @throws Throwable failure
|
|
|
|
+ */
|
|
|
|
+ @Test
|
|
|
|
+ public void testNonEmptyFileChecksums() throws Throwable {
|
|
|
|
+ final S3AFileSystem fs = getFileSystem();
|
|
|
|
+ final Path file3 = mkFile("file3", HELLO);
|
|
|
|
+ final EtagChecksum checksum1 = fs.getFileChecksum(file3, 0);
|
|
|
|
+ assertNotNull("file 3 checksum", checksum1);
|
|
|
|
+ final Path file4 = touchFile("file4");
|
|
|
|
+ final EtagChecksum checksum2 = fs.getFileChecksum(file4, 0);
|
|
|
|
+ assertNotEquals("checksums", checksum1, checksum2);
|
|
|
|
+ // overwrite
|
|
|
|
+ createFile(fs, file4, true,
|
|
|
|
+ "hello, world".getBytes(StandardCharsets.UTF_8));
|
|
|
|
+ assertNotEquals(checksum2, fs.getFileChecksum(file4, 0));
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ * Verify that on an unencrypted store, the checksum of two non-empty
|
|
|
|
+ * (single PUT) files is the same if the data is the same.
|
|
|
|
+ * This will fail if the bucket has S3 default encryption enabled.
|
|
|
|
+ * @throws Throwable failure
|
|
|
|
+ */
|
|
|
|
+ @Test
|
|
|
|
+ public void testNonEmptyFileChecksumsUnencrypted() throws Throwable {
|
|
|
|
+ Assume.assumeTrue(encryptionAlgorithm().equals(S3AEncryptionMethods.NONE));
|
|
|
|
+ final S3AFileSystem fs = getFileSystem();
|
|
|
|
+ final EtagChecksum checksum1 =
|
|
|
|
+ fs.getFileChecksum(mkFile("file5", HELLO), 0);
|
|
|
|
+ assertNotNull("file 3 checksum", checksum1);
|
|
|
|
+ assertEquals("checksums", checksum1,
|
|
|
|
+ fs.getFileChecksum(mkFile("file6", HELLO), 0));
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ private S3AEncryptionMethods encryptionAlgorithm() {
|
|
|
|
+ return getFileSystem().getServerSideEncryptionAlgorithm();
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ @Test
|
|
|
|
+ public void testNegativeLength() throws Throwable {
|
|
|
|
+ LambdaTestUtils.intercept(IllegalArgumentException.class,
|
|
|
|
+ () -> getFileSystem().getFileChecksum(mkFile("negative", HELLO), -1));
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ @Test
|
|
|
|
+ public void testLengthPastEOF() throws Throwable {
|
|
|
|
+ final S3AFileSystem fs = getFileSystem();
|
|
|
|
+ Path f = mkFile("file5", HELLO);
|
|
|
|
+ assertEquals(
|
|
|
|
+ fs.getFileChecksum(f, HELLO.length),
|
|
|
|
+ fs.getFileChecksum(f, HELLO.length * 2));
|
|
|
|
+ }
|
|
|
|
+
|
|
}
|
|
}
|