|
@@ -19,6 +19,7 @@
|
|
|
package org.apache.hadoop.fs.s3a;
|
|
|
|
|
|
import static org.apache.hadoop.fs.s3a.Constants.*;
|
|
|
+import static org.apache.hadoop.fs.s3a.S3ATestConstants.*;
|
|
|
import static org.junit.Assert.*;
|
|
|
|
|
|
import java.io.IOException;
|
|
@@ -26,8 +27,13 @@ import java.net.URI;
|
|
|
import java.nio.file.AccessDeniedException;
|
|
|
|
|
|
import org.apache.hadoop.conf.Configuration;
|
|
|
+import org.apache.hadoop.fs.FileStatus;
|
|
|
+import org.apache.hadoop.fs.FileSystem;
|
|
|
import org.apache.hadoop.fs.Path;
|
|
|
+import org.junit.Rule;
|
|
|
import org.junit.Test;
|
|
|
+import org.junit.rules.ExpectedException;
|
|
|
+import org.junit.rules.Timeout;
|
|
|
|
|
|
import com.amazonaws.auth.AWSCredentials;
|
|
|
import com.amazonaws.auth.AWSCredentialsProvider;
|
|
@@ -45,6 +51,12 @@ public class TestS3AAWSCredentialsProvider {
|
|
|
private static final Logger LOG =
|
|
|
LoggerFactory.getLogger(TestS3AAWSCredentialsProvider.class);
|
|
|
|
|
|
+ @Rule
|
|
|
+ public Timeout testTimeout = new Timeout(1 * 60 * 1000);
|
|
|
+
|
|
|
+ @Rule
|
|
|
+ public ExpectedException exception = ExpectedException.none();
|
|
|
+
|
|
|
@Test
|
|
|
public void testBadConfiguration() throws IOException {
|
|
|
Configuration conf = new Configuration();
|
|
@@ -113,4 +125,47 @@ public class TestS3AAWSCredentialsProvider {
|
|
|
conf.set(AWS_CREDENTIALS_PROVIDER, GoodCredentialsProvider.class.getName());
|
|
|
S3ATestUtils.createTestFileSystem(conf);
|
|
|
}
|
|
|
+
|
|
|
+ @Test
|
|
|
+ public void testAnonymousProvider() throws Exception {
|
|
|
+ Configuration conf = new Configuration();
|
|
|
+ conf.set(AWS_CREDENTIALS_PROVIDER,
|
|
|
+ AnonymousAWSCredentialsProvider.class.getName());
|
|
|
+ Path testFile = new Path(
|
|
|
+ conf.getTrimmed(KEY_CSVTEST_FILE, DEFAULT_CSVTEST_FILE));
|
|
|
+ FileSystem fs = FileSystem.newInstance(testFile.toUri(), conf);
|
|
|
+ assertNotNull(fs);
|
|
|
+ assertTrue(fs instanceof S3AFileSystem);
|
|
|
+ FileStatus stat = fs.getFileStatus(testFile);
|
|
|
+ assertNotNull(stat);
|
|
|
+ assertEquals(testFile, stat.getPath());
|
|
|
+ }
|
|
|
+
|
|
|
+ static class ConstructorErrorProvider implements AWSCredentialsProvider {
|
|
|
+
|
|
|
+ @SuppressWarnings("unused")
|
|
|
+ public ConstructorErrorProvider(String str) {
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public AWSCredentials getCredentials() {
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void refresh() {
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ @Test
|
|
|
+ public void testProviderConstructorError() throws Exception {
|
|
|
+ Configuration conf = new Configuration();
|
|
|
+ conf.set(AWS_CREDENTIALS_PROVIDER,
|
|
|
+ ConstructorErrorProvider.class.getName());
|
|
|
+ Path testFile = new Path(
|
|
|
+ conf.getTrimmed(KEY_CSVTEST_FILE, DEFAULT_CSVTEST_FILE));
|
|
|
+ exception.expect(IOException.class);
|
|
|
+ exception.expectMessage("constructor exception");
|
|
|
+ FileSystem fs = FileSystem.newInstance(testFile.toUri(), conf);
|
|
|
+ }
|
|
|
}
|