2929import static org .apache .hadoop .test .MetricsAsserts .assertGauge ;
3030import static org .apache .hadoop .test .MetricsAsserts .getMetrics ;
3131import static org .junit .Assert .assertNotEquals ;
32- import static org .junit .Assert .assertNotNull ;
3332import static org .junit .Assert .assertTrue ;
3433import static org .junit .Assert .assertEquals ;
3534import static org .junit .Assert .fail ;
4342import java .io .File ;
4443import java .io .FileInputStream ;
4544import java .io .IOException ;
46- import java .io .InputStream ;
4745import java .io .InputStreamReader ;
4846import java .net .HttpURLConnection ;
4947import java .net .MalformedURLException ;
@@ -162,7 +160,7 @@ public void testMaxConnections() throws Exception {
162160 shuffleHandler .init (conf );
163161 shuffleHandler .start ();
164162 final String port = shuffleHandler .getConfig ().get (SHUFFLE_PORT_CONFIG_KEY );
165- final SecretKey secretKey = shuffleHandler .addTestApp (TEST_USER );
163+ final SecretKey secretKey = shuffleHandler .addTestApp ();
166164
167165 // setup connections
168166 HttpURLConnection [] conns = new HttpURLConnection [connAttempts ];
@@ -240,7 +238,7 @@ public void testKeepAlive() throws Exception {
240238 shuffleHandler .init (conf );
241239 shuffleHandler .start ();
242240 final String port = shuffleHandler .getConfig ().get (ShuffleHandler .SHUFFLE_PORT_CONFIG_KEY );
243- final SecretKey secretKey = shuffleHandler .addTestApp (TEST_USER );
241+ final SecretKey secretKey = shuffleHandler .addTestApp ();
244242
245243 HttpURLConnection conn1 = createRequest (
246244 geURL (port , TEST_JOB_ID , 0 , Collections .singletonList (TEST_ATTEMPT_1 ), true ),
@@ -281,34 +279,18 @@ public void testMapFileAccess() throws IOException {
281279 conf .set (CommonConfigurationKeysPublic .HADOOP_SECURITY_AUTHENTICATION , "kerberos" );
282280 UserGroupInformation .setConfiguration (conf );
283281
284- final String randomUser = "randomUser" ;
285- final String attempt = "attempt_1111111111111_0004_m_000004_0" ;
286- generateMapOutput (randomUser , tempDir .toAbsolutePath ().toString (), attempt ,
287- Arrays .asList (TEST_DATA_C , TEST_DATA_B , TEST_DATA_A ));
288-
289282 ShuffleHandlerMock shuffleHandler = new ShuffleHandlerMock ();
290283 shuffleHandler .init (conf );
291284 try {
292285 shuffleHandler .start ();
293286 final String port = shuffleHandler .getConfig ().get (ShuffleHandler .SHUFFLE_PORT_CONFIG_KEY );
294- final SecretKey secretKey = shuffleHandler .addTestApp (randomUser );
287+ final SecretKey secretKey = shuffleHandler .addTestApp ();
295288
296289 HttpURLConnection conn = createRequest (
297- geURL (port , TEST_JOB_ID , 0 , Collections .singletonList (attempt ), false ),
290+ geURL (port , TEST_JOB_ID , 0 , Collections .singletonList (TEST_ATTEMPT_1 ), false ),
298291 secretKey );
299292 conn .connect ();
300-
301- InputStream is = null ;
302- try {
303- is = conn .getInputStream ();
304- } catch (IOException ioe ) {
305- if (conn .getResponseCode () != HttpURLConnection .HTTP_OK ) {
306- is = conn .getErrorStream ();
307- }
308- }
309-
310- assertNotNull (is );
311- BufferedReader in = new BufferedReader (new InputStreamReader (is ));
293+ BufferedReader in = new BufferedReader (new InputStreamReader (conn .getInputStream ()));
312294 StringBuilder builder = new StringBuilder ();
313295 String inputLine ;
314296 while ((inputLine = in .readLine ()) != null ) {
@@ -318,19 +300,19 @@ public void testMapFileAccess() throws IOException {
318300 String receivedString = builder .toString ();
319301
320302 //Retrieve file owner name
321- String indexFilePath = getIndexFile (randomUser , tempDir .toAbsolutePath ().toString (), attempt );
303+ String indexFilePath = getIndexFile (tempDir .toAbsolutePath ().toString (), TEST_ATTEMPT_1 );
322304 String owner ;
323305 try (FileInputStream fis = new FileInputStream (indexFilePath )) {
324306 owner = NativeIO .POSIX .getFstat (fis .getFD ()).getOwner ();
325307 }
326308
327309 String message =
328310 "Owner '" + owner + "' for path " + indexFilePath
329- + " did not match expected owner '" + randomUser + "'" ;
311+ + " did not match expected owner '" + TEST_USER + "'" ;
330312 assertTrue (String .format ("Received string '%s' should contain " +
331313 "message '%s'" , receivedString , message ),
332314 receivedString .contains (message ));
333- assertEquals (HttpURLConnection .HTTP_INTERNAL_ERROR , conn .getResponseCode ());
315+ assertEquals (HttpURLConnection .HTTP_OK , conn .getResponseCode ());
334316 LOG .info ("received: " + receivedString );
335317 assertNotEquals ("" , receivedString );
336318 } finally {
@@ -353,7 +335,7 @@ public void testRecovery() throws IOException {
353335 shuffle .init (conf );
354336 shuffle .start ();
355337 final String port = shuffle .getConfig ().get (ShuffleHandler .SHUFFLE_PORT_CONFIG_KEY );
356- final SecretKey secretKey = shuffle .addTestApp (TEST_USER );
338+ final SecretKey secretKey = shuffle .addTestApp ();
357339
358340 // verify we are authorized to shuffle
359341 int rc = getShuffleResponseCode (port , secretKey );
@@ -406,7 +388,7 @@ public void testRecoveryFromOtherVersions() throws IOException {
406388 shuffle .init (conf );
407389 shuffle .start ();
408390 final String port = shuffle .getConfig ().get (ShuffleHandler .SHUFFLE_PORT_CONFIG_KEY );
409- final SecretKey secretKey = shuffle .addTestApp (TEST_USER );
391+ final SecretKey secretKey = shuffle .addTestApp ();
410392
411393 // verify we are authorized to shuffle
412394 int rc = getShuffleResponseCode (port , secretKey );
@@ -508,14 +490,14 @@ private static HttpURLConnection createRequest(URL url, SecretKey secretKey) thr
508490
509491 class ShuffleHandlerMock extends ShuffleHandler {
510492
511- public SecretKey addTestApp (String user ) throws IOException {
493+ public SecretKey addTestApp () throws IOException {
512494 DataOutputBuffer outputBuffer = new DataOutputBuffer ();
513495 outputBuffer .reset ();
514496 Token <JobTokenIdentifier > jt = new Token <>(
515- "identifier" .getBytes (), "password" .getBytes (), new Text (user ),
497+ "identifier" .getBytes (), "password" .getBytes (), new Text (TEST_USER ),
516498 new Text ("shuffleService" ));
517499 jt .write (outputBuffer );
518- initializeApplication (new ApplicationInitializationContext (user , TEST_APP_ID ,
500+ initializeApplication (new ApplicationInitializationContext (TEST_USER , TEST_APP_ID ,
519501 ByteBuffer .wrap (outputBuffer .getData (), 0 ,
520502 outputBuffer .getLength ())));
521503
0 commit comments