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

    https://github.com/apache/spark/pull/16857#discussion_r101360629
  
    --- 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)
    +      }
    +    }
    +  }
    +
    +  testWithUninterruptibleThread("deserialization of initial offsets 
written by Spark 2.1.0") {
    --- End diff --
    
    Could you use Spark 2.1.0 to generate a real file and put it in the 
`external/kafka-0-10-sql/src/test/resources/` folder (there is already a file 
called kafka-source-offset-version-2.1.0.txt in it)? Using a real file to write 
the test so that if we change the APIs of HDFSMetadataLog and KafkaSourceOffset 
in future, we can still generate the correct file format.


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