From 5e463abd0c1cfd510e671c691902940c8f2ddc59 Mon Sep 17 00:00:00 2001 From: Will Morrison Date: Wed, 10 Jan 2024 12:08:39 -0500 Subject: [PATCH] Set file modified time explicitly --- .../ha/router/TestRoutingGroupSelector.java | 19 +++---------------- 1 file changed, 3 insertions(+), 16 deletions(-) diff --git a/gateway-ha/src/test/java/io/trino/gateway/ha/router/TestRoutingGroupSelector.java b/gateway-ha/src/test/java/io/trino/gateway/ha/router/TestRoutingGroupSelector.java index e3a054671..ae2d03851 100644 --- a/gateway-ha/src/test/java/io/trino/gateway/ha/router/TestRoutingGroupSelector.java +++ b/gateway-ha/src/test/java/io/trino/gateway/ha/router/TestRoutingGroupSelector.java @@ -19,8 +19,6 @@ import org.junit.jupiter.api.TestInstance.Lifecycle; import org.junit.jupiter.params.ParameterizedTest; import org.junit.jupiter.params.provider.MethodSource; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; import java.io.File; import java.io.FileWriter; @@ -28,8 +26,8 @@ import static io.trino.gateway.ha.router.RoutingGroupSelector.ROUTING_GROUP_HEADER; import static java.nio.charset.StandardCharsets.UTF_8; +import static org.assertj.core.api.Assertions.assertThat; import static org.junit.jupiter.api.Assertions.assertEquals; -import static org.junit.jupiter.api.Assertions.assertNotEquals; import static org.junit.jupiter.api.Assertions.assertNull; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.when; @@ -37,7 +35,6 @@ @TestInstance(Lifecycle.PER_CLASS) public class TestRoutingGroupSelector { - private static final Logger log = LoggerFactory.getLogger(TestRoutingGroupSelector.class); public static final String TRINO_SOURCE_HEADER = "X-Trino-Source"; public static final String TRINO_CLIENT_TAGS_HEADER = "X-Trino-Client-Tags"; @@ -111,7 +108,6 @@ void testByRoutingRulesEngineNoMatch(String rulesConfigPath) assertNull(routingGroupSelector.findRoutingGroup(mockRequest)); } - //Todo: The functionality of reading the file before every request needs to be smarter @Test public void testByRoutingRulesEngineFileChange() throws Exception @@ -127,9 +123,7 @@ public void testByRoutingRulesEngineFileChange() + "actions:\n" + " - \"result.put(\\\"routingGroup\\\", \\\"etl\\\")\""); fw.close(); - file.getPath(); - long etlLastModified = file.lastModified(); - log.info("etl rule file created at: " + etlLastModified); + long lastModifed = file.lastModified(); RoutingGroupSelector routingGroupSelector = RoutingGroupSelector.byRoutingRulesEngine(file.getPath()); @@ -140,11 +134,6 @@ public void testByRoutingRulesEngineFileChange() assertEquals("etl", routingGroupSelector.findRoutingGroup(mockRequest)); - Thread.sleep(1); - // java.nio.file.attribute.FileTime offers a maximum precision of 1 ms. If the first - // half of this test runs in <1ms, the gateway may not recognize that the file - // has changed. - fw = new FileWriter(file, UTF_8); fw.write( "---\n" @@ -154,9 +143,7 @@ public void testByRoutingRulesEngineFileChange() + "actions:\n" + " - \"result.put(\\\"routingGroup\\\", \\\"etl2\\\")\""); // change from etl to etl2 fw.close(); - long etl2LastModified = file.lastModified(); - log.info("etl2 rule file created at: " + etl2LastModified); - assertNotEquals(etl2LastModified, etlLastModified); + assertThat(file.setLastModified(lastModifed + 1000)).isTrue(); when(mockRequest.getHeader(TRINO_SOURCE_HEADER)).thenReturn("airflow"); assertEquals("etl2",