@@ -76,20 +76,24 @@ class BlockFetcherIteratorSuite extends FunSuite with Matchers {
76
76
77
77
iterator.initialize()
78
78
79
- // 3rd getLocalFromDisk invocation should be failed
80
- verify(blockManager, times(3 )).getLocalFromDisk(any(), any())
79
+ // Without exhausting the iterator, the iterator should be lazy and not call getLocalFromDisk.
80
+ verify(blockManager, times(0 )).getLocalFromDisk(any(), any())
81
81
82
82
assert(iterator.hasNext, " iterator should have 5 elements but actually has no elements" )
83
83
// the 2nd element of the tuple returned by iterator.next should be defined when fetching successfully
84
- assert(iterator.next._2.isDefined, " 1st element should be defined but is not actually defined" )
84
+ assert(iterator.next()._2.isDefined, " 1st element should be defined but is not actually defined" )
85
+ verify(blockManager, times(1 )).getLocalFromDisk(any(), any())
86
+
85
87
assert(iterator.hasNext, " iterator should have 5 elements but actually has 1 element" )
86
- assert(iterator.next._2.isDefined, " 2nd element should be defined but is not actually defined" )
88
+ assert(iterator.next()._2.isDefined, " 2nd element should be defined but is not actually defined" )
89
+ verify(blockManager, times(2 )).getLocalFromDisk(any(), any())
90
+
87
91
assert(iterator.hasNext, " iterator should have 5 elements but actually has 2 elements" )
88
92
// 3rd fetch should be failed
89
- assert( ! iterator.next._2.isDefined, " 3rd element should not be defined but is actually defined " )
90
- assert(iterator.hasNext, " iterator should have 5 elements but actually has 3 elements " )
91
- // Don't call next() after fetching non-defined element even if thare are rest of elements in the iterator.
92
- // Otherwise, BasicBlockFetcherIterator hangs up.
93
+ intercept[ Exception ] {
94
+ iterator.next( )
95
+ }
96
+ verify(blockManager, times( 3 )).getLocalFromDisk(any(), any())
93
97
}
94
98
95
99
@@ -127,8 +131,8 @@ class BlockFetcherIteratorSuite extends FunSuite with Matchers {
127
131
128
132
iterator.initialize()
129
133
130
- // getLocalFromDis should be invoked for all of 5 blocks
131
- verify(blockManager, times(5 )).getLocalFromDisk(any(), any())
134
+ // Without exhausting the iterator, the iterator should be lazy and not call getLocalFromDisk.
135
+ verify(blockManager, times(0 )).getLocalFromDisk(any(), any())
132
136
133
137
assert(iterator.hasNext, " iterator should have 5 elements but actually has no elements" )
134
138
assert(iterator.next._2.isDefined, " All elements should be defined but 1st element is not actually defined" )
@@ -139,7 +143,9 @@ class BlockFetcherIteratorSuite extends FunSuite with Matchers {
139
143
assert(iterator.hasNext, " iterator should have 5 elements but actually has 3 elements" )
140
144
assert(iterator.next._2.isDefined, " All elements should be defined but 4th element is not actually defined" )
141
145
assert(iterator.hasNext, " iterator should have 5 elements but actually has 4 elements" )
142
- assert(iterator.next._2.isDefined, " All elements should be defined but 5th element is not actually defined" )
146
+ assert(iterator.next._2.isDefined, " All elements should be defined but 5th element is not actually defined" )
147
+
148
+ verify(blockManager, times(5 )).getLocalFromDisk(any(), any())
143
149
}
144
150
145
151
test(" block fetch from remote fails using BasicBlockFetcherIterator" ) {
0 commit comments