我正在尝试使用
EmbeddedKafkaCluster来自Kafka的集成测试实用程序库。与Integration Test示例Integration Test examples here类似。
但是我打java.nio.file.FileSystemException
:
java.lang.RuntimeException: java.nio.file.FileSystemException: C:\Users\AppData\Local\Temp\junit3544952207288614104\junit965058698809817752\inputTopic-0\00000000000000000000.timeindex: The process cannot access the file because it is being used by another process.
at org.apache.kafka.streams.integration.utils.KafkaEmbedded.stop(KafkaEmbedded.java:138)
at org.apache.kafka.streams.integration.utils.EmbeddedKafkaCluster.stop(EmbeddedKafkaCluster.java:119)
at org.apache.kafka.streams.integration.utils.EmbeddedKafkaCluster.after(EmbeddedKafkaCluster.java:150)
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:363)
at org.junit.runner.JUnitCore.run(JUnitCore.java:137)
at com.intellij.junit4.JUnit4IdeaTestRunner.startRunnerWithArgs(JUnit4IdeaTestRunner.java:68)
at com.intellij.rt.execution.junit.IdeaTestRunner$Repeater.startRunnerWithArgs(IdeaTestRunner.java:51)
at com.intellij.rt.execution.junit.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java:242)
at com.intellij.rt.execution.junit.JUnitStarter.main(JUnitStarter.java:70)
Caused by: java.nio.file.FileSystemException: C:\Users\AppData\Local\Temp\junit3544952207288614104\junit965058698809817752\inputTopic-0\00000000000000000000.timeindex: 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:757)
at org.apache.kafka.common.utils.Utils$2.visitFile(Utils.java:746)
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:746)
at org.apache.kafka.streams.integration.utils.KafkaEmbedded.stop(KafkaEmbedded.java:136)
... 10 more
删除文件并重新运行是行不通的-无论如何每次都会创建一个新文件。
我仅使用1个代理,而这些是我的brokerConfigs:
brokerConfig.setProperty("offsets.topic.num.partitions", "1");
brokerConfig.setProperty("transaction.state.log.num.partitions", "1");
我的代码与前面提到的example非常相似。除了使用
public static final EmbeddedKafkaCluster CLUSTER = new EmbeddedKafkaCluster(1, brokerConfig);
代替
public static final EmbeddedSingleNodeKafkaCluster CLUSTER = new EmbeddedSingleNodeKafkaCluster();