This is an automated email from the ASF dual-hosted git repository. ppalaga pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/camel-quarkus.git
The following commit(s) were added to refs/heads/master by this push: new 83cda81 Fix #1177 Add simple timer dev mode test 83cda81 is described below commit 83cda81e806f928889ee4bd0f63c28f021bf5a43 Author: Peter Palaga <ppal...@redhat.com> AuthorDate: Mon May 4 12:55:30 2020 +0200 Fix #1177 Add simple timer dev mode test --- extensions/timer/deployment/pom.xml | 12 +++ .../test/devmode/timer/TimerDevModeTest.java | 97 ++++++++++++++++++++++ .../component/test/devmode/timer/TimerRoute.java | 31 +++++++ 3 files changed, 140 insertions(+) diff --git a/extensions/timer/deployment/pom.xml b/extensions/timer/deployment/pom.xml index 008253a..93904a8 100644 --- a/extensions/timer/deployment/pom.xml +++ b/extensions/timer/deployment/pom.xml @@ -50,6 +50,18 @@ <groupId>org.apache.camel.quarkus</groupId> <artifactId>camel-quarkus-timer</artifactId> </dependency> + + + <dependency> + <groupId>io.quarkus</groupId> + <artifactId>quarkus-junit5-internal</artifactId> + <scope>test</scope> + </dependency> + <dependency> + <groupId>org.awaitility</groupId> + <artifactId>awaitility</artifactId> + <scope>test</scope> + </dependency> </dependencies> <build> diff --git a/extensions/timer/deployment/src/test/java/org/apache/camel/quarkus/component/test/devmode/timer/TimerDevModeTest.java b/extensions/timer/deployment/src/test/java/org/apache/camel/quarkus/component/test/devmode/timer/TimerDevModeTest.java new file mode 100644 index 0000000..f83c82e --- /dev/null +++ b/extensions/timer/deployment/src/test/java/org/apache/camel/quarkus/component/test/devmode/timer/TimerDevModeTest.java @@ -0,0 +1,97 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.camel.quarkus.component.test.devmode.timer; + +import java.io.BufferedReader; +import java.io.IOException; +import java.io.StringWriter; +import java.io.Writer; +import java.nio.charset.StandardCharsets; +import java.nio.file.Files; +import java.nio.file.Path; +import java.nio.file.Paths; +import java.util.Properties; +import java.util.concurrent.TimeUnit; + +import io.quarkus.test.QuarkusDevModeTest; +import org.awaitility.Awaitility; +import org.jboss.shrinkwrap.api.ShrinkWrap; +import org.jboss.shrinkwrap.api.asset.Asset; +import org.jboss.shrinkwrap.api.asset.StringAsset; +import org.jboss.shrinkwrap.api.spec.JavaArchive; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.RegisterExtension; + +public class TimerDevModeTest { + private static final Path LOG_FILE = Paths.get("target/" + TimerDevModeTest.class.getSimpleName() + ".log"); + + @RegisterExtension + static final QuarkusDevModeTest TEST = new QuarkusDevModeTest() + .setArchiveProducer(() -> ShrinkWrap + .create(JavaArchive.class) + .addClasses(TimerRoute.class) + .addAsResource(applicationProperties(), "application.properties")) + .setLogFileName(LOG_FILE.getFileName().toString()); + + @Test + void logMessageEdit() throws IOException { + Awaitility.await() + .atMost(1, TimeUnit.MINUTES) + .until(() -> Files.exists(LOG_FILE)); + + try (BufferedReader logFileReader = Files.newBufferedReader(LOG_FILE, StandardCharsets.UTF_8)) { + assertLogMessage(logFileReader, "Hello foo", 30000); + TEST.modifySourceFile(TimerRoute.class, oldSource -> oldSource.replace("Hello foo", "Hello bar")); + assertLogMessage(logFileReader, "Hello bar", 30000); + } + } + + static void assertLogMessage(BufferedReader logFileReader, String msg, long timeout) throws IOException { + boolean found = false; + final long deadline = System.currentTimeMillis() + timeout; + while (System.currentTimeMillis() < deadline) { + final String line = logFileReader.readLine(); + if (line == null) { + try { + Thread.sleep(50); + } catch (InterruptedException e) { + Thread.currentThread().interrupt(); + throw new RuntimeException(e); + } + } else if (line.contains(msg)) { + found = true; + break; + } + } + Assertions.assertTrue(found, "Could not find '" + msg + "' in " + LOG_FILE); + } + + public static Asset applicationProperties() { + Writer writer = new StringWriter(); + Properties props = new Properties(); + props.setProperty("quarkus.log.file.enable", "true"); + props.setProperty("quarkus.log.file.path", LOG_FILE.toString()); + try { + props.store(writer, ""); + } catch (IOException e) { + throw new RuntimeException(e); + } + + return new StringAsset(writer.toString()); + } +} diff --git a/extensions/timer/deployment/src/test/java/org/apache/camel/quarkus/component/test/devmode/timer/TimerRoute.java b/extensions/timer/deployment/src/test/java/org/apache/camel/quarkus/component/test/devmode/timer/TimerRoute.java new file mode 100644 index 0000000..fc2d1cd --- /dev/null +++ b/extensions/timer/deployment/src/test/java/org/apache/camel/quarkus/component/test/devmode/timer/TimerRoute.java @@ -0,0 +1,31 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.camel.quarkus.component.test.devmode.timer; + +import org.apache.camel.builder.RouteBuilder; +import org.jboss.logging.Logger; + +public class TimerRoute extends RouteBuilder { + + private static final Logger LOG = Logger.getLogger(TimerRoute.class); + + @Override + public void configure() throws Exception { + from("timer:foo?period=100") + .process(exchange -> LOG.info("Hello foo")); + } +}