Skip to content

Commit e3bba5f

Browse files
HADOOP-16706. ITestClientUrlScheme fails for accounts which don't support HTTP
Adds a new service code to recognise accounts without HTTP support; catches that and considers such a responset a successful validation of the ability of the client to switch to http when the test parameters expect that. Contributed by Steve Loughran
1 parent 7f35676 commit e3bba5f

File tree

2 files changed

+23
-5
lines changed

2 files changed

+23
-5
lines changed

hadoop-tools/hadoop-azure/src/main/java/org/apache/hadoop/fs/azurebfs/contracts/services/AzureServiceErrorCode.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ public enum AzureServiceErrorCode {
4646
EGRESS_OVER_ACCOUNT_LIMIT(null, HttpURLConnection.HTTP_UNAVAILABLE, "Egress is over the account limit."),
4747
INVALID_QUERY_PARAMETER_VALUE("InvalidQueryParameterValue", HttpURLConnection.HTTP_BAD_REQUEST, null),
4848
AUTHORIZATION_PERMISSION_MISS_MATCH("AuthorizationPermissionMismatch", HttpURLConnection.HTTP_FORBIDDEN, null),
49+
ACCOUNT_REQUIRES_HTTPS("AccountRequiresHttps", HttpURLConnection.HTTP_BAD_REQUEST, null),
4950
UNKNOWN(null, -1, null);
5051

5152
private final String errorCode;

hadoop-tools/hadoop-azure/src/test/java/org/apache/hadoop/fs/azurebfs/ITestClientUrlScheme.java

Lines changed: 22 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,8 @@
2929
import org.junit.runners.Parameterized;
3030

3131
import org.apache.hadoop.conf.Configuration;
32+
import org.apache.hadoop.fs.azurebfs.contracts.exceptions.AbfsRestOperationException;
33+
import org.apache.hadoop.fs.azurebfs.contracts.services.AzureServiceErrorCode;
3234
import org.apache.hadoop.fs.azurebfs.services.AbfsClient;
3335
import org.apache.hadoop.fs.CommonConfigurationKeysPublic;
3436
import org.apache.hadoop.fs.azurebfs.constants.FileSystemUriSchemes;
@@ -81,18 +83,33 @@ public void testClientUrlScheme() throws Exception {
8183
Configuration config = getRawConfiguration();
8284
config.set(CommonConfigurationKeysPublic.FS_DEFAULT_NAME_KEY, fsUrl.toString());
8385
config.setBoolean(FS_AZURE_ALWAYS_USE_HTTPS, alwaysUseHttps);
84-
85-
AbfsClient client = this.getFileSystem(config).getAbfsClient();
86+
// HTTP is enabled only when "abfs://XXX" is used and FS_AZURE_ALWAYS_USE_HTTPS
87+
// is set as false, otherwise HTTPS should be used.
88+
boolean expectHttpConnection = !useSecureScheme && !alwaysUseHttps;
89+
90+
AbfsClient client = null;
91+
try {
92+
client = this.getFileSystem(config).getAbfsClient();
93+
} catch (AbfsRestOperationException e) {
94+
if (AzureServiceErrorCode.ACCOUNT_REQUIRES_HTTPS.equals(e.getErrorCode())
95+
&& expectHttpConnection) {
96+
// if we get here, the error message was the account supports HTTPS only
97+
// and this parameterized test is trying to create an HTTP one.
98+
// we can implicitly infer that the scheme setup went through,
99+
// otherwise it would not have been rejected at the far end
100+
return;
101+
} else {
102+
throw e;
103+
}
104+
}
86105

87106
Field baseUrlField = AbfsClient.class.
88107
getDeclaredField("baseUrl");
89108
baseUrlField.setAccessible(true);
90109

91110
String url = ((URL) baseUrlField.get(client)).toString();
92111

93-
// HTTP is enabled only when "abfs://XXX" is used and FS_AZURE_ALWAYS_USE_HTTPS
94-
// is set as false, otherwise HTTPS should be used.
95-
if (!useSecureScheme && !alwaysUseHttps) {
112+
if (expectHttpConnection) {
96113
Assert.assertTrue(url.startsWith(FileSystemUriSchemes.HTTP_SCHEME));
97114
} else {
98115
Assert.assertTrue(url.startsWith(FileSystemUriSchemes.HTTPS_SCHEME));

0 commit comments

Comments
 (0)