spark-reviews mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From zsxwing <...@git.apache.org>
Subject [GitHub] spark pull request #16857: [SPARK-19517][SS] KafkaSource fails to initialize...
Date Wed, 15 Feb 2017 19:44:15 GMT
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 infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


Mime
View raw message