kafka流测试不正确关闭

h7wcgrx3  于 2021-06-06  发布在  Kafka
关注(0)|答案(1)|浏览(312)

我有两个单元测试
当我运行它们时,我有下面的错误
1) 试验

@Test
    public void simpleInsertAndOutputEventPrint() throws IOException, URISyntaxException {

        GenericRecord record = getInitialEvent();

        testDriver.pipeInput(recordFactory.create(record));
        GenericRecord result =  testDriver.readOutput(detailsEventTopic, stringDeserializer, genericAvroSerde.deserializer()).value();

        Assert.assertEquals(1,result.get("tt"));

    }

2) 试验

@Test
  public void stateStoreSimpleInsertOutputPrint()  {
       GenericRecord record = getInitialAvayaEvent();
       testDriver.pipeInput(recordFactory.create(record));
      Packet packet1 = (Packet)  store.get("dddfdfdf");
      Assert.assertEquals("ddd",packet1.getc1()); 
  }

方法初始化

@Before
    public void setUp() throws IOException, RestClientException, URISyntaxException {

       ...

        recordFactory = new ConsumerRecordFactory<>(initialSourceTopic,new StringSerializer(),  genericAvroSerde.serializer());
        testDriver = new TopologyTestDriver(topology, props);
        this.store = testDriver.getKeyValueStore(db);

    }

当我尝试添加下一个代码时:

@After
    public void tearDown() {
        testDriver.close(); // Close processors after finish the tests
    }

下一个错误是:

[2018-09-25 22:45:38,178] ERROR stream-thread [main] Failed to delete the state directory. (org.apache.kafka.streams.processor.internals.StateDirectory)
java.nio.file.DirectoryNotEmptyException: \tmp\kafka-streams\ks-stock-analysis-appid\0_0
    at sun.nio.fs.WindowsFileSystemProvider.implDelete(WindowsFileSystemProvider.java:266)
    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.postVisitDirectory(Utils.java:740)
    at org.apache.kafka.common.utils.Utils$2.postVisitDirectory(Utils.java:723)
    at java.nio.file.Files.walkFileTree(Files.java:2688)
    at java.nio.file.Files.walkFileTree(Files.java:2742)
    at org.apache.kafka.common.utils.Utils.delete(Utils.java:723)
    at org.apache.kafka.streams.processor.internals.StateDirectory.cleanRemovedTasks(StateDirectory.java:287)
    at org.apache.kafka.streams.processor.internals.StateDirectory.clean(StateDirectory.java:228)
    at org.apache.kafka.streams.TopologyTestDriver.close(TopologyTestDriver.java:679)
    at com.dvsts.avaya.processing.topology.TopologyKafkaStreamTest.tearDown(TopologyKafkaStreamTest.java:235)
nzrxty8p

nzrxty8p1#

对于测试,可以使用 IN_MEMORY("in-memory") 为每个存储 KTable 创建(直接或间接,如聚合);这样可以避免创建任何目录,从而不再发生错误。

相关问题