From a3c8b0abbd4decf13041bd7b05f3b9394ae2e628 Mon Sep 17 00:00:00 2001 From: Artem Bilan Date: Mon, 12 Dec 2016 09:48:11 -0500 Subject: [PATCH] Fix LastModifiedFileListFilterTests timing issue https://build.spring.io/browse/INT-AT42SIO-365/ * Fix timing issue with the `LastModifiedFileListFilterTests`, when the `age = 1` might not be enough for the file object when we have some delay before checking * Get rid of any `Thread.sleep()` in the test via mocking age on the file. Cherry-picked from the https://github.com/spring-projects/spring-integration/commit/4ac3a79df7356aad47147edad7b9581febffe1c4 --- .../file/filters/LastModifiedFileListFilterTests.java | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/spring-integration-file/src/test/java/org/springframework/integration/file/filters/LastModifiedFileListFilterTests.java b/spring-integration-file/src/test/java/org/springframework/integration/file/filters/LastModifiedFileListFilterTests.java index d56746a9a7..97d3fda490 100644 --- a/spring-integration-file/src/test/java/org/springframework/integration/file/filters/LastModifiedFileListFilterTests.java +++ b/spring-integration-file/src/test/java/org/springframework/integration/file/filters/LastModifiedFileListFilterTests.java @@ -13,6 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package org.springframework.integration.file.filters; import static org.junit.Assert.assertEquals; @@ -27,6 +28,7 @@ import org.junit.rules.TemporaryFolder; /** * @author Gary Russell + * @author Artem Bilan * @since 4.2 * */ @@ -38,14 +40,14 @@ public class LastModifiedFileListFilterTests { @Test public void testAge() throws Exception { LastModifiedFileListFilter filter = new LastModifiedFileListFilter(); - filter.setAge(10, TimeUnit.SECONDS); + filter.setAge(60, TimeUnit.SECONDS); File foo = this.folder.newFile(); FileOutputStream fileOutputStream = new FileOutputStream(foo); fileOutputStream.write("x".getBytes()); fileOutputStream.close(); assertEquals(0, filter.filterFiles(new File[] { foo }).size()); - filter.setAge(50, TimeUnit.MILLISECONDS); - Thread.sleep(100); + // Make a file as of yesterday's + foo.setLastModified(System.currentTimeMillis() - 1000 * 60 * 60 * 24); assertEquals(1, filter.filterFiles(new File[] { foo }).size()); }