Uploaded image for project: 'Kafka'
  1. Kafka
  2. KAFKA-8427

Error while cleanup under windows for EmbeddedKafkaCluster

    XMLWordPrintableJSON

    Details

      Description

      Unable to run a simple test case for EmbeddedKafkaCluster where there is an object of  EmbeddedKafkaCluster with 1 broker.

      Running below simple code (which is actually code snippet from org.apache.kafka.streams.KafkaStreamsTest class)

      public class KTest {
          private static final int NUM_BROKERS = 1;
          // We need this to avoid the KafkaConsumer hanging on poll
          // (this may occur if the test doesn't complete quickly enough)
          @ClassRule
          public static final EmbeddedKafkaCluster CLUSTER = new EmbeddedKafkaCluster(NUM_BROKERS);
          private static final int NUM_THREADS = 2;
          private final StreamsBuilder builder = new StreamsBuilder();
          @Rule
          public TestName testName = new TestName();
          private KafkaStreams globalStreams;
          private Properties props;
      
          @Before
          public void before() {
              props = new Properties();
              props.put(StreamsConfig.APPLICATION_ID_CONFIG, "appId");
              props.put(StreamsConfig.CLIENT_ID_CONFIG, "clientId");
              props.put(StreamsConfig.BOOTSTRAP_SERVERS_CONFIG, CLUSTER.bootstrapServers());
              props.put(StreamsConfig.METRIC_REPORTER_CLASSES_CONFIG, MockMetricsReporter.class.getName());
              props.put(StreamsConfig.STATE_DIR_CONFIG, TestUtils.tempDirectory().getPath());
              props.put(StreamsConfig.NUM_STREAM_THREADS_CONFIG, NUM_THREADS);
              globalStreams = new KafkaStreams(builder.build(), props);
          }
      
          @After
          public void cleanup() {
              if (globalStreams != null) {
                  globalStreams.close();
              }
          }
      
          @Test
          public void thisIsFirstFakeTest() {
              assert true;
          }
      }
      

      But getting these error message at the time of cleanup

      java.nio.file.FileSystemException: C:\Users\Sukumaar\AppData\Local\Temp\kafka-3445189010908127083\version-2\log.1: The process cannot access the file because it is being used by another process.
      
      
      	at sun.nio.fs.WindowsException.translateToIOException(WindowsException.java:86)
      	at sun.nio.fs.WindowsException.rethrowAsIOException(WindowsException.java:97)
      	at sun.nio.fs.WindowsException.rethrowAsIOException(WindowsException.java:102)
      	at sun.nio.fs.WindowsFileSystemProvider.implDelete(WindowsFileSystemProvider.java:269)
      	at sun.nio.fs.AbstractFileSystemProvider.delete(AbstractFileSystemProvider.java:103)
      	at java.nio.file.Files.delete(Files.java:1126)
      	at org.apache.kafka.common.utils.Utils$2.visitFile(Utils.java:753)
      	at org.apache.kafka.common.utils.Utils$2.visitFile(Utils.java:742)
      	at java.nio.file.Files.walkFileTree(Files.java:2670)
      	at java.nio.file.Files.walkFileTree(Files.java:2742)
      	at org.apache.kafka.common.utils.Utils.delete(Utils.java:742)
      	at kafka.zk.EmbeddedZookeeper.shutdown(EmbeddedZookeeper.scala:65)
      	at org.apache.kafka.streams.integration.utils.EmbeddedKafkaCluster.stop(EmbeddedKafkaCluster.java:122)
      	at org.apache.kafka.streams.integration.utils.EmbeddedKafkaCluster.after(EmbeddedKafkaCluster.java:151)
      	at org.junit.rules.ExternalResource$1.evaluate(ExternalResource.java:50)
      	at org.junit.rules.RunRules.evaluate(RunRules.java:20)
      	at org.junit.runners.ParentRunner.run(ParentRunner.java:309)
      	at org.junit.runner.JUnitCore.run(JUnitCore.java:160)
      	at com.intellij.junit4.JUnit4IdeaTestRunner.startRunnerWithArgs(JUnit4IdeaTestRunner.java:68)
      	at com.intellij.rt.execution.junit.IdeaTestRunner$Repeater.startRunnerWithArgs(IdeaTestRunner.java:47)
      	at com.intellij.rt.execution.junit.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java:242)
      	at com.intellij.rt.execution.junit.JUnitStarter.main(JUnitStarter.java:70)
      
      

      One similar issue (KAFKA-6075) had been reported and marked as resolved but still getting the error while cleanup.

        Attachments

          Issue Links

            Activity

              People

              • Assignee:
                guozhang Guozhang Wang
                Reporter:
                sukumaar Sukumaar Mane
              • Votes:
                1 Vote for this issue
                Watchers:
                5 Start watching this issue

                Dates

                • Created:
                  Updated:
                  Resolved: