Skip to content

Commit d23b56c

Browse files
committed
Revert "ODP-2637: MAPREDUCE-7434: Fix ShuffleHandler tests. Contributed by Tamas Domok (#49)"
This reverts commit 2e1efcf.
1 parent d634e5b commit d23b56c

File tree

3 files changed

+28
-47
lines changed

3 files changed

+28
-47
lines changed

hadoop-mapreduce-project/hadoop-mapreduce-client/hadoop-mapreduce-client-shuffle/src/test/java/org/apache/hadoop/mapred/TestShuffleChannelHandler.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -225,7 +225,7 @@ public void testInvalidMapNoDataFile() {
225225
final ShuffleTest t = createShuffleTest();
226226
final EmbeddedChannel shuffle = t.createShuffleHandlerChannelFileRegion();
227227

228-
String dataFile = getDataFile(TEST_USER, tempDir.toAbsolutePath().toString(), TEST_ATTEMPT_2);
228+
String dataFile = getDataFile(tempDir.toAbsolutePath().toString(), TEST_ATTEMPT_2);
229229
assertTrue("should delete", new File(dataFile).delete());
230230

231231
FullHttpRequest req = t.createRequest(getUri(TEST_JOB_ID, 0,

hadoop-mapreduce-project/hadoop-mapreduce-client/hadoop-mapreduce-client-shuffle/src/test/java/org/apache/hadoop/mapred/TestShuffleHandler.java

Lines changed: 13 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@
2929
import static org.apache.hadoop.test.MetricsAsserts.assertGauge;
3030
import static org.apache.hadoop.test.MetricsAsserts.getMetrics;
3131
import static org.junit.Assert.assertNotEquals;
32-
import static org.junit.Assert.assertNotNull;
3332
import static org.junit.Assert.assertTrue;
3433
import static org.junit.Assert.assertEquals;
3534
import static org.junit.Assert.fail;
@@ -43,7 +42,6 @@
4342
import java.io.File;
4443
import java.io.FileInputStream;
4544
import java.io.IOException;
46-
import java.io.InputStream;
4745
import java.io.InputStreamReader;
4846
import java.net.HttpURLConnection;
4947
import 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

hadoop-mapreduce-project/hadoop-mapreduce-client/hadoop-mapreduce-client-shuffle/src/test/java/org/apache/hadoop/mapred/TestShuffleHandlerBase.java

Lines changed: 14 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ public class TestShuffleHandlerBase {
5555
public static final String TEST_ATTEMPT_2 = "attempt_1111111111111_0002_m_000002_0";
5656
public static final String TEST_ATTEMPT_3 = "attempt_1111111111111_0003_m_000003_0";
5757
public static final String TEST_JOB_ID = "job_1111111111111_0001";
58-
public static final String TEST_USER = System.getProperty("user.name");
58+
public static final String TEST_USER = "testUser";
5959
public static final String TEST_DATA_A = "aaaaa";
6060
public static final String TEST_DATA_B = "bbbbb";
6161
public static final String TEST_DATA_C = "ccccc";
@@ -70,11 +70,11 @@ public void setup() throws IOException {
7070
tempDir = Files.createTempDirectory("test-shuffle-channel-handler");
7171
tempDir.toFile().deleteOnExit();
7272

73-
generateMapOutput(TEST_USER, tempDir.toAbsolutePath().toString(), TEST_ATTEMPT_1,
73+
generateMapOutput(tempDir.toAbsolutePath().toString(), TEST_ATTEMPT_1,
7474
Arrays.asList(TEST_DATA_A, TEST_DATA_B, TEST_DATA_C));
75-
generateMapOutput(TEST_USER, tempDir.toAbsolutePath().toString(), TEST_ATTEMPT_2,
75+
generateMapOutput(tempDir.toAbsolutePath().toString(), TEST_ATTEMPT_2,
7676
Arrays.asList(TEST_DATA_B, TEST_DATA_A, TEST_DATA_C));
77-
generateMapOutput(TEST_USER, tempDir.toAbsolutePath().toString(), TEST_ATTEMPT_3,
77+
generateMapOutput(tempDir.toAbsolutePath().toString(), TEST_ATTEMPT_3,
7878
Arrays.asList(TEST_DATA_C, TEST_DATA_B, TEST_DATA_A));
7979

8080
outputStreamCaptor.reset();
@@ -101,13 +101,12 @@ public List<String> matchLogs(String pattern) {
101101
return allMatches;
102102
}
103103

104-
public static void generateMapOutput(String user, String tempDir,
105-
String attempt, List<String> maps)
104+
public static void generateMapOutput(String tempDir, String attempt, List<String> maps)
106105
throws IOException {
107106
SpillRecord record = new SpillRecord(maps.size());
108107

109-
assertTrue(new File(getBasePath(user, tempDir, attempt)).mkdirs());
110-
try (PrintWriter writer = new PrintWriter(getDataFile(user, tempDir, attempt), "UTF-8")) {
108+
assertTrue(new File(getBasePath(tempDir, attempt)).mkdirs());
109+
try (PrintWriter writer = new PrintWriter(getDataFile(tempDir, attempt), "UTF-8")) {
111110
long startOffset = 0;
112111
int partition = 0;
113112
for (String map : maps) {
@@ -120,21 +119,21 @@ public static void generateMapOutput(String user, String tempDir,
120119
partition++;
121120
writer.write(map);
122121
}
123-
record.writeToFile(new Path(getIndexFile(user, tempDir, attempt)),
122+
record.writeToFile(new Path(getIndexFile(tempDir, attempt)),
124123
new JobConf(new Configuration()));
125124
}
126125
}
127126

128-
public static String getIndexFile(String user, String tempDir, String attempt) {
129-
return String.format("%s/%s", getBasePath(user, tempDir, attempt), INDEX_FILE_NAME);
127+
public static String getIndexFile(String tempDir, String attempt) {
128+
return String.format("%s/%s", getBasePath(tempDir, attempt), INDEX_FILE_NAME);
130129
}
131130

132-
public static String getDataFile(String user, String tempDir, String attempt) {
133-
return String.format("%s/%s", getBasePath(user, tempDir, attempt), DATA_FILE_NAME);
131+
public static String getDataFile(String tempDir, String attempt) {
132+
return String.format("%s/%s", getBasePath(tempDir, attempt), DATA_FILE_NAME);
134133
}
135134

136-
private static String getBasePath(String user, String tempDir, String attempt) {
137-
return String.format("%s/%s/%s/%s", tempDir, TEST_JOB_ID, user, attempt);
135+
private static String getBasePath(String tempDir, String attempt) {
136+
return String.format("%s/%s/%s/%s", tempDir, TEST_JOB_ID, TEST_USER, attempt);
138137
}
139138

140139
public static String getUri(String jobId, int reduce, List<String> maps, boolean keepAlive) {

0 commit comments

Comments
 (0)