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

    https://github.com/apache/spark/pull/16857#discussion_r101362919
  
    --- Diff: 
external/kafka-0-10-sql/src/test/scala/org/apache/spark/sql/kafka010/KafkaSourceSuite.scala
 ---
    @@ -141,6 +142,118 @@ class KafkaSourceSuite extends KafkaSourceTest {
     
       private val topicId = new AtomicInteger(0)
     
    +  private def createSpark210MetadataLog(metadataPath: String): 
HDFSMetadataLog[KafkaSourceOffset] =
    +  {
    +    new HDFSMetadataLog[KafkaSourceOffset](sqlContext.sparkSession, 
metadataPath) {
    +      override def serialize(metadata: KafkaSourceOffset, out: 
OutputStream): Unit = {
    +        val bytes = metadata.json.getBytes(UTF_8)
    +        out.write(bytes.length)
    +        out.write(bytes)
    +      }
    +
    +      override def deserialize(in: InputStream): KafkaSourceOffset = {
    +        val length = in.read()
    +        val bytes = new Array[Byte](length)
    +        in.read(bytes)
    +        KafkaSourceOffset(SerializedOffset(new String(bytes, UTF_8)))
    +      }
    +    }
    +  }
    +
    +  testWithUninterruptibleThread(
    +    "deserialization of initial offsets compliant to new spec with Spark 
2.1.0") {
    +    withTempDir { metadataPath =>
    +      val topic = newTopic
    +      testUtils.createTopic(topic, partitions = 3)
    +
    +      // Write metadata using new spec
    +      val provider = new KafkaSourceProvider
    +      val parameters = Map(
    +        "kafka.bootstrap.servers" -> testUtils.brokerAddress,
    +        "subscribe" -> topic
    +      )
    +      val source = provider.createSource(spark.sqlContext, 
metadataPath.getAbsolutePath, None,
    +        "", parameters)
    +      source.getOffset.get // Initialize partition offsets
    +      val spark210MetadataLog = 
createSpark210MetadataLog(metadataPath.getAbsolutePath)
    +
    +      intercept[java.lang.IllegalArgumentException] {
    +        spark210MetadataLog.get(0)
    --- End diff --
    
    How about simulating the behavior of Spark 2.1.0 instead of using 
HDFSMetadataLog?
    ```Scala
          intercept[java.lang.IllegalArgumentException] {
            val in = new FileInputStream(metadataPath.getAbsolutePath + "/0")
            val length = in.read()
            val bytes = new Array[Byte](length)
            in.read(bytes)
            KafkaSourceOffset(SerializedOffset(new String(bytes, UTF_8)))
          }
    ```
    
    



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

Reply via email to