21
21
import java .io .IOException ;
22
22
23
23
import org .assertj .core .api .Assertions ;
24
- import org .junit .Assert ;
25
24
import org .junit .Test ;
26
25
27
26
import org .apache .hadoop .conf .Configuration ;
43
42
* Verify the AbfsRestOperationException error message format.
44
43
* */
45
44
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" ;
47
47
48
48
public ITestAbfsRestOperationException () throws Exception {
49
49
super ();
@@ -61,13 +61,29 @@ public void testAbfsRestOperationExceptionFormat() throws IOException {
61
61
String [] errorFields = errorMessage .split ("," );
62
62
63
63
// 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 );
65
67
// 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:" );
71
87
}
72
88
73
89
try {
@@ -76,19 +92,43 @@ public void testAbfsRestOperationExceptionFormat() throws IOException {
76
92
// verify its format
77
93
String errorMessage = ex .getLocalizedMessage ();
78
94
String [] errorFields = errorMessage .split ("," );
95
+ // Expected Fields are: Message, StatusCode, Method, URL, ActivityId(rId), StorageErrorCode, StorageErrorMessage
79
96
Assertions .assertThat (errorFields )
80
- .describedAs ("fields in exception of %s" , ex )
97
+ .describedAs ("Number of Fields in exception message are not as expected" )
81
98
.hasSize (7 );
82
99
// 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:" );
88
119
// 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" );
92
132
}
93
133
}
94
134
@@ -126,10 +166,10 @@ public void testWithDifferentCustomTokenFetchRetry(int numOfRetries) throws Exce
126
166
});
127
167
128
168
// 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 );
133
173
}
134
174
135
175
@ Test
0 commit comments