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
This commit is contained in:
Steve Loughran 2020-02-21 11:13:38 +00:00 committed by GitHub
parent 7f35676f90
commit e3bba5fa22
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 22 additions and 4 deletions

View File

@ -46,6 +46,7 @@ public enum AzureServiceErrorCode {
EGRESS_OVER_ACCOUNT_LIMIT(null, HttpURLConnection.HTTP_UNAVAILABLE, "Egress is over the account limit."),
INVALID_QUERY_PARAMETER_VALUE("InvalidQueryParameterValue", HttpURLConnection.HTTP_BAD_REQUEST, null),
AUTHORIZATION_PERMISSION_MISS_MATCH("AuthorizationPermissionMismatch", HttpURLConnection.HTTP_FORBIDDEN, null),
ACCOUNT_REQUIRES_HTTPS("AccountRequiresHttps", HttpURLConnection.HTTP_BAD_REQUEST, null),
UNKNOWN(null, -1, null);
private final String errorCode;

View File

@ -29,6 +29,8 @@ import org.junit.runner.RunWith;
import org.junit.runners.Parameterized;
import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.fs.azurebfs.contracts.exceptions.AbfsRestOperationException;
import org.apache.hadoop.fs.azurebfs.contracts.services.AzureServiceErrorCode;
import org.apache.hadoop.fs.azurebfs.services.AbfsClient;
import org.apache.hadoop.fs.CommonConfigurationKeysPublic;
import org.apache.hadoop.fs.azurebfs.constants.FileSystemUriSchemes;
@ -81,8 +83,25 @@ public class ITestClientUrlScheme extends AbstractAbfsIntegrationTest{
Configuration config = getRawConfiguration();
config.set(CommonConfigurationKeysPublic.FS_DEFAULT_NAME_KEY, fsUrl.toString());
config.setBoolean(FS_AZURE_ALWAYS_USE_HTTPS, alwaysUseHttps);
// HTTP is enabled only when "abfs://XXX" is used and FS_AZURE_ALWAYS_USE_HTTPS
// is set as false, otherwise HTTPS should be used.
boolean expectHttpConnection = !useSecureScheme && !alwaysUseHttps;
AbfsClient client = this.getFileSystem(config).getAbfsClient();
AbfsClient client = null;
try {
client = this.getFileSystem(config).getAbfsClient();
} catch (AbfsRestOperationException e) {
if (AzureServiceErrorCode.ACCOUNT_REQUIRES_HTTPS.equals(e.getErrorCode())
&& expectHttpConnection) {
// if we get here, the error message was the account supports HTTPS only
// and this parameterized test is trying to create an HTTP one.
// we can implicitly infer that the scheme setup went through,
// otherwise it would not have been rejected at the far end
return;
} else {
throw e;
}
}
Field baseUrlField = AbfsClient.class.
getDeclaredField("baseUrl");
@ -90,9 +109,7 @@ public class ITestClientUrlScheme extends AbstractAbfsIntegrationTest{
String url = ((URL) baseUrlField.get(client)).toString();
// HTTP is enabled only when "abfs://XXX" is used and FS_AZURE_ALWAYS_USE_HTTPS
// is set as false, otherwise HTTPS should be used.
if (!useSecureScheme && !alwaysUseHttps) {
if (expectHttpConnection) {
Assert.assertTrue(url.startsWith(FileSystemUriSchemes.HTTP_SCHEME));
} else {
Assert.assertTrue(url.startsWith(FileSystemUriSchemes.HTTPS_SCHEME));