Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions dsl/camel-jbang/camel-jbang-it/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -227,6 +227,7 @@
<cli.jbang.repo>apache/camel</cli.jbang.repo>
<cli.jbang.branch>main</cli.jbang.branch>
<cli.jbang.docker.file/>
<cli.service.command>camel</cli.service.command>
<export.runtime/>
<maven.test.skip>false</maven.test.skip>
<shared.data.folder>target/data</shared.data.folder>
Expand Down Expand Up @@ -276,6 +277,7 @@
<cli.service.repo>${cli.jbang.repo}</cli.service.repo>
<cli.service.branch>${cli.jbang.branch}</cli.service.branch>
<cli.service.docker.file>${cli.jbang.docker.file}</cli.service.docker.file>
<cli.service.command>${cli.service.command}</cli.service.command>
<jbang.it.assert.wait.timeout>300</jbang.it.assert.wait.timeout>
<DISPLAY>${x11.display}</DISPLAY>
</systemPropertyVariables>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ public class CamelDebugITCase extends JBangTestSupport {
@Test
public void testDebug() throws IOException {
copyResourceInDataFolder(TestResources.ROUTE2);
execInContainer(String.format("nohup camel debug %s/route2.yaml&", mountPoint()));
execNohup(String.format("debug %s/route2.yaml", mountPoint()));
checkLogContains("Debugger JMXConnector listening at:");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,10 @@ public void testCmdStopByRouteID() throws IOException {
public void testCmdStopByPID() throws IOException {
copyResourceInDataFolder(TestResources.DIR_ROUTE);
copyResourceInDataFolder(TestResources.ROUTE2);
String PID = executeBackground(String.format("run %s/FromDirectoryRoute.java", mountPoint()));
String process = executeBackground(String.format("run %s/FromDirectoryRoute.java", mountPoint()));
executeBackground(String.format("run %s/route2.yaml", mountPoint()));
checkLogContains("Hello world!");
execute("cmd stop-route " + PID);
execute("cmd stop-route " + getPID(process));
checkCommandOutputsPattern("get route",
"route1\\s+timer:\\/\\/(yaml|java)\\?period=1000\\s+Stopped.*\\n.*route2.*timer:\\/\\/(yaml|java)\\?period=1000\\s+Started",
ASSERTION_WAIT_SECONDS);
Expand Down Expand Up @@ -78,11 +78,11 @@ public void testCmdStartByRouteID() throws IOException {
public void testCmdStartByPID() throws IOException {
copyResourceInDataFolder(TestResources.DIR_ROUTE);
copyResourceInDataFolder(TestResources.ROUTE2);
String PID = executeBackground(String.format("run %s/FromDirectoryRoute.java", mountPoint()));
String process = executeBackground(String.format("run %s/FromDirectoryRoute.java", mountPoint()));
executeBackground(String.format("run %s/route2.yaml", mountPoint()));
checkLogContains("Hello world!");
execute("cmd stop-route");
execute("cmd start-route " + PID);
execute("cmd start-route " + getPID(process));
checkCommandOutputsPattern("get route",
"route1\\s+timer:\\/\\/(yaml|java)\\?period=1000\\s+Started.*\\n.*route2.*timer:\\/\\/(yaml|java)\\?period=1000\\s+Stopped",
ASSERTION_WAIT_SECONDS);
Expand All @@ -104,14 +104,14 @@ public void testCmdStartAll() throws IOException {
@Test
public void testCamelWatch() throws IOException {
copyResourceInDataFolder(TestResources.ROUTE2);
String PID = executeBackground(String.format("run %s/route2.yaml", mountPoint()));
newFileInDataFolder("watch-sleep", "nohup camel ps --watch&\n" +
String process = executeBackground(String.format("run %s/route2.yaml", mountPoint()));
newFileInDataFolder("watch-sleep", "nohup " + getMainCommand() + " ps --watch&\n" +
"sleep 5\n" +
"echo \"q\"\n");
execInContainer(String.format("chmod +x %s/watch-sleep", mountPoint()));
Assertions.assertThat(
execInContainer(String.format("%s/watch-sleep", mountPoint())))
.as("watch command should output PID" + PID)
.contains(PID);
.as("watch command should output PID" + getPID(process))
.contains(getPID(process));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ public void infraListTest() {
@Test
public void runStopServiceTest() {
String msg = execute("infra run --background " + SERVICE);
String PID = getPID(msg);
String PID = getServicePID(msg);
Assertions.assertThat(msg).contains(String.format("Running %s in background", SERVICE));
Awaitility.await()
.atMost(Duration.ofSeconds(30))
Expand All @@ -55,7 +55,7 @@ public void runStopServiceTest() {
@Test
public void runServiceWithImplementationTest() {
String msg = execute(String.format("infra run --background %s %s", IMPL_SERVICE, IMPLEMENTATION));
String PID = getPID(msg);
String PID = getServicePID(msg);
Assertions.assertThat(msg).contains(String.format("Running %s in background", IMPL_SERVICE));
Awaitility.await()
.atMost(Duration.ofSeconds(30))
Expand All @@ -66,7 +66,7 @@ public void runServiceWithImplementationTest() {
checkCommandDoesNotOutput("infra ps", PID);
}

private String getPID(String message) {
private String getServicePID(String message) {
return message.split(":")[1].replaceAll("[^0-9]", "");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -29,24 +29,23 @@ public class JolokiaITCase extends JBangTestSupport {
@Test
public void testAttachJolokia() throws IOException {
copyResourceInDataFolder(TestResources.DIR_ROUTE);
String processID = executeBackground(String.format("run %s/FromDirectoryRoute.java", mountPoint()));
String process = executeBackground(String.format("run %s/FromDirectoryRoute.java", mountPoint()));
checkLogContains("(FromDirectoryRoute) started");
execute("jolokia FromDirectoryRoute");
Assertions.assertThat(execInContainer("curl http://127.0.0.1:8778/jolokia/"))
.as("Jolokia should be reachable")
.contains("\"agentContext\":\"/jolokia\"");
Assertions.assertThat(execute("jolokia FromDirectoryRoute --stop"))
.as("Jolokia should stop")
.contains("Stopped Jolokia for PID " + processID);

.contains("Stopped Jolokia for PID " + getPID(process));
}

@Test
public void testRunHawtio() throws IOException, InterruptedException {
copyResourceInDataFolder(TestResources.DIR_ROUTE);
executeBackground(String.format("run %s/FromDirectoryRoute.java", mountPoint()));
checkLogContains("(FromDirectoryRoute) started");
execInContainer("nohup camel hawtio FromDirectoryRoute &");
execNohup("hawtio FromDirectoryRoute");
Awaitility.await()
.atMost(Duration.ofSeconds(30))
.pollInterval(Duration.ofSeconds(1))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,24 +28,26 @@ public class MavenGradleITCase extends JBangTestSupport {
@Test
public void runFromMavenModuleTest() {
execInContainer(String.format("mkdir %s/mvn-app", mountPoint()));
execInContainer(String.format("cd %s/mvn-app && camel init cheese.xml", mountPoint()));
execInContainer(String.format("cd %s/mvn-app && %s init cheese.xml", mountPoint(), getMainCommand()));
execInContainer(String.format(
"cd %s/mvn-app && camel export --runtime=camel-main --gav=org.jbang:maven-app:1.0-SNAPSHOT", mountPoint()));
execInContainer(String.format("cd %s/mvn-app && camel run pom.xml --background", mountPoint()));
"cd %s/mvn-app && %s export --runtime=camel-main --gav=org.jbang:maven-app:1.0-SNAPSHOT", mountPoint(),
getMainCommand()));
execInContainer(String.format("cd %s/mvn-app && %s run pom.xml --background", mountPoint(), getMainCommand()));
checkLogContains("Apache Camel " + version() + " (maven-app) started");
checkLogContains("Hello Camel from route1");
}

@Test
public void runFromGradleTest() throws IOException {
execInContainer(String.format("mkdir %s/gradle-app", mountPoint()));
execInContainer(String.format("cd %s/gradle-app && camel init cheese.xml", mountPoint()));
execInContainer(String.format("cd %s/gradle-app && %s init cheese.xml", mountPoint(), getMainCommand()));
execInContainer(String.format(
"cd %s/gradle-app && camel export --runtime=camel-main --gav=org.jbang:gradle-app:1.0-SNAPSHOT", mountPoint()));
"cd %s/gradle-app && %s export --runtime=camel-main --gav=org.jbang:gradle-app:1.0-SNAPSHOT", mountPoint(),
getMainCommand()));
copyResourceInDataFolder(TestResources.BUILD_GRADLE);
Files.move(Path.of(String.format("%s/build.gradle", getDataFolder())),
Path.of(String.format("%s/gradle-app/build.gradle", getDataFolder())));
execInContainer(String.format("cd %s/gradle-app && camel run pom.xml --background", mountPoint()));
execInContainer(String.format("cd %s/gradle-app && %s run pom.xml --background", mountPoint(), getMainCommand()));
checkLogContains("Apache Camel " + version() + " (gradle-app) started");
checkLogContains("Hello Camel from route1");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,5 +29,4 @@ public void runFromDirTest() throws IOException {
executeBackground(String.format("run --source-dir=%s", mountPoint()));
checkLogContains("Hello world!");
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -153,10 +153,10 @@ public void runDownloadedInDirectoryFromGithubTest() {
@DisabledIfSystemProperty(named = CliProperties.FORCE_RUN_VERSION, matches = ".+", disabledReason = "Due to CAMEL-20426")
public void runSpecificVersionTest(String version) {
initFileInDataFolder("cheese.xml");
final String pid = executeBackground(String.format("run %s/cheese.xml --camel-version=%s", mountPoint(), version));
final String process = executeBackground(String.format("run %s/cheese.xml --camel-version=%s", mountPoint(), version));
checkLogContainsPattern(String.format(" Apache Camel %s .* started", version));
checkLogContains(DEFAULT_MSG);
execute("stop " + pid);
execute("stop " + getPID(process));
}

@Test
Expand All @@ -182,7 +182,8 @@ public void runFromClipboardTest() throws IOException {
"sshpass -p '" + containerService.getSshPassword()
+ "' ssh -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no -X jbang@localhost -p "
+ containerService.getSshPort()
+ " \"camel run clipboard.xml --background && camel log\"")
+ " \"" + getMainCommand() + " run clipboard.xml --background && " + getMainCommand()
+ " log\"")
.redirectErrorStream(true);
try (BufferedReader input = new BufferedReader(new InputStreamReader(builder.start().getInputStream()))) {
Assertions.assertThatCode(() -> Awaitility.await()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,22 +48,22 @@ public static void end() {
public void sendMessageWithoutEndpoint() throws IOException {
copyResourceInDataFolder(TestResources.MQQT_CONSUMER);
final String ipAddr = getIpAddr(service.getContainer());
final String pid = executeBackground(String.format("run --property=brokerUrl=%s %s/%s",
final String process = executeBackground(String.format("run --property=brokerUrl=%s %s/%s",
"tcp://" + ipAddr + ":1883",
mountPoint(), TestResources.MQQT_CONSUMER.getName()));
checkLogContains("Started route1 (kamelet:mqtt5-source)");
final String payloadFile = "payload.json";
newFileInDataFolder(payloadFile, "{\"value\": 21}");
sendCmd(String.format("%s/%s", mountPoint(), payloadFile), pid);
sendCmd(String.format("%s/%s", mountPoint(), payloadFile), getPID(process));
checkLogContains("The temperature is 21");
}

@Test
public void testStub() throws IOException {
copyResourceInDataFolder(TestResources.STUB_ROUTE);
final String pid = executeBackground(String.format("run %s/%s --stub=jms",
final String process = executeBackground(String.format("run %s/%s --stub=jms",
mountPoint(), TestResources.STUB_ROUTE.getName()));
checkCommandOutputs("cmd send --body='Hello camel from stubbed jms' " + pid, "Sent (success)");
checkCommandOutputs("cmd send --body='Hello camel from stubbed jms' " + getPID(process), "Sent (success)");
checkCommandOutputs("cmd stub --browse", "Hello camel from stubbed jms", ASSERTION_WAIT_SECONDS);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,10 @@ protected String executeBackground(final String command) {
return containerService.executeBackground(command);
}

protected String execNohup(final String command) {
return containerService.executeGenericCommand("nohup " + getMainCommand() + " " + command + " &");
}

protected String mountPoint() {
return String.format("%s/%s", containerService.getMountPoint(), containerService.id());
}
Expand Down Expand Up @@ -178,13 +182,13 @@ protected void checkCommandOutputs(String command, String contains, int waitForS

protected void checkCommandOutputs(String command, String contains) {
Assertions.assertThat(execute(command))
.as("command camel " + command + " should output " + contains)
.as("command " + getMainCommand() + " " + command + "should output " + contains)
.contains(contains);
}

protected void checkCommandOutputsPattern(String command, String contains) {
Assertions.assertThat(execute(command))
.as("command camel " + command + " should output pattern " + contains)
.as("command " + getMainCommand() + " " + command + "should output " + contains)
.containsPattern(contains);
}

Expand All @@ -196,7 +200,7 @@ protected void checkCommandOutputsPattern(String command, String contains, int w

protected void checkCommandDoesNotOutput(String command, String contains) {
Assertions.assertThat(execute(command))
.as("command camel " + command + " should not output " + contains)
.as("command " + getMainCommand() + " " + command + "should not output " + contains)
.doesNotContain(contains);
}

Expand Down Expand Up @@ -289,6 +293,10 @@ protected String getLogs() {
return getLogs(null);
}

protected String getPID(String startupMessage) {
return startupMessage.split("PID:")[1].split(" ")[1].replaceAll("[^0-9]", "");
}

protected String getContainerLogs() {
return containerService.getContainerLogs();
}
Expand Down Expand Up @@ -334,6 +342,10 @@ protected String getDataFolder() {
return containerDataFolder;
}

protected String getMainCommand() {
return containerService.getMainCommand();
}

public String version() {
return containerService.version();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@

public class CliLocalContainerService implements CliService, ContainerService<CliBuiltContainer> {
public static final String CONTAINER_NAME = "camel-cli";
public static final String MAIN_COMMAND = System.getProperty("cli.service.command", "camel");
private static final Logger LOG = LoggerFactory.getLogger(CliLocalContainerService.class);
private final CliBuiltContainer container;
private String version;
Expand Down Expand Up @@ -113,7 +114,7 @@ public CliBuiltContainer getContainer() {

@Override
public String execute(String command) {
return executeGenericCommand(String.format("camel %s", command));
return executeGenericCommand(MAIN_COMMAND + " " + command);
}

@Override
Expand Down Expand Up @@ -215,6 +216,11 @@ public String getSshPassword() {
return container.getSshPassword();
}

@Override
public String getMainCommand() {
return MAIN_COMMAND;
}

private static Map<String, String> getHostsMap() {
return Optional.ofNullable(System.getProperty(CliProperties.EXTRA_HOSTS))
.map(p -> p.split(","))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,4 +74,6 @@ default void beforeEach(ExtensionContext extensionContext) throws Exception {
int getSshPort();

String getSshPassword();

String getMainCommand();
}