Github user andrewor14 commented on a diff in the pull request: https://github.com/apache/spark/pull/11241#discussion_r55739701 --- Diff: core/src/test/scala/org/apache/spark/storage/BlockManagerSuite.scala --- @@ -1331,6 +1335,74 @@ 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)") { + store = makeBlockManager(8000, "executor1") + val mockBlockTransferService = + new MockBlockTransferService(store.maxFailuresBeforeLocationRefresh) + + 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]) + store = makeBlockManager(8000, "executor1", mockBlockManagerMaster) + val mockBlockTransferService = + new MockBlockTransferService(store.maxFailuresBeforeLocationRefresh) + + // make sure we have more than maxFailuresBeforeLocationRefresh locations + // so that we have a chance to do location refresh + val blockManagerIds = (0 to store.maxFailuresBeforeLocationRefresh) + .map { i => BlockManagerId(s"id-$i", s"host-$i", i + 1) } + + when(mockBlockManagerMaster.getLocations(mc.any[BlockId])).thenReturn(blockManagerIds) + + 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 = { --- End diff -- style: ``` override def fetchBlocks( host: String, port: Int, ..., listener: BlockFetchingListener): Unit ```
--- 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 infrastruct...@apache.org or file a JIRA ticket with INFRA. --- --------------------------------------------------------------------- To unsubscribe, e-mail: reviews-unsubscr...@spark.apache.org For additional commands, e-mail: reviews-h...@spark.apache.org