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

    https://github.com/apache/spark/pull/20767#discussion_r173332248
  
    --- Diff: 
external/kafka-0-10-sql/src/test/scala/org/apache/spark/sql/kafka010/KafkaDataConsumerSuite.scala
 ---
    @@ -0,0 +1,111 @@
    +/*
    + * Licensed to the Apache Software Foundation (ASF) under one or more
    + * contributor license agreements.  See the NOTICE file distributed with
    + * this work for additional information regarding copyright ownership.
    + * The ASF licenses this file to You under the Apache License, Version 2.0
    + * (the "License"); you may not use this file except in compliance with
    + * the License.  You may obtain a copy of the License at
    + *
    + *    http://www.apache.org/licenses/LICENSE-2.0
    + *
    + * Unless required by applicable law or agreed to in writing, software
    + * distributed under the License is distributed on an "AS IS" BASIS,
    + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    + * See the License for the specific language governing permissions and
    + * limitations under the License.
    + */
    +
    +package org.apache.spark.sql.kafka010
    +
    +import java.util.concurrent.{Executors, TimeUnit}
    +
    +import scala.collection.JavaConverters._
    +import scala.concurrent.{ExecutionContext, Future}
    +import scala.concurrent.duration.Duration
    +import scala.util.Random
    +
    +import org.apache.kafka.clients.consumer.ConsumerConfig
    +import org.apache.kafka.common.TopicPartition
    +import org.apache.kafka.common.serialization.ByteArrayDeserializer
    +import org.scalatest.PrivateMethodTester
    +
    +import org.apache.spark.sql.test.SharedSQLContext
    +import org.apache.spark.util.ThreadUtils
    +
    +class KafkaDataConsumerSuite extends SharedSQLContext with 
PrivateMethodTester {
    +
    +  protected var testUtils: KafkaTestUtils = _
    +
    +  override def beforeAll(): Unit = {
    +    super.beforeAll()
    +    testUtils = new KafkaTestUtils(Map[String, Object]())
    +    testUtils.setup()
    +  }
    +
    +  override def afterAll(): Unit = {
    +    if (testUtils != null) {
    +      testUtils.teardown()
    +      testUtils = null
    +    }
    +    super.afterAll()
    +  }
    +
    +  test("SPARK-19886: Report error cause correctly in reportDataLoss") {
    +    val cause = new Exception("D'oh!")
    +    val reportDataLoss = PrivateMethod[Unit]('reportDataLoss0)
    +    val e = intercept[IllegalStateException] {
    +      InternalKafkaConsumer.invokePrivate(reportDataLoss(true, "message", 
cause))
    +    }
    +    assert(e.getCause === cause)
    +  }
    +
    +  test("concurrent use of KafkaDataConsumer") {
    +    val topic = "topic" + Random.nextInt()
    +    testUtils.createTopic(topic, 1)
    +    testUtils.sendMessages(topic, (1 to 1000).map(_.toString).toArray)
    +    val topicPartition = new TopicPartition(topic, 0)
    +
    +    import ConsumerConfig._
    +    val kafkaParams = Map[String, Object](
    +      GROUP_ID_CONFIG -> "groupId",
    +      BOOTSTRAP_SERVERS_CONFIG -> testUtils.brokerAddress,
    +      KEY_DESERIALIZER_CLASS_CONFIG -> 
classOf[ByteArrayDeserializer].getName,
    +      VALUE_DESERIALIZER_CLASS_CONFIG -> 
classOf[ByteArrayDeserializer].getName,
    +      AUTO_OFFSET_RESET_CONFIG -> "earliest",
    +      ENABLE_AUTO_COMMIT_CONFIG -> "false"
    +    )
    +
    +    val numThreads = 50
    +    val numConsumerUsages = 500
    +
    +    val threadpool = Executors.newFixedThreadPool(numThreads)
    --- End diff --
    
    nit: threadpool should be shut down


---

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

Reply via email to