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

    https://github.com/apache/spark/pull/6707#discussion_r32297611
  
    --- Diff: 
streaming/src/test/scala/org/apache/spark/streaming/ReceivedBlockHandlerSuite.scala
 ---
    @@ -174,6 +186,183 @@ class ReceivedBlockHandlerSuite
         }
       }
     
    +  test("BlockManagerBasedBlockHandler-MEMORY_ONLY-ByteBufferBlock - count 
messages") {
    +    storageLevel = StorageLevel.MEMORY_ONLY
    +    // Create a non-trivial (not all zeros) byte array
    +    val bytes = Array.tabulate(100)(i => i.toByte)
    +    val byteBufferBlock = ByteBuffer.wrap(bytes)
    +    withBlockManagerBasedBlockHandler { handler =>
    +      val blockStoreResult = storeBlock(handler, 
ByteBufferBlock(byteBufferBlock))
    +      // ByteBufferBlock is counted as single record
    +      assert(blockStoreResult.numRecords === Some(1))
    +    }
    +  }
    +
    +  test("WriteAheadLogBasedBlockHandler-MEMORY_ONLY-ByteBufferBlock - count 
messages") {
    +    storageLevel = StorageLevel.MEMORY_ONLY
    +    // Create a non-trivial (not all zeros) byte array
    +    val bytes = Array.tabulate(100)(i => i.toByte)
    +    val byteBufferBlock = ByteBuffer.wrap(bytes)
    +    withWriteAheadLogBasedBlockHandler { handler =>
    +      val blockStoreResult = storeBlock(handler, 
ByteBufferBlock(byteBufferBlock))
    +      // ByteBufferBlock is counted as single record
    +      assert(blockStoreResult.numRecords === Some(1))
    +    }
    +  }
    +
    +  test("BlockManagerBasedBlockHandler-MEMORY_ONLY-ArrayBufferBlock - count 
messages") {
    +    storageLevel = StorageLevel.MEMORY_ONLY
    --- End diff --
    
    I had commented on this in the previous PR. This is a lot of duplicate 
code! You can put all of this in a simple function like 
    
    ```
    def testRecordcount(isBlockManagedBasedBlockHandler: Boolean, storageLevel: 
StorageLevel, receivedBlock: ReceivedBlock, expectedNumRecords: Int) {
       if (isBlockManagedBasedBlockHandler) {
          // test received block with BlockManager based handler
       } else {
          // test received block with WAL based handler
       }
    }
    
    Then you can just use it in a loop, and turn the whole thing into just a 
couple of unit tests - one with BMBased, and another with WALBased.


---
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