Skip to content

Commit 0061a82

Browse files
committed
Add a Camel dev mode test
1 parent 76bdf3d commit 0061a82

File tree

6 files changed

+172
-0
lines changed

6 files changed

+172
-0
lines changed
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<!--
3+
4+
Licensed to the Apache Software Foundation (ASF) under one or more
5+
contributor license agreements. See the NOTICE file distributed with
6+
this work for additional information regarding copyright ownership.
7+
The ASF licenses this file to You under the Apache License, Version 2.0
8+
(the "License"); you may not use this file except in compliance with
9+
the License. You may obtain a copy of the License at
10+
11+
http://www.apache.org/licenses/LICENSE-2.0
12+
13+
Unless required by applicable law or agreed to in writing, software
14+
distributed under the License is distributed on an "AS IS" BASIS,
15+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16+
See the License for the specific language governing permissions and
17+
limitations under the License.
18+
19+
-->
20+
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
21+
<modelVersion>4.0.0</modelVersion>
22+
<parent>
23+
<groupId>io.quarkus</groupId>
24+
<artifactId>quarkus-universe-integration-tests-camel</artifactId>
25+
<version>999-SNAPSHOT</version>
26+
<relativePath>../pom.xml</relativePath>
27+
</parent>
28+
29+
<artifactId>quarkus-universe-integration-tests-camel-timer-devmode</artifactId>
30+
31+
<dependencyManagement>
32+
<dependencies>
33+
<dependency>
34+
<groupId>io.quarkus</groupId>
35+
<artifactId>quarkus-universe-bom-deployment</artifactId>
36+
<version>${project.version}</version>
37+
<type>pom</type>
38+
<scope>import</scope>
39+
</dependency>
40+
</dependencies>
41+
</dependencyManagement>
42+
43+
<dependencies>
44+
<dependency>
45+
<groupId>org.apache.camel.quarkus</groupId>
46+
<artifactId>camel-quarkus-timer-deployment</artifactId>
47+
</dependency>
48+
49+
<dependency>
50+
<groupId>io.quarkus</groupId>
51+
<artifactId>quarkus-junit5-internal</artifactId>
52+
<scope>test</scope>
53+
</dependency>
54+
<dependency>
55+
<groupId>org.awaitility</groupId>
56+
<artifactId>awaitility</artifactId>
57+
<scope>test</scope>
58+
</dependency>
59+
</dependencies>
60+
61+
</project>
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
package io.quarkus.platform.camel.timer.test.devmode;
2+
3+
/**
4+
* A workaround for https://github.com/quarkusio/quarkus/issues/9299
5+
*
6+
*/
7+
public class Dummy {
8+
9+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
package io.quarkus.platform.camel.timer.test.devmode;
2+
3+
import java.io.BufferedReader;
4+
import java.io.IOException;
5+
import java.io.StringWriter;
6+
import java.io.Writer;
7+
import java.nio.charset.StandardCharsets;
8+
import java.nio.file.Files;
9+
import java.nio.file.Path;
10+
import java.nio.file.Paths;
11+
import java.util.Properties;
12+
import java.util.concurrent.TimeUnit;
13+
14+
import io.quarkus.test.QuarkusDevModeTest;
15+
import org.awaitility.Awaitility;
16+
import org.jboss.shrinkwrap.api.ShrinkWrap;
17+
import org.jboss.shrinkwrap.api.asset.Asset;
18+
import org.jboss.shrinkwrap.api.asset.StringAsset;
19+
import org.jboss.shrinkwrap.api.spec.JavaArchive;
20+
import org.junit.jupiter.api.Assertions;
21+
import org.junit.jupiter.api.Test;
22+
import org.junit.jupiter.api.extension.RegisterExtension;
23+
24+
public class TimerDevModeTest {
25+
private static final Path LOG_FILE = Paths.get("target/" + TimerDevModeTest.class.getSimpleName() + ".log");
26+
27+
@RegisterExtension
28+
static final QuarkusDevModeTest TEST = new QuarkusDevModeTest()
29+
.setArchiveProducer(() -> ShrinkWrap
30+
.create(JavaArchive.class)
31+
.addClasses(TimerRoute.class)
32+
.addAsResource(applicationProperties(), "application.properties"))
33+
.setLogFileName(LOG_FILE.getFileName().toString());
34+
35+
@Test
36+
void logMessageEdit() throws IOException {
37+
Awaitility.await()
38+
.atMost(1, TimeUnit.MINUTES)
39+
.until(() -> {
40+
return Files.exists(LOG_FILE);
41+
});
42+
try (BufferedReader logFileReader = Files.newBufferedReader(LOG_FILE, StandardCharsets.UTF_8)) {
43+
assertLogMessage(logFileReader, "Hello foo", 30000);
44+
TEST.modifySourceFile(TimerRoute.class, oldSource -> oldSource.replace("Hello foo", "Hello bar"));
45+
assertLogMessage(logFileReader, "Hello bar", 30000);
46+
}
47+
}
48+
49+
static void assertLogMessage(BufferedReader logFileReader, String msg, long timeout) throws IOException {
50+
boolean found = false;
51+
final long deadline = System.currentTimeMillis() + timeout;
52+
while (System.currentTimeMillis() < deadline) {
53+
final String line = logFileReader.readLine();
54+
if (line == null) {
55+
try {
56+
Thread.sleep(50);
57+
} catch (InterruptedException e) {
58+
Thread.currentThread().interrupt();
59+
throw new RuntimeException(e);
60+
}
61+
} else if (line.contains(msg)) {
62+
found = true;
63+
break;
64+
}
65+
}
66+
Assertions.assertTrue(found, "Could not find '" + msg + "' in " + LOG_FILE);
67+
}
68+
69+
public static Asset applicationProperties() {
70+
Writer writer = new StringWriter();
71+
Properties props = new Properties();
72+
props.setProperty("quarkus.log.file.enable", "true");
73+
props.setProperty("quarkus.log.file.path", LOG_FILE.toString());
74+
try {
75+
props.store(writer, "");
76+
} catch (IOException e) {
77+
throw new RuntimeException(e);
78+
}
79+
80+
return new StringAsset(writer.toString());
81+
}
82+
}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
package io.quarkus.platform.camel.timer.test.devmode;
2+
3+
import org.apache.camel.builder.RouteBuilder;
4+
import org.jboss.logging.Logger;
5+
6+
public class TimerRoute extends RouteBuilder {
7+
8+
private static final Logger LOG = Logger.getLogger(TimerRoute.class);
9+
10+
@Override
11+
public void configure() throws Exception {
12+
from("timer:foo?period=100")
13+
.process(exchange -> LOG.info("Hello foo"));
14+
}
15+
}

integration-tests/camel/pom.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
</dependencyManagement>
2626

2727
<modules>
28+
<module>camel-timer-devmode</module>
2829
<module>rpkgtests</module>
2930
<!-- START: modules generated by rpkgtests-maven-plugin -->
3031
<module>camel-activemq</module>

pom.xml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -182,6 +182,10 @@
182182
<rpkgModulePomXmlPath>integration-tests/camel/rpkgtests/pom.xml</rpkgModulePomXmlPath>
183183
<rpkgtestsPluginVersion>@{rpkgtests-maven-plugin.version}</rpkgtestsPluginVersion>
184184
<templatesUriBase>file:src/rpkg-templates</templatesUriBase>
185+
<cleanExcludes>
186+
<cleanExclude>pom.xml</cleanExclude>
187+
<cleanExclude>camel-timer-devmode/**</cleanExclude>
188+
</cleanExcludes>
185189
</configuration>
186190
</execution>
187191
</executions>

0 commit comments

Comments
 (0)