@@ -63,6 +63,9 @@ class BlockManagerSuite extends FunSuite with Matchers with BeforeAndAfter
6363 val securityMgr = new SecurityManager (conf)
6464 val mapOutputTracker = new MapOutputTrackerMaster (conf)
6565 val shuffleManager = new HashShuffleManager (conf)
66+
67+ // List of block manager created during an unit test, so that all of the them can be stopped
68+ // after the unit test.
6669 val allStores = new ArrayBuffer [BlockManager ]
6770
6871 // Reuse a serializer across tests to avoid creating a new thread-local buffer on each test
@@ -1241,7 +1244,7 @@ class BlockManagerSuite extends FunSuite with Matchers with BeforeAndAfter
12411244 assert(unrollMemoryAfterB7 === unrollMemoryAfterB4)
12421245 }
12431246
1244- test(" get peers with store addition and removal" ) {
1247+ test(" get peers with addition and removal of block managers " ) {
12451248 val numStores = 4
12461249 val stores = (1 to numStores - 1 ).map { i => makeBlockManager(1000 , s " store $i" ) }
12471250 val storeIds = stores.map { _.blockManagerId }.toSet
@@ -1313,11 +1316,17 @@ class BlockManagerSuite extends FunSuite with Matchers with BeforeAndAfter
13131316 testReplication(5 , storageLevels)
13141317 }
13151318
1316- test(" block replication with addition and deletion of executors " ) {
1319+ test(" block replication with addition and deletion of block managers " ) {
13171320 val blockSize = 1000
13181321 val storeSize = 10000
13191322 val initialStores = (1 to 2 ).map { i => makeBlockManager(storeSize, s " store $i" ) }
13201323
1324+ /**
1325+ * Function to test whether insert a block with replication achieves the expected replication.
1326+ * Since this function can be call on the same block id repeatedly through an `eventually`,
1327+ * it needs to be ensured that the method leaves block manager + master in the same state as
1328+ * it was before attempting to insert the block.
1329+ */
13211330 def testPut (blockId : String , storageLevel : StorageLevel , expectedNumLocations : Int ) {
13221331 try {
13231332 initialStores(0 ).putSingle(blockId, new Array [Byte ](blockSize), storageLevel)
@@ -1345,7 +1354,7 @@ class BlockManagerSuite extends FunSuite with Matchers with BeforeAndAfter
13451354 }
13461355
13471356 // Remove all but the 1st store, 2x replication should fail
1348- (initialStores.slice( 1 , initialStores.size) ++ Seq (newStore1, newStore2)).foreach {
1357+ (initialStores.tail ++ Seq (newStore1, newStore2)).foreach {
13491358 store =>
13501359 master.removeExecutor(store.blockManagerId.executorId)
13511360 store.stop()
@@ -1394,57 +1403,57 @@ class BlockManagerSuite extends FunSuite with Matchers with BeforeAndAfter
13941403 s " master did not have ${storageLevel.replication} locations for $blockId" )
13951404
13961405 // Test state of the stores that contain the block
1397- stores.filter( testStore => blockLocations.contains(testStore.blockManagerId.executorId))
1406+ stores.filter { testStore => blockLocations.contains(testStore.blockManagerId.executorId) }
13981407 .foreach { testStore =>
1399- val testStoreName = testStore.blockManagerId.executorId
1400- assert(testStore.getLocal(blockId).isDefined, s " $blockId was not found in $testStoreName" )
1401- assert(master.getLocations(blockId).map(_.executorId).toSet.contains(testStoreName),
1402- s " master does not have status for ${blockId.name} in $testStoreName" )
1403-
1404- val blockStatus = master.getBlockStatus(blockId)(testStore.blockManagerId)
1405-
1406- // Assert that block status in the master for this store has expected storage level
1407- assert(
1408- blockStatus.storageLevel.useDisk === storageLevel.useDisk &&
1409- blockStatus.storageLevel.useMemory === storageLevel.useMemory &&
1410- blockStatus.storageLevel.useOffHeap === storageLevel.useOffHeap &&
1411- blockStatus.storageLevel.deserialized === storageLevel.deserialized,
1412- s " master does not know correct storage level for ${blockId.name} in $testStoreName" )
1413-
1414- // Assert that the block status in the master for this store has correct memory usage info
1415- assert(! blockStatus.storageLevel.useMemory || blockStatus.memSize >= blockSize,
1416- s " master does not know size of ${blockId.name} stored in memory of $testStoreName" )
1417-
1418-
1419- // If the block is supposed to be in memory, then drop the copy of the block in
1420- // this store test whether master is updated with zero memory usage this store
1421- if (storageLevel.useMemory) {
1422- // Force the block to be dropped by adding a number of dummy blocks
1423- (1 to 10 ).foreach { i =>
1424- testStore.putSingle(s " dummy-block- $i" , new Array [Byte ](1000 ), MEMORY_ONLY_SER )
1425- }
1426- (1 to 10 ).foreach { i => testStore.removeBlock(s " dummy-block- $i" ) }
1408+ val testStoreName = testStore.blockManagerId.executorId
1409+ assert(testStore.getLocal(blockId).isDefined, s " $blockId was not found in $testStoreName" )
1410+ assert(master.getLocations(blockId).map(_.executorId).toSet.contains(testStoreName),
1411+ s " master does not have status for ${blockId.name} in $testStoreName" )
14271412
1428- val newBlockStatusOption = master.getBlockStatus(blockId).get (testStore.blockManagerId)
1413+ val blockStatus = master.getBlockStatus(blockId)(testStore.blockManagerId)
14291414
1430- // Assert that the block status in the master either does not exist (block removed
1431- // from every store) or has zero memory usage for this store
1415+ // Assert that block status in the master for this store has expected storage level
14321416 assert(
1433- newBlockStatusOption.isEmpty || newBlockStatusOption.get.memSize === 0 ,
1434- s " after dropping, master does not know size of ${blockId.name} " +
1435- s " stored in memory of $testStoreName"
1436- )
1437- }
1417+ blockStatus.storageLevel.useDisk === storageLevel.useDisk &&
1418+ blockStatus.storageLevel.useMemory === storageLevel.useMemory &&
1419+ blockStatus.storageLevel.useOffHeap === storageLevel.useOffHeap &&
1420+ blockStatus.storageLevel.deserialized === storageLevel.deserialized,
1421+ s " master does not know correct storage level for ${blockId.name} in $testStoreName" )
1422+
1423+ // Assert that the block status in the master for this store has correct memory usage info
1424+ assert(! blockStatus.storageLevel.useMemory || blockStatus.memSize >= blockSize,
1425+ s " master does not know size of ${blockId.name} stored in memory of $testStoreName" )
1426+
1427+
1428+ // If the block is supposed to be in memory, then drop the copy of the block in
1429+ // this store test whether master is updated with zero memory usage this store
1430+ if (storageLevel.useMemory) {
1431+ // Force the block to be dropped by adding a number of dummy blocks
1432+ (1 to 10 ).foreach { i =>
1433+ testStore.putSingle(s " dummy-block- $i" , new Array [Byte ](1000 ), MEMORY_ONLY_SER )
1434+ }
1435+ (1 to 10 ).foreach { i => testStore.removeBlock(s " dummy-block- $i" ) }
1436+
1437+ val newBlockStatusOption = master.getBlockStatus(blockId).get(testStore.blockManagerId)
1438+
1439+ // Assert that the block status in the master either does not exist (block removed
1440+ // from every store) or has zero memory usage for this store
1441+ assert(
1442+ newBlockStatusOption.isEmpty || newBlockStatusOption.get.memSize === 0 ,
1443+ s " after dropping, master does not know size of ${blockId.name} " +
1444+ s " stored in memory of $testStoreName"
1445+ )
1446+ }
14381447
1439- // If the block is supposed to be in disk (after dropping or otherwise, then
1440- // test whether master has correct disk usage for this store
1441- if (storageLevel.useDisk) {
1442- assert(master.getBlockStatus(blockId)(testStore.blockManagerId).diskSize >= blockSize,
1443- s " after dropping, master does not know size of ${blockId.name} " +
1444- s " stored in disk of $testStoreName"
1445- )
1448+ // If the block is supposed to be in disk (after dropping or otherwise, then
1449+ // test whether master has correct disk usage for this store
1450+ if (storageLevel.useDisk) {
1451+ assert(master.getBlockStatus(blockId)(testStore.blockManagerId).diskSize >= blockSize,
1452+ s " after dropping, master does not know size of ${blockId.name} " +
1453+ s " stored in disk of $testStoreName"
1454+ )
1455+ }
14461456 }
1447- }
14481457 master.removeBlock(blockId)
14491458 }
14501459 }
0 commit comments