From a3d347eddd2a2ecd93b94c80998622653e968b26 Mon Sep 17 00:00:00 2001 From: Artem Bilan Date: Wed, 6 Dec 2023 12:56:07 -0500 Subject: [PATCH] Fix FileTailingMessProducerTests for tail events The `OSDelegatingFileTailingMessageProducer` publishes event from scheduled task * Modify `FileTailingMessageProducerTests.testGuts()` to use `CountDownLatch` to wait for those asynchronous events **Cherry-pick to `6.1.x`** --- .../file/tail/FileTailingMessageProducerTests.java | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/spring-integration-file/src/test/java/org/springframework/integration/file/tail/FileTailingMessageProducerTests.java b/spring-integration-file/src/test/java/org/springframework/integration/file/tail/FileTailingMessageProducerTests.java index 739ee4faf2..025a3cb770 100644 --- a/spring-integration-file/src/test/java/org/springframework/integration/file/tail/FileTailingMessageProducerTests.java +++ b/spring-integration-file/src/test/java/org/springframework/integration/file/tail/FileTailingMessageProducerTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2022 the original author or authors. + * Copyright 2002-2023 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -188,17 +188,15 @@ public class FileTailingMessageProducerTests { file.delete(); } - private void testGuts(FileTailingMessageProducerSupport adapter, String field) - throws Exception { + private void testGuts(FileTailingMessageProducerSupport adapter, String field) throws Exception { this.adapter = adapter; ThreadPoolTaskScheduler taskScheduler = new ThreadPoolTaskScheduler(); taskScheduler.afterPropertiesSet(); adapter.setTaskScheduler(taskScheduler); - final List events = new ArrayList<>(); + CountDownLatch tailEventLatch = new CountDownLatch(1); adapter.setApplicationEventPublisher(event -> { - FileTailingEvent tailEvent = (FileTailingEvent) event; logger.debug(event); - events.add(tailEvent); + tailEventLatch.countDown(); }); adapter.setFile(new File(testDir, "foo")); QueueChannel outputChannel = new QueueChannel(); @@ -242,7 +240,7 @@ public class FileTailingMessageProducerTests { assertThat(message.getHeaders().get(FileHeaders.FILENAME)).isEqualTo(file.getName()); } - assertThat(events.size()).isGreaterThanOrEqualTo(1); + assertThat(tailEventLatch.await(20, TimeUnit.SECONDS)).isTrue(); taskScheduler.destroy(); }