Skip to content

Commit e586bf9

Browse files
author
Anuj Modi
committed
Addressed Comments
1 parent 7a3afea commit e586bf9

File tree

1 file changed

+61
-21
lines changed

1 file changed

+61
-21
lines changed

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

Lines changed: 61 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@
2121
import java.io.IOException;
2222

2323
import org.assertj.core.api.Assertions;
24-
import org.junit.Assert;
2524
import org.junit.Test;
2625

2726
import org.apache.hadoop.conf.Configuration;
@@ -43,7 +42,8 @@
4342
* Verify the AbfsRestOperationException error message format.
4443
* */
4544
public class ITestAbfsRestOperationException extends AbstractAbfsIntegrationTest{
46-
private static final String RETRY_TEST_TOKEN_PROVIDER = "org.apache.hadoop.fs.azurebfs.oauth2.RetryTestTokenProvider";
45+
private static final String RETRY_TEST_TOKEN_PROVIDER =
46+
"org.apache.hadoop.fs.azurebfs.oauth2.RetryTestTokenProvider";
4747

4848
public ITestAbfsRestOperationException() throws Exception {
4949
super();
@@ -61,13 +61,29 @@ public void testAbfsRestOperationExceptionFormat() throws IOException {
6161
String[] errorFields = errorMessage.split(",");
6262

6363
// Expected Fields are: Message, StatusCode, Method, URL, ActivityId(rId)
64-
Assert.assertEquals(5, errorFields.length);
64+
Assertions.assertThat(errorFields)
65+
.describedAs("Number of Fields in exception message are not as expected")
66+
.hasSize(5);
6567
// Check status message, status code, HTTP Request Type and URL.
66-
Assert.assertEquals("Operation failed: \"The specified path does not exist.\"", errorFields[0].trim());
67-
Assert.assertEquals("404", errorFields[1].trim());
68-
Assert.assertEquals("HEAD", errorFields[2].trim());
69-
Assert.assertTrue(errorFields[3].trim().startsWith("http"));
70-
Assert.assertTrue(errorFields[4].trim().startsWith("rId:"));
68+
Assertions.assertThat(errorFields[0].trim())
69+
.describedAs("Error Message Field in exception message is wrong")
70+
.isEqualTo("Operation failed: \"The specified path does not exist.\"");
71+
Assertions.assertThat(errorFields[1].trim())
72+
.describedAs("Status Code Field in exception message "
73+
+ "should be \"404\"")
74+
.isEqualTo("404");
75+
Assertions.assertThat(errorFields[2].trim())
76+
.describedAs("Http Rest Method Field in exception message "
77+
+ "should be \"HEAD\"")
78+
.isEqualTo("HEAD");
79+
Assertions.assertThat(errorFields[3].trim())
80+
.describedAs("Url Field in exception message"
81+
+ " should start with \"http\"")
82+
.startsWith("http");
83+
Assertions.assertThat(errorFields[4].trim())
84+
.describedAs("ActivityId Field in exception message "
85+
+ "should start with \"rId:\"")
86+
.startsWith("rId:");
7187
}
7288

7389
try {
@@ -76,19 +92,43 @@ public void testAbfsRestOperationExceptionFormat() throws IOException {
7692
// verify its format
7793
String errorMessage = ex.getLocalizedMessage();
7894
String[] errorFields = errorMessage.split(",");
95+
// Expected Fields are: Message, StatusCode, Method, URL, ActivityId(rId), StorageErrorCode, StorageErrorMessage
7996
Assertions.assertThat(errorFields)
80-
.describedAs("fields in exception of %s", ex)
97+
.describedAs("Number of Fields in exception message are not as expected")
8198
.hasSize(7);
8299
// Check status message, status code, HTTP Request Type and URL.
83-
Assert.assertEquals("Operation failed: \"The specified path does not exist.\"", errorFields[0].trim());
84-
Assert.assertEquals("404", errorFields[1].trim());
85-
Assert.assertEquals("GET", errorFields[2].trim());
86-
Assert.assertTrue(errorFields[3].trim().startsWith("http"));
87-
Assert.assertTrue(errorFields[4].trim().startsWith("rId:"));
100+
Assertions.assertThat(errorFields[0].trim())
101+
.describedAs("Error Message Field in exception message is wrong")
102+
.isEqualTo("Operation failed: \"The specified path does not exist.\"");
103+
Assertions.assertThat(errorFields[1].trim())
104+
.describedAs("Status Code Field in exception message"
105+
+ " should be \"404\"")
106+
.isEqualTo("404");
107+
Assertions.assertThat(errorFields[2].trim())
108+
.describedAs("Http Rest Method Field in exception message"
109+
+ " should be \"GET\"")
110+
.isEqualTo("GET");
111+
Assertions.assertThat(errorFields[3].trim())
112+
.describedAs("Url Field in exception message"
113+
+ " should start with \"http\"")
114+
.startsWith("http");
115+
Assertions.assertThat(errorFields[4].trim())
116+
.describedAs("ActivityId Field in exception message"
117+
+ " should start with \"rId:\"")
118+
.startsWith("rId:");
88119
// Check storage error code and storage error message.
89-
Assert.assertEquals("PathNotFound", errorFields[5].trim());
90-
Assert.assertTrue(errorFields[6].contains("RequestId")
91-
&& errorFields[6].contains("Time"));
120+
Assertions.assertThat(errorFields[5].trim())
121+
.describedAs("StorageErrorCode Field in exception message"
122+
+ " should be \"PathNotFound\"")
123+
.isEqualTo("PathNotFound");
124+
Assertions.assertThat(errorFields[6].trim())
125+
.describedAs("StorageErrorMessage Field in exception message"
126+
+ " should contain \"RequestId\"")
127+
.contains("RequestId");
128+
Assertions.assertThat(errorFields[6].trim())
129+
.describedAs("StorageErrorMessage Field in exception message"
130+
+ " should contain \"Time\"")
131+
.contains("Time");
92132
}
93133
}
94134

@@ -126,10 +166,10 @@ public void testWithDifferentCustomTokenFetchRetry(int numOfRetries) throws Exce
126166
});
127167

128168
// Number of retries done should be as configured
129-
Assert.assertEquals(
130-
"Number of token fetch retries done does not match with fs.azure"
131-
+ ".custom.token.fetch.retry.count configured", numOfRetries,
132-
retryTestTokenProvider.getRetryCount());
169+
Assertions.assertThat(retryTestTokenProvider.getRetryCount())
170+
.describedAs("Number of token fetch retries done does not "
171+
+ "match with fs.azure.custom.token.fetch.retry.count configured")
172+
.isEqualTo(numOfRetries);
133173
}
134174

135175
@Test

0 commit comments

Comments
 (0)