-
Notifications
You must be signed in to change notification settings - Fork 443
TEZ-4733: Fix flaky TestHistoryParser.testParserWithSuccessfulJob #519
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,109 @@ | ||
| /* | ||
| * Licensed to the Apache Software Foundation (ASF) under one | ||
| * or more contributor license agreements. See the NOTICE file | ||
| * distributed with this work for additional information | ||
| * regarding copyright ownership. The ASF licenses this file | ||
| * to you under the Apache License, Version 2.0 (the | ||
| * "License"); you may not use this file except in compliance | ||
| * with the License. You may obtain a copy of the License at | ||
| * | ||
| * http://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, | ||
| * software distributed under the License is distributed on an | ||
| * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
| * KIND, either express or implied. See the License for the | ||
| * specific language governing permissions and limitations | ||
| * under the License. | ||
| */ | ||
| package org.apache.tez.history.parser; | ||
|
|
||
| import static org.junit.jupiter.api.Assertions.assertEquals; | ||
| import static org.junit.jupiter.api.Assertions.assertNotNull; | ||
| import static org.junit.jupiter.api.Assertions.assertThrows; | ||
| import static org.junit.jupiter.api.Assertions.assertTrue; | ||
|
|
||
| import java.io.File; | ||
| import java.io.FileOutputStream; | ||
| import java.nio.charset.StandardCharsets; | ||
| import java.nio.file.Path; | ||
| import java.util.Collections; | ||
| import java.util.zip.ZipEntry; | ||
| import java.util.zip.ZipOutputStream; | ||
|
|
||
| import org.apache.tez.dag.api.TezException; | ||
| import org.apache.tez.history.parser.datamodel.DagInfo; | ||
|
|
||
| import org.codehaus.jettison.json.JSONArray; | ||
| import org.codehaus.jettison.json.JSONException; | ||
| import org.codehaus.jettison.json.JSONObject; | ||
| import org.junit.jupiter.api.Test; | ||
| import org.junit.jupiter.api.io.TempDir; | ||
|
|
||
| public class TestATSFileParser { | ||
|
|
||
| private static final String DAG_ID = "dag_1234567890_0001_1"; | ||
|
|
||
| private static JSONObject minimalDagJson() throws JSONException { | ||
| JSONObject dag = new JSONObject(); | ||
| dag.put("entityId", DAG_ID); | ||
| dag.put("entityType", "TEZ_DAG_ID"); | ||
| JSONObject otherInfo = new JSONObject(); | ||
| otherInfo.put("startTime", 1L); | ||
| otherInfo.put("endTime", 2L); | ||
| otherInfo.put("status", "SUCCEEDED"); | ||
| otherInfo.put("counters", new JSONObject().put("counterGroups", new JSONArray())); | ||
| dag.put("otherInfo", otherInfo); | ||
| return dag; | ||
| } | ||
|
|
||
| private static File writeZip(Path dir, String name, ZipContent... entries) throws Exception { | ||
| File zip = dir.resolve(name).toFile(); | ||
| try (FileOutputStream fos = new FileOutputStream(zip); | ||
| ZipOutputStream zos = new ZipOutputStream(fos)) { | ||
| for (ZipContent entry : entries) { | ||
| zos.putNextEntry(new ZipEntry(entry.name())); | ||
| zos.write(entry.payload().getBytes(StandardCharsets.UTF_8)); | ||
| zos.closeEntry(); | ||
| } | ||
| } | ||
| return zip; | ||
| } | ||
|
|
||
| @Test | ||
| public void parserSkipsEmptyZipEntryAndParsesRemaining(@TempDir Path tmp) throws Exception { | ||
| JSONObject dagRoot = new JSONObject().put("dag", minimalDagJson()); | ||
|
|
||
| File zip = writeZip(tmp, "empty-then-good.zip", | ||
| new ZipContent("empty-part.json", ""), | ||
| new ZipContent("whitespace-part.json", " \n\t "), | ||
| new ZipContent(DAG_ID, dagRoot.toString())); | ||
|
|
||
| ATSFileParser parser = new ATSFileParser(Collections.singletonList(zip)); | ||
| DagInfo info = parser.getDAGData(DAG_ID); | ||
|
|
||
| assertNotNull(info, "Parser should return DagInfo even when some entries are empty"); | ||
| assertEquals(DAG_ID, info.getDagId()); | ||
| assertEquals("SUCCEEDED", info.getStatus()); | ||
| } | ||
|
|
||
| @Test | ||
| public void parserReportsOffendingEntryOnMalformedJson(@TempDir Path tmp) throws Exception { | ||
| // Simulates the timeline server returning an HTML error page instead of JSON. | ||
| File zip = writeZip(tmp, "malformed.zip", | ||
| new ZipContent(DAG_ID, "<html><body>internal error</body></html>")); | ||
|
abstractdog marked this conversation as resolved.
|
||
|
|
||
| ATSFileParser parser = new ATSFileParser(Collections.singletonList(zip)); | ||
| TezException thrown = assertThrows(TezException.class, () -> parser.getDAGData(DAG_ID)); | ||
|
|
||
| Throwable cause = thrown.getCause(); | ||
| assertNotNull(cause); | ||
| String msg = cause.getMessage(); | ||
| assertNotNull(msg); | ||
| assertTrue(msg.contains(DAG_ID), "Error should name the offending zip entry, got: " + msg); | ||
| assertTrue(msg.contains("<html>"), "Error should include a snippet of the offending payload, got: " + msg); | ||
| } | ||
|
|
||
| private record ZipContent(String name, String payload) { | ||
| } | ||
|
Comment on lines
+107
to
+108
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. what is the record for?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @abstractdog |
||
| } | ||
Uh oh!
There was an error while loading. Please reload this page.