This is an automated email from the ASF dual-hosted git repository.

vy pushed a commit to branch feature/main/jtl-docker
in repository https://gitbox.apache.org/repos/asf/logging-log4j2.git


The following commit(s) were added to refs/heads/feature/main/jtl-docker by 
this push:
     new 2816153bcd Enable `docker` profile in CI for 
`log4j-layout-template-json-test`
2816153bcd is described below

commit 2816153bcd268f71587e1274417cde0823742cbf
Author: Volkan Yazıcı <[email protected]>
AuthorDate: Sun Sep 15 22:14:22 2024 +0200

    Enable `docker` profile in CI for `log4j-layout-template-json-test`
---
 log4j-layout-template-json-test/pom.xml            | 42 +++++++++++-----------
 .../log4j/layout/template/json/LogstashIT.java     | 23 ++++++++++--
 2 files changed, 41 insertions(+), 24 deletions(-)

diff --git a/log4j-layout-template-json-test/pom.xml 
b/log4j-layout-template-json-test/pom.xml
index 024b187f43..314acd9b86 100644
--- a/log4j-layout-template-json-test/pom.xml
+++ b/log4j-layout-template-json-test/pom.xml
@@ -118,23 +118,6 @@
   <build>
     <plugins>
 
-      <!-- Disable ITs, which are Docker-dependent, by default. -->
-      <plugin>
-        <groupId>org.apache.maven.plugins</groupId>
-        <artifactId>maven-failsafe-plugin</artifactId>
-        <configuration>
-          <skip>true</skip>
-        </configuration>
-        <executions>
-          <execution>
-            <goals>
-              <goal>integration-test</goal>
-              <goal>verify</goal>
-            </goals>
-          </execution>
-        </executions>
-      </plugin>
-
       <plugin>
         <groupId>org.apache.maven.plugins</groupId>
         <artifactId>maven-surefire-plugin</artifactId>
@@ -159,8 +142,17 @@
 
       <id>docker</id>
 
+      <!--
+        ~ Only the `ubuntu` CI runners have access to Docker
+        -->
       <activation>
-        <activeByDefault>false</activeByDefault>
+        <os>
+          <family>linux</family>
+        </os>
+        <property>
+          <name>env.CI</name>
+          <value>true</value>
+        </property>
       </activation>
 
       <properties>
@@ -191,7 +183,8 @@
                       <ES_JAVA_OPTS>${elastic.java-opts}</ES_JAVA_OPTS>
                     </env>
                     <ports>
-                      <port>9200:9200</port>
+                      <!-- Binds an ephemeral port to the `elasticsearch.port` 
Maven property. -->
+                      <port>localhost:elasticsearch.port:9200</port>
                     </ports>
                     <network>
                       <mode>custom</mode>
@@ -224,8 +217,10 @@
                       <LS_JAVA_OPTS>${elastic.java-opts}</LS_JAVA_OPTS>
                     </env>
                     <ports>
-                      <port>12222:12222</port>
-                      <port>12345:12345</port>
+                      <!-- Binds an ephemeral port to the `logstash.gelf.port` 
Maven property. -->
+                      <port>localhost:logstash.gelf.port:12222</port>
+                      <!-- Binds an ephemeral port to the `logstash.tcp.port` 
Maven property. -->
+                      <port>localhost:logstash.tcp.port:12345</port>
                     </ports>
                     <log>
                       <prefix>[LS]</prefix>
@@ -316,6 +311,11 @@
               <includes>
                 <include>**/*IT.java</include>
               </includes>
+              <systemPropertyVariables>
+                
<log4j.elasticsearch.port>${elasticsearch.port}</log4j.elasticsearch.port>
+                
<log4j.logstash.gelf.port>${logstash.gelf.port}</log4j.logstash.gelf.port>
+                
<log4j.logstash.tcp.port>${logstash.tcp.port}</log4j.logstash.tcp.port>
+              </systemPropertyVariables>
             </configuration>
             <executions>
               <execution>
diff --git 
a/log4j-layout-template-json-test/src/test/java/org/apache/logging/log4j/layout/template/json/LogstashIT.java
 
b/log4j-layout-template-json-test/src/test/java/org/apache/logging/log4j/layout/template/json/LogstashIT.java
index 72dfdc37f2..ac43ea3b1e 100644
--- 
a/log4j-layout-template-json-test/src/test/java/org/apache/logging/log4j/layout/template/json/LogstashIT.java
+++ 
b/log4j-layout-template-json-test/src/test/java/org/apache/logging/log4j/layout/template/json/LogstashIT.java
@@ -45,6 +45,7 @@ import org.apache.logging.log4j.core.util.NetUtils;
 import 
org.apache.logging.log4j.layout.template.json.JsonTemplateLayout.EventTemplateAdditionalField;
 import org.apache.logging.log4j.message.SimpleMessage;
 import org.apache.logging.log4j.status.StatusLogger;
+import org.apache.logging.log4j.util.Strings;
 import org.assertj.core.api.Assertions;
 import org.awaitility.Awaitility;
 import org.elasticsearch.ElasticsearchStatusException;
@@ -133,13 +134,29 @@ class LogstashIT {
 
         private MavenHardcodedConstants() {}
 
-        private static final int LS_GELF_INPUT_PORT = 12222;
+        private static final int LS_GELF_INPUT_PORT = 
readPort("log4j.logstash.gelf.port");
 
-        private static final int LS_TCP_INPUT_PORT = 12345;
+        private static final int LS_TCP_INPUT_PORT = 
readPort("log4j.logstash.tcp.port");
 
-        private static final int ES_PORT = 9200;
+        private static final int ES_PORT = 
readPort("log4j.elasticsearch.port");
 
         private static final String ES_INDEX_NAME = "log4j";
+
+        private static int readPort(final String propertyName) {
+            final String propertyValue = System.getProperty(propertyName);
+            final int port;
+            final String errorMessage = String.format(
+                    "was expecting a valid port number in the system property 
`%s`, found: `%s`",
+                    propertyName, propertyValue);
+            try {
+                if (Strings.isBlank(propertyValue) || (port = 
Integer.parseInt(propertyValue)) < 0 || port >= 0xFFFF) {
+                    throw new IllegalArgumentException(errorMessage);
+                }
+            } catch (final NumberFormatException error) {
+                throw new IllegalArgumentException(errorMessage, error);
+            }
+            return port;
+        }
     }
 
     @Test

Reply via email to