Skip to content

Commit 12d3de8

Browse files
committed
Added BlockFetcherIteratorSuite.scala
1 parent 4117b8f commit 12d3de8

File tree

1 file changed

+74
-0
lines changed

1 file changed

+74
-0
lines changed
Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
/*
2+
* Licensed to the Apache Software Foundation (ASF) under one or more
3+
* contributor license agreements. See the NOTICE file distributed with
4+
* this work for additional information regarding copyright ownership.
5+
* The ASF licenses this file to You under the Apache License, Version 2.0
6+
* (the "License"); you may not use this file except in compliance with
7+
* the License. You may obtain a copy of the License at
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS,
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
*/
17+
18+
package org.apache.spark.storage
19+
20+
import org.scalatest.{FunSuite, Matchers}
21+
22+
import org.mockito.Mockito.{mock, when}
23+
import org.mockito.Matchers.any
24+
25+
import java.nio.ByteBuffer
26+
27+
import scala.concurrent.future
28+
import scala.concurrent.ExecutionContext.Implicits.global
29+
import org.apache.spark._
30+
import org.apache.spark.storage.BlockFetcherIterator._
31+
import org.apache.spark.network.{ConnectionManager, ConnectionManagerId,
32+
Message}
33+
34+
class BlockFetcherIteratorSuite extends FunSuite with Matchers {
35+
36+
test("block fetch from remote fails using BasicBlockFetcherIterator") {
37+
val conf = new SparkConf
38+
val blockManager = mock(classOf[BlockManager])
39+
val connManager = mock(classOf[ConnectionManager])
40+
val message = Message.createBufferMessage(0)
41+
message.hasError = true
42+
val someMessage = Some(message)
43+
44+
val f = future {
45+
someMessage
46+
}
47+
when(blockManager.connectionManager).thenReturn(connManager)
48+
when(connManager.sendMessageReliably(any(),
49+
any())).thenReturn(f)
50+
when(blockManager.futureExecContext).thenReturn(global)
51+
when(blockManager.blockManagerId).thenReturn(
52+
BlockManagerId("test-client", "test-client", 1, 0))
53+
when(blockManager.maxBytesInFlight).thenReturn(48 * 1024 * 1024)
54+
55+
val dummyBlId1 = ShuffleBlockId(0,0,0)
56+
val dummyBlId2 = ShuffleBlockId(0,1,0)
57+
val bmId = BlockManagerId("test-server", "test-server",1 , 0)
58+
val blocksByAddress = Seq[(BlockManagerId, Seq[(BlockId, Long)])](
59+
(bmId, Seq((dummyBlId1, 1))),
60+
(bmId, Seq((dummyBlId2, 1)))
61+
)
62+
63+
val iterator = new BasicBlockFetcherIterator(blockManager,
64+
blocksByAddress, null)
65+
66+
iterator.initialize()
67+
iterator.foreach{
68+
case (_, r) => {
69+
(!r.isDefined) should be(true)
70+
}
71+
}
72+
}
73+
74+
}

0 commit comments

Comments
 (0)