Skip to content

Commit

Permalink
Try some dark magic to fix DevMojoIT.testThatNewResourcesAreServed
Browse files Browse the repository at this point in the history
It's perfectly stable locally, apparently also working well on Windows
on CI but consistently failing with Java 17 on CI.
  • Loading branch information
gsmet committed Nov 28, 2023
1 parent 8243d5d commit 8085100
Showing 1 changed file with 23 additions and 27 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -649,16 +649,15 @@ public void testThatTheApplicationIsReloadedMultiModule() throws MavenInvocation

// Create a new resource
source = new File(testDir, "html/src/main/resources/META-INF/resources/lorem.txt");
FileUtils.write(source,
"Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.",
"UTF-8");
Files.writeString(source.toPath(),
"Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.");
await()
.pollDelay(100, TimeUnit.MILLISECONDS)
.atMost(TestUtils.getDefaultTimeout(), TimeUnit.MINUTES)
.until(() -> devModeClient.getHttpResponse("/lorem.txt").contains("Lorem ipsum"));

// Update the resource
FileUtils.write(source, uuid, "UTF-8");
Files.writeString(source.toPath(), uuid);
await()
.pollDelay(100, TimeUnit.MILLISECONDS)
.atMost(TestUtils.getDefaultTimeout(), TimeUnit.MINUTES)
Expand Down Expand Up @@ -755,7 +754,7 @@ public void testThatTheApplicationIsReloadedOnNewResource() throws MavenInvocati
" return \"bar\";\n" +
" }\n" +
"}\n";
FileUtils.write(source, myNewResource, StandardCharsets.UTF_8);
Files.writeString(source.toPath(), myNewResource);

// Wait until we get "bar"
await()
Expand Down Expand Up @@ -790,7 +789,7 @@ public void testThatClassFileAreCleanedUp() throws MavenInvocationException, IOE
" return \"to be deleted\";\n" +
" }\n" +
"}";
FileUtils.write(source, classDeletionResource, StandardCharsets.UTF_8);
Files.writeString(source.toPath(), classDeletionResource, StandardCharsets.UTF_8);

runAndCheck();
// Wait until source file is compiled
Expand Down Expand Up @@ -903,9 +902,8 @@ public void testThatAddingConfigFileWorksCorrectly() throws MavenInvocationExcep

String uuid = UUID.randomUUID().toString();

FileUtils.write(configurationFile,
"greeting=" + uuid,
"UTF-8");
Files.writeString(configurationFile.toPath(),
"greeting=" + uuid);
await()
.pollDelay(100, TimeUnit.MILLISECONDS)
.pollInterval(1, TimeUnit.SECONDS)
Expand All @@ -926,9 +924,8 @@ public void testThatExternalConfigOverridesConfigInJar() throws MavenInvocationE

String uuid = UUID.randomUUID().toString();

FileUtils.write(configurationFile,
"greeting=" + uuid,
"UTF-8");
Files.writeString(configurationFile.toPath(),
"greeting=" + uuid);
await()
.pollDelay(100, TimeUnit.MILLISECONDS)
.pollInterval(1, TimeUnit.SECONDS)
Expand All @@ -950,26 +947,25 @@ public void testThatNewResourcesAreServed() throws MavenInvocationException, IOE

// Create a new resource
File source = new File(testDir, "src/main/resources/META-INF/resources/lorem.txt");
FileUtils.write(source,
"Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.",
"UTF-8");
Files.writeString(source.toPath(),
"Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.");
await()
.pollDelay(100, TimeUnit.MILLISECONDS)
.pollDelay(200, TimeUnit.MILLISECONDS)
.atMost(TestUtils.getDefaultTimeout(), TimeUnit.MINUTES)
.until(() -> devModeClient.getHttpResponse("/lorem.txt"), containsString("Lorem ipsum"));

// Update the resource
String uuid = UUID.randomUUID().toString();
FileUtils.write(source, uuid, "UTF-8");
Files.writeString(source.toPath(), uuid);
await()
.pollDelay(100, TimeUnit.MILLISECONDS)
.pollDelay(200, TimeUnit.MILLISECONDS)
.atMost(TestUtils.getDefaultTimeout(), TimeUnit.MINUTES)
.until(() -> devModeClient.getHttpResponse("/lorem.txt"), equalTo(uuid));

// Delete the resource
source.delete();
await()
.pollDelay(100, TimeUnit.MILLISECONDS)
.pollDelay(200, TimeUnit.MILLISECONDS)
.atMost(TestUtils.getDefaultTimeout(), TimeUnit.MINUTES)
.until(() -> devModeClient.getHttpResponse("/lorem.txt", 404));
}
Expand All @@ -985,7 +981,7 @@ public void testThatConfigFileDeletionsAreDetected() throws MavenInvocationExcep
.until(() -> devModeClient.getHttpResponse("/app/hello/greetings").contains("Bonjour"));

File source = new File(testDir, "src/main/resources/application.properties");
FileUtils.delete(source);
Files.delete(source.toPath());

await()
.pollDelay(100, TimeUnit.MILLISECONDS)
Expand Down Expand Up @@ -1014,24 +1010,24 @@ private void testMultipleResourceDirectories() throws MavenInvocationException,

// Update the application.properties
File source = new File(testDir, "src/main/resources-primary/application.properties");
FileUtils.write(source, "greeting=Salut", "UTF-8");
Files.writeString(source.toPath(), "greeting=Salut");
await()
.pollDelay(100, TimeUnit.MILLISECONDS)
.atMost(TestUtils.getDefaultTimeout(), TimeUnit.MINUTES)
.until(() -> devModeClient.getHttpResponse("/app/hello/greetings").contains("Salut/Other"));

// Add the application.yaml
source = new File(testDir, "src/main/resources-secondary/application.yaml");
FileUtils.write(source, "other:\n" +
" greeting: Buenos dias", "UTF-8");
Files.writeString(source.toPath(), "other:\n" +
" greeting: Buenos dias");
await()
.pollDelay(100, TimeUnit.MILLISECONDS)
.atMost(TestUtils.getDefaultTimeout(), TimeUnit.MINUTES)
.until(() -> devModeClient.getHttpResponse("/app/hello/greetings").contains("Salut/Buenos dias"));

// Update the application.yaml
FileUtils.write(source, "other:\n" +
" greeting: Hola", "UTF-8");
Files.writeString(source.toPath(), "other:\n" +
" greeting: Hola");
await()
.pollDelay(100, TimeUnit.MILLISECONDS)
.atMost(TestUtils.getDefaultTimeout(), TimeUnit.MINUTES)
Expand Down Expand Up @@ -1127,7 +1123,7 @@ public void testThatNewBeanAreDiscovered() throws IOException, MavenInvocationEx
" }\n" +
" \n" +
"}";
FileUtils.write(source, content, "UTF-8");
Files.writeString(source.toPath(), content);

// Update the resource to use the bean
File resource = new File(testDir, "src/main/java/org/acme/HelloResource.java");
Expand Down Expand Up @@ -1399,7 +1395,7 @@ public void testThatWatchedAbsolutePathsAreNotDeleted() throws MavenInvocationEx

// Update the .env
File source = new File(testDir, ".env");
FileUtils.write(source, "GREETING=Hallo", "UTF-8");
Files.writeString(source.toPath(), "GREETING=Hallo");

assertTrue(source.exists());

Expand Down

0 comments on commit 8085100

Please sign in to comment.