@@ -30,62 +30,62 @@ class StreamingJobProgressListenerSuite extends TestSuiteBase with Matchers {
3030
3131 override def batchDuration = Milliseconds (100 )
3232
33- test(" onBatchSubmitted" ) {
33+ test(" onBatchSubmitted, onBatchStarted, onBatchCompleted, " +
34+ " onReceiverStarted, onReceiverError, onReceiverStopped" ) {
3435 val ssc = setupStreams(input, operation)
3536 val listener = new StreamingJobProgressListener (ssc)
3637
37- val batchInfoSubmitted = BatchInfo (Time (1000 ), Map (), 1000 , None , None )
38- listener.onBatchSubmitted(StreamingListenerBatchSubmitted (batchInfoSubmitted))
39-
40- listener.waitingBatches should be(List (batchInfoSubmitted))
41- }
42-
43- test(" onBatchStarted" ) {
44- val ssc = setupStreams(input, operation)
45- val listener = new StreamingJobProgressListener (ssc)
46-
47- val batchInfoSubmitted = BatchInfo (Time (1000 ), Map (), 1000 , None , None )
48- listener.onBatchSubmitted(StreamingListenerBatchSubmitted (batchInfoSubmitted))
49-
5038 val receivedBlockInfo = Map (
5139 0 -> Array (ReceivedBlockInfo (0 , 100 , null ), ReceivedBlockInfo (0 , 200 , null )),
5240 1 -> Array (ReceivedBlockInfo (1 , 300 , null ))
5341 )
54- val batchInfoStarted = BatchInfo (Time (1000 ), receivedBlockInfo, 1000 , Some (2000 ), None )
55- listener.onBatchStarted(StreamingListenerBatchStarted (batchInfoStarted))
5642
57- listener.runningBatches should be(List (batchInfoStarted))
58- listener.waitingBatches should be(Nil )
59- listener.numTotalReceivedRecords should be(600 )
60- }
61-
62- test(" onBatchCompleted" ) {
63- val ssc = setupStreams(input, operation)
64- val listener = new StreamingJobProgressListener (ssc)
65-
66- val batchInfoSubmitted = BatchInfo (Time (1000 ), Map (), 1000 , None , None )
43+ // onBatchSubmitted
44+ val batchInfoSubmitted = BatchInfo (Time (1000 ), receivedBlockInfo, 1000 , None , None )
6745 listener.onBatchSubmitted(StreamingListenerBatchSubmitted (batchInfoSubmitted))
46+ listener.waitingBatches should be(List (batchInfoSubmitted))
6847
69- val receivedBlockInfo = Map (
70- 0 -> Array (ReceivedBlockInfo (0 , 100 , null ), ReceivedBlockInfo (0 , 200 , null )),
71- 1 -> Array (ReceivedBlockInfo (1 , 300 , null ))
72- )
48+ // onBatchStarted
7349 val batchInfoStarted = BatchInfo (Time (1000 ), receivedBlockInfo, 1000 , Some (2000 ), None )
7450 listener.onBatchStarted(StreamingListenerBatchStarted (batchInfoStarted))
51+ listener.runningBatches should be(List (batchInfoStarted))
52+ listener.waitingBatches should be(Nil )
53+ listener.numTotalReceivedRecords should be(600 )
7554
55+ // onBatchCompleted
7656 val batchInfoCompleted = BatchInfo (Time (1000 ), receivedBlockInfo, 1000 , Some (2000 ), None )
7757 listener.onBatchCompleted(StreamingListenerBatchCompleted (batchInfoCompleted))
78-
7958 listener.runningBatches should be (Nil )
8059 listener.waitingBatches should be (Nil )
8160 listener.lastCompletedBatch should be (Some (batchInfoCompleted))
8261 listener.retainedCompletedBatches should be (List (batchInfoCompleted))
8362 listener.numTotalCompletedBatches should be (1 )
8463 listener.numTotalProcessedRecords should be (600 )
8564 listener.numTotalReceivedRecords should be (600 )
65+
66+ // onReceiverStarted
67+ val receiverInfoStarted = ReceiverInfo (0 , " test" , null , true , " localhost" )
68+ listener.onReceiverStarted(StreamingListenerReceiverStarted (receiverInfoStarted))
69+ listener.receiverInfo(0 ) should be (Some (receiverInfoStarted))
70+ listener.receiverInfo(1 ) should be (None )
71+
72+ // onReceiverError
73+ val receiverInfoError = ReceiverInfo (1 , " test" , null , true , " localhost" )
74+ listener.onReceiverError(StreamingListenerReceiverError (receiverInfoError))
75+ listener.receiverInfo(0 ) should be (Some (receiverInfoStarted))
76+ listener.receiverInfo(1 ) should be (Some (receiverInfoError))
77+ listener.receiverInfo(2 ) should be (None )
78+
79+ // onReceiverStopped
80+ val receiverInfoStopped = ReceiverInfo (2 , " test" , null , true , " localhost" )
81+ listener.onReceiverStopped(StreamingListenerReceiverStopped (receiverInfoStopped))
82+ listener.receiverInfo(0 ) should be (Some (receiverInfoStarted))
83+ listener.receiverInfo(1 ) should be (Some (receiverInfoError))
84+ listener.receiverInfo(2 ) should be (Some (receiverInfoStopped))
85+ listener.receiverInfo(3 ) should be (None )
8686 }
8787
88- test(" retain completed batch " ) {
88+ test(" Remove the old completed batches when exceeding the limit " ) {
8989 val ssc = setupStreams(input, operation)
9090 val limit = ssc.conf.getInt(" spark.streaming.ui.retainedBatches" , 100 )
9191 val listener = new StreamingJobProgressListener (ssc)
@@ -103,38 +103,4 @@ class StreamingJobProgressListenerSuite extends TestSuiteBase with Matchers {
103103 listener.retainedCompletedBatches.size should be (limit)
104104 listener.numTotalCompletedBatches should be(limit + 10 )
105105 }
106-
107- test(" onReceiverStarted" ) {
108- val ssc = setupStreams(input, operation)
109- val listener = new StreamingJobProgressListener (ssc)
110-
111- val receiverInfo = ReceiverInfo (0 , " test" , null , true , " localhost" )
112- listener.onReceiverStarted(StreamingListenerReceiverStarted (receiverInfo))
113-
114- listener.receiverInfo(0 ) should be (Some (receiverInfo))
115- listener.receiverInfo(1 ) should be (None )
116- }
117-
118- test(" onReceiverError" ) {
119- val ssc = setupStreams(input, operation)
120- val listener = new StreamingJobProgressListener (ssc)
121-
122- val receiverInfo = ReceiverInfo (0 , " test" , null , true , " localhost" )
123- listener.onReceiverError(StreamingListenerReceiverError (receiverInfo))
124-
125- listener.receiverInfo(0 ) should be (Some (receiverInfo))
126- listener.receiverInfo(1 ) should be (None )
127- }
128-
129- test(" onReceiverStopped" ) {
130- val ssc = setupStreams(input, operation)
131- val listener = new StreamingJobProgressListener (ssc)
132-
133- val receiverInfo = ReceiverInfo (0 , " test" , null , true , " localhost" )
134- listener.onReceiverStopped(StreamingListenerReceiverStopped (receiverInfo))
135-
136- listener.receiverInfo(0 ) should be (Some (receiverInfo))
137- listener.receiverInfo(1 ) should be (None )
138- }
139-
140106}
0 commit comments