gnodet-bot commented on code in PR #29083: URL: https://github.com/apache/camel/pull/29083#discussion_r4669138730
########## dsl/camel-jbang/camel-jbang-it/src/test/java/org/apache/camel/dsl/jbang/it/InfraAdvancedITCase.java: ########## @@ -0,0 +1,103 @@ +/* + * 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.dsl.jbang.it; + +import java.time.Duration; +import java.util.regex.Matcher; +import java.util.regex.Pattern; + +import org.apache.camel.dsl.jbang.it.support.JBangTestSupport; +import org.assertj.core.api.Assertions; +import org.awaitility.Awaitility; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.Tag; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.condition.DisabledIfSystemProperty; +import org.junit.jupiter.api.condition.DisabledOnOs; + +import static org.junit.jupiter.api.condition.OS.WINDOWS; + +@Tag("container-only") +@DisabledOnOs(WINDOWS) +@DisabledIfSystemProperty(named = "ci.env.name", matches = ".*", disabledReason = "Requires too much resources") +public class InfraAdvancedITCase extends JBangTestSupport { + + private static final String SERVICE = "ftp"; + + @AfterEach + public void stopInfraService() { + execInContainer(getMainCommand() + " infra stop " + SERVICE + " || true"); + } + + private static final Pattern PID_PATTERN = Pattern.compile("PID:\\s*(\\d+)"); + + private String getServicePID(String message) { + Assertions.assertThat(message) + .as("infra run/restart --background output should contain 'PID:'") + .contains("PID:"); + // Find the last "PID: <digits>" in the output — the new process when infra restart + // prints both a "Stopping (PID: old)" and a "Running ... PID: new" line. + Matcher m = PID_PATTERN.matcher(message); + String pid = null; + while (m.find()) { + pid = m.group(1); + } + return pid; Review Comment: ⚠️ **Null return on regex mismatch** — `getServicePID` guards with `.contains("PID:")` (line 51) but then matches with `PID:\\s*(\\d+)` (line 54). If the output contains the literal `"PID:"` but no digits follow (e.g. a future format change), the while-loop finds nothing, `pid` stays `null`, and the method returns `null` silently. Callers then do `Assertions.assertThat(execute("infra ps")).contains(pid)` — AssertJ throws an NPE on a `null` argument rather than a readable assertion failure. Move the assertion after the loop to guard the actual parse result: ```suggestion String pid = null; while (m.find()) { pid = m.group(1); } Assertions.assertThat(pid) .as("infra output should contain 'PID: <digits>' but was: %s", message) .isNotNull(); return pid; ``` -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected]
