<commit_before>/*
 * Copyright 2010 LinkedIn
 *
 * Licensed 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 kafka.server

import kafka.TestUtils
import java.io.File
import kafka.utils.Utils
import kafka.message.{Message, ByteBufferMessageSet}
import kafka.api.FetchRequest
import kafka.integration.ProducerConsumerTestHarness
import kafka.producer.{SyncProducer, SyncProducerConfig}
import kafka.consumer.SimpleConsumer
import java.util.Properties
import org.scalatest.junit.JUnitSuite
import junit.framework.{Assert, TestCase}
import org.junit.{After, Before, Test}
import junit.framework.Assert._

class ServerShutdownTest extends JUnitSuite {
  val port = 9999

  @Test
  def testCleanShutdown() {
    val props = TestUtils.createBrokerConfig(0, port)
    val config = new KafkaConfig(props) {
      override val enableZookeeper = false
    }
    val host = "localhost"
    val topic = "test"
    val sent1 = new ByteBufferMessageSet(new Message("hello".getBytes()), new Message("there".getBytes()))
    val sent2 = new ByteBufferMessageSet(new Message("more".getBytes()), new Message("messages".getBytes()))

    {
      val producer = new SyncProducer(getProducerConfig(host,
                                                        port,
                                                        64*1024,
                                                        100000,
                                                        10000))
      val consumer = new SimpleConsumer(host,
                                        port,
                                        1000000,
                                        64*1024)

      val server = new KafkaServer(config)
      server.startup()

      // send some messages
      producer.send(topic, sent1)
      sent1.buffer.rewind

      // do a clean shutdown
      server.shutdown()
      val cleanShutDownFile = new File(new File(config.logDir), server.CLEAN_SHUTDOWN_FILE)
      assertTrue(cleanShutDownFile.exists)
    }


    {
      val producer = new SyncProducer(getProducerConfig(host,
                                                        port,
                                                        64*1024,
                                                        100000,
                                                        10000))<commit_msg>Adding sleep timeout after send in ServerShutdownTest<commit_after>/*
 * Copyright 2010 LinkedIn
 *
 * Licensed 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 kafka.server

import kafka.TestUtils
import java.io.File
import kafka.utils.Utils
import kafka.message.{Message, ByteBufferMessageSet}
import kafka.api.FetchRequest
import kafka.integration.ProducerConsumerTestHarness
import kafka.producer.{SyncProducer, SyncProducerConfig}
import kafka.consumer.SimpleConsumer
import java.util.Properties
import org.scalatest.junit.JUnitSuite
import junit.framework.{Assert, TestCase}
import org.junit.{After, Before, Test}
import junit.framework.Assert._

class ServerShutdownTest extends JUnitSuite {
  val port = 9999

  @Test
  def testCleanShutdown() {
    val props = TestUtils.createBrokerConfig(0, port)
    val config = new KafkaConfig(props) {
      override val enableZookeeper = false
    }

    val host = "localhost"
    val topic = "test"
    val sent1 = new ByteBufferMessageSet(new Message("hello".getBytes()), new Message("there".getBytes()))
    val sent2 = new ByteBufferMessageSet(new Message("more".getBytes()), new Message("messages".getBytes()))

    {
      val producer = new SyncProducer(getProducerConfig(host,
                                                        port,
                                                        64*1024,
                                                        100000,
                                                        10000))
      val consumer = new SimpleConsumer(host,
                                        port,
                                        1000000,
                                        64*1024)

      val server = new KafkaServer(config)
      server.startup()

      // send some messages
      producer.send(topic, sent1)
      sent1.buffer.rewind

      Thread.sleep(200)
      // do a clean shutdown
      server.shutdown()
      val cleanShutDownFile = new File(new File(config.logDir), server.CLEAN_SHUTDOWN_FILE)
      assertTrue(cleanShutDownFile.exists)
    }


    {
      val producer = new SyncProducer(getProducerConfig(host,
                                                        port,
                                                        64*1024,
                                                        100000,
                                                        10000))
{'fraction_non_alphanumeric': 0.07206733298264072, 'fraction_numerical': 0.02297036647378573, 'mean_word_length': 1.7878787878787878, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 38, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5041727', 'n_tokens_mistral': 1430, 'n_tokens_neox': 1299, 'n_words': 412}