Skip to content

Commit 90f5dde

Browse files
committed
Add a unit test
1 parent d8c9cd0 commit 90f5dde

File tree

1 file changed

+30
-13
lines changed

1 file changed

+30
-13
lines changed

core/src/test/scala/org/apache/spark/deploy/history/FsHistoryProviderSuite.scala

Lines changed: 30 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -67,29 +67,33 @@ class FsHistoryProviderSuite extends SparkFunSuite with BeforeAndAfter with Matc
6767
// Write a new-style application log.
6868
val newAppComplete = newLogFile("new1", None, inProgress = false)
6969
writeFile(newAppComplete, true, None,
70-
SparkListenerApplicationStart("new-app-complete", None, 1L, "test", None),
70+
SparkListenerApplicationStart(
71+
"new-app-complete", Some("new-app-complete"), 1L, "test", None),
7172
SparkListenerApplicationEnd(5L)
7273
)
7374

7475
// Write a new-style application log.
7576
val newAppCompressedComplete = newLogFile("new1compressed", None, inProgress = false,
7677
Some("lzf"))
7778
writeFile(newAppCompressedComplete, true, None,
78-
SparkListenerApplicationStart("new-app-compressed-complete", None, 1L, "test", None),
79+
SparkListenerApplicationStart(
80+
"new-app-compressed-complete", Some("new-app-compressed-complete"), 1L, "test", None),
7981
SparkListenerApplicationEnd(4L))
8082

8183
// Write an unfinished app, new-style.
8284
val newAppIncomplete = newLogFile("new2", None, inProgress = true)
8385
writeFile(newAppIncomplete, true, None,
84-
SparkListenerApplicationStart("new-app-incomplete", None, 1L, "test", None)
86+
SparkListenerApplicationStart(
87+
"new-app-incomplete", Some("new-app-incomplete"), 1L, "test", None)
8588
)
8689

8790
// Write an old-style application log.
8891
val oldAppComplete = new File(testDir, "old1")
8992
oldAppComplete.mkdir()
9093
createEmptyFile(new File(oldAppComplete, provider.SPARK_VERSION_PREFIX + "1.0"))
9194
writeFile(new File(oldAppComplete, provider.LOG_PREFIX + "1"), false, None,
92-
SparkListenerApplicationStart("old-app-complete", None, 2L, "test", None),
95+
SparkListenerApplicationStart(
96+
"old-app-complete", Some("old-app-complete"), 2L, "test", None),
9397
SparkListenerApplicationEnd(3L)
9498
)
9599
createEmptyFile(new File(oldAppComplete, provider.APPLICATION_COMPLETE))
@@ -103,7 +107,8 @@ class FsHistoryProviderSuite extends SparkFunSuite with BeforeAndAfter with Matc
103107
oldAppIncomplete.mkdir()
104108
createEmptyFile(new File(oldAppIncomplete, provider.SPARK_VERSION_PREFIX + "1.0"))
105109
writeFile(new File(oldAppIncomplete, provider.LOG_PREFIX + "1"), false, None,
106-
SparkListenerApplicationStart("old-app-incomplete", None, 2L, "test", None)
110+
SparkListenerApplicationStart(
111+
"old-app-incomplete", Some("old-app-incomplete"), 2L, "test", None)
107112
)
108113

109114
// Force a reload of data from the log directory, and check that both logs are loaded.
@@ -124,16 +129,16 @@ class FsHistoryProviderSuite extends SparkFunSuite with BeforeAndAfter with Matc
124129
List(ApplicationAttemptInfo(None, start, end, lastMod, user, completed)))
125130
}
126131

127-
list(0) should be (makeAppInfo(newAppComplete.getName(), "new-app-complete", 1L, 5L,
132+
list(0) should be (makeAppInfo("new-app-complete", "new-app-complete", 1L, 5L,
128133
newAppComplete.lastModified(), "test", true))
129-
list(1) should be (makeAppInfo(newAppCompressedComplete.getName(),
134+
list(1) should be (makeAppInfo("new-app-compressed-complete",
130135
"new-app-compressed-complete", 1L, 4L, newAppCompressedComplete.lastModified(), "test",
131136
true))
132-
list(2) should be (makeAppInfo(oldAppComplete.getName(), "old-app-complete", 2L, 3L,
137+
list(2) should be (makeAppInfo("old-app-complete", "old-app-complete", 2L, 3L,
133138
oldAppComplete.lastModified(), "test", true))
134-
list(3) should be (makeAppInfo(oldAppIncomplete.getName(), "old-app-incomplete", 2L, -1L,
139+
list(3) should be (makeAppInfo("old-app-incomplete", "old-app-incomplete", 2L, -1L,
135140
oldAppIncomplete.lastModified(), "test", false))
136-
list(4) should be (makeAppInfo(newAppIncomplete.getName(), "new-app-incomplete", 1L, -1L,
141+
list(4) should be (makeAppInfo("new-app-incomplete", "new-app-incomplete", 1L, -1L,
137142
newAppIncomplete.lastModified(), "test", false))
138143

139144
// Make sure the UI can be rendered.
@@ -157,7 +162,7 @@ class FsHistoryProviderSuite extends SparkFunSuite with BeforeAndAfter with Matc
157162
logDir.mkdir()
158163
createEmptyFile(new File(logDir, provider.SPARK_VERSION_PREFIX + "1.0"))
159164
writeFile(new File(logDir, provider.LOG_PREFIX + "1"), false, Option(codec),
160-
SparkListenerApplicationStart("app2", None, 2L, "test", None),
165+
SparkListenerApplicationStart("app2", Some("app2"), 2L, "test", None),
161166
SparkListenerApplicationEnd(3L)
162167
)
163168
createEmptyFile(new File(logDir, provider.COMPRESSION_CODEC_PREFIX + codecName))
@@ -180,12 +185,12 @@ class FsHistoryProviderSuite extends SparkFunSuite with BeforeAndAfter with Matc
180185
test("SPARK-3697: ignore directories that cannot be read.") {
181186
val logFile1 = newLogFile("new1", None, inProgress = false)
182187
writeFile(logFile1, true, None,
183-
SparkListenerApplicationStart("app1-1", None, 1L, "test", None),
188+
SparkListenerApplicationStart("app1-1", Some("app1-1"), 1L, "test", None),
184189
SparkListenerApplicationEnd(2L)
185190
)
186191
val logFile2 = newLogFile("new2", None, inProgress = false)
187192
writeFile(logFile2, true, None,
188-
SparkListenerApplicationStart("app1-2", None, 1L, "test", None),
193+
SparkListenerApplicationStart("app1-2", Some("app1-2"), 1L, "test", None),
189194
SparkListenerApplicationEnd(2L)
190195
)
191196
logFile2.setReadable(false, false)
@@ -218,6 +223,18 @@ class FsHistoryProviderSuite extends SparkFunSuite with BeforeAndAfter with Matc
218223
}
219224
}
220225

226+
test("Parse logs that application is not started") {
227+
val provider = new FsHistoryProvider((createTestConf()))
228+
229+
val logFile1 = newLogFile("app1", None, inProgress = true)
230+
writeFile(logFile1, true, None,
231+
SparkListenerLogStart("1.4")
232+
)
233+
updateAndCheck(provider) { list =>
234+
list.size should be (0)
235+
}
236+
}
237+
221238
test("SPARK-5582: empty log directory") {
222239
val provider = new FsHistoryProvider(createTestConf())
223240

0 commit comments

Comments
 (0)