Github user squito commented on a diff in the pull request:

    https://github.com/apache/spark/pull/11241#discussion_r55603252
  
    --- Diff: 
core/src/test/scala/org/apache/spark/storage/BlockManagerSuite.scala ---
    @@ -1331,6 +1336,72 @@ class BlockManagerSuite extends SparkFunSuite with 
Matchers with BeforeAndAfterE
         assert(store.getSingle("a1").isDefined, "a1 was not in store")
         assert(store.getSingle("a3").isDefined, "a3 was not in store")
       }
    +
    +  test("SPARK-13328: refresh block locations (fetch should fail after 
hitting a threshold)") {
    +    val mockBlockTransferService = new 
MockBlockTransferService(maxFailuresBeforeLocationRefresh)
    +    store = makeBlockManager(8000, "executor1")
    +
    +    store.putSingle("item", 999L, StorageLevel.MEMORY_ONLY, tellMaster = 
true)
    +
    +    intercept[BlockFetchException] {
    +      store.doGetRemote("item", mockBlockTransferService, asBlockResult = 
false)
    +      .asInstanceOf[Option[ByteBuffer]]
    +    }
    +  }
    +
    +  test("SPARK-13328: refresh block locations (fetch should succeed after 
location refresh)") {
    +    val mockBlockManagerMaster = mock(classOf[BlockManagerMaster])
    +    val mockBlockTransferService = new 
MockBlockTransferService(maxFailuresBeforeLocationRefresh)
    +
    +    // make sure we have more than maxFailuresBeforeLocationRefresh 
locations
    +    // so that we have a chance to do location refresh
    +    val blockManagerIds = new ArrayBuffer[BlockManagerId]()
    +    for (i <- 0 to maxFailuresBeforeLocationRefresh) {
    +      blockManagerIds += BlockManagerId(s"id-$i", s"host-$i", i + 1)
    +    }
    +
    +    
when(mockBlockManagerMaster.getLocations(mc.any[BlockId])).thenReturn(blockManagerIds.toSeq)
    +
    +    store = makeBlockManager(8000, "executor1", mockBlockManagerMaster)
    +
    +    val block = store.doGetRemote("item", mockBlockTransferService, 
asBlockResult = false)
    +      .asInstanceOf[Option[ByteBuffer]]
    +    assert(block.isDefined)
    +    verify(mockBlockManagerMaster, times(2)).getLocations("item")
    +  }
    +
    +  class MockBlockTransferService(val maxFailures: Int) extends 
BlockTransferService {
    +    var numCalls = 0
    +
    +    override def init(blockDataManager: BlockDataManager): Unit = {}
    +
    +    override def fetchBlocks(host: String, port: Int, execId: String, 
blockIds: Array[String],
    +                             listener: BlockFetchingListener): Unit = {
    +      listener.onBlockFetchSuccess("mockBlockId", new 
NioManagedBuffer(ByteBuffer.allocate(1)))
    +    }
    +
    +    override def close(): Unit = {}
    +
    +    override def hostName: String = { "MockBlockTransferService::host" }
    +
    +    override def port: Int = { -1 }
    +
    +    override def uploadBlock(hostname: String, port: Int, execId: String,
    +                             blockId: BlockId, blockData: ManagedBuffer,
    +                             level: StorageLevel): Future[Unit] = {
    +      import scala.concurrent.ExecutionContext.Implicits.global
    +      Future {}
    +    }
    +
    +    override def  fetchBlockSync(host: String, port: Int,
    +                                 execId: String, blockId: String): 
ManagedBuffer = {
    +      numCalls += 1
    +      if (numCalls <= maxFailures) {
    +        throw new RuntimeException("Failing block fetch in the moch block 
transfer service")
    --- End diff --
    
    typo: mock


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at [email protected] or file a JIRA ticket
with INFRA.
---

---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to