Skip to content

Commit d0ba380

Browse files
Hean ChhinlingHean Chhinling
authored andcommitted
YARN-11726: Adding test cases for IOException and change log from debug to info
1 parent 809e3d8 commit d0ba380

2 files changed

Lines changed: 22 additions & 6 deletions

File tree

hadoop-yarn-project/hadoop-yarn/hadoop-yarn-common/src/main/java/org/apache/hadoop/yarn/webapp/util/WebAppUtils.java

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -512,13 +512,18 @@ static String getPassword(Configuration conf, String alias) {
512512
char[] passchars = conf.getPassword(alias);
513513
if (passchars != null) {
514514
password = new String(passchars);
515-
LOG.debug("Successful password retrieval for alias: {}", alias);
515+
LOG.info("Successful password retrieval for alias: {}", alias);
516516
}
517517
}
518518
catch (IOException ioe) {
519519
password = null;
520520
LOG.error("Unable to retrieve password for alias: {}", alias, ioe);
521521
}
522+
523+
if (password == null) {
524+
LOG.error("Password does not exist for alias: {}", alias);
525+
}
526+
522527
return password;
523528
}
524529

hadoop-yarn-project/hadoop-yarn/hadoop-yarn-common/src/test/java/org/apache/hadoop/yarn/webapp/util/TestWebAppUtils.java

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
import java.util.Map;
2626
import javax.servlet.http.HttpServletRequest;
2727

28+
import org.apache.hadoop.yarn.util.TestBoundedAppender;
2829
import org.junit.jupiter.api.AfterAll;
2930
import org.junit.jupiter.api.BeforeAll;
3031
import org.junit.jupiter.api.Test;
@@ -43,6 +44,7 @@
4344
import static org.junit.jupiter.api.Assertions.assertArrayEquals;
4445
import static org.junit.jupiter.api.Assertions.assertEquals;
4546
import static org.junit.jupiter.api.Assertions.assertNull;
47+
import static org.mockito.Mockito.when;
4648

4749
public class TestWebAppUtils {
4850
private static final String RM1_NODE_ID = "rm1";
@@ -109,6 +111,15 @@ void testGetPassword() throws Exception {
109111
assertNull(WebAppUtils.getPassword(conf, "invalid-alias"));
110112
}
111113

114+
@Test
115+
void testGetPasswordIOException() throws Exception {
116+
Configuration mockConf = Mockito.mock(Configuration.class);
117+
118+
when(mockConf.getPassword("error-alias")).thenThrow(new IOException("Simulated IO error"));
119+
120+
assertNull(WebAppUtils.getPassword(mockConf, "error-alias"));
121+
}
122+
112123
@Test
113124
void testLoadSslConfiguration() throws Exception {
114125
Configuration conf = provisionCredentialsForSSL();
@@ -186,7 +197,7 @@ protected Configuration provisionCredentialsForSSL() throws IOException,
186197
void testAppendQueryParams() throws Exception {
187198
HttpServletRequest request = Mockito.mock(HttpServletRequest.class);
188199
String targetUri = "/test/path";
189-
Mockito.when(request.getCharacterEncoding()).thenReturn(null);
200+
when(request.getCharacterEncoding()).thenReturn(null);
190201
Map<String, String> paramResultMap = new HashMap<>();
191202
paramResultMap.put("param1=x", targetUri + "?" + "param1=x");
192203
paramResultMap
@@ -195,7 +206,7 @@ void testAppendQueryParams() throws Exception {
195206
targetUri + "?" + "param1=x&param2=y&param3=x+y");
196207

197208
for (Map.Entry<String, String> entry : paramResultMap.entrySet()) {
198-
Mockito.when(request.getQueryString()).thenReturn(entry.getKey());
209+
when(request.getQueryString()).thenReturn(entry.getKey());
199210
String uri = WebAppUtils.appendQueryParams(request, targetUri);
200211
assertEquals(entry.getValue(), uri);
201212
}
@@ -205,8 +216,8 @@ void testAppendQueryParams() throws Exception {
205216
void testGetHtmlEscapedURIWithQueryString() throws Exception {
206217
HttpServletRequest request = Mockito.mock(HttpServletRequest.class);
207218
String targetUri = "/test/path";
208-
Mockito.when(request.getCharacterEncoding()).thenReturn(null);
209-
Mockito.when(request.getRequestURI()).thenReturn(targetUri);
219+
when(request.getCharacterEncoding()).thenReturn(null);
220+
when(request.getRequestURI()).thenReturn(targetUri);
210221
Map<String, String> paramResultMap = new HashMap<>();
211222
paramResultMap.put("param1=x", targetUri + "?" + "param1=x");
212223
paramResultMap
@@ -215,7 +226,7 @@ void testGetHtmlEscapedURIWithQueryString() throws Exception {
215226
targetUri + "?" + "param1=x&amp;param2=y&amp;param3=x+y");
216227

217228
for (Map.Entry<String, String> entry : paramResultMap.entrySet()) {
218-
Mockito.when(request.getQueryString()).thenReturn(entry.getKey());
229+
when(request.getQueryString()).thenReturn(entry.getKey());
219230
String uri = WebAppUtils.getHtmlEscapedURIWithQueryString(request);
220231
assertEquals(entry.getValue(), uri);
221232
}

0 commit comments

Comments
 (0)