Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added trivial test for every basic variant of execution #18

Merged
merged 4 commits into from
Oct 4, 2024
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
6 changes: 3 additions & 3 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,11 @@ jobs:

steps:
- uses: actions/checkout@v4
- name: Set up JDK 17
- name: Set up JDK 21
uses: actions/setup-java@v4
with:
java-version: '17'
java-version: '21'
distribution: 'temurin'
cache: maven
- name: Build with Maven
run: mvn -B clean package
run: mvn -B clean verify
2 changes: 1 addition & 1 deletion .github/workflows/docker-publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ jobs:
- name: Maven Configure
uses: actions/setup-java@v4
with:
java-version: '17'
java-version: '21'
distribution: 'temurin'

- name: Set up Docker Buildx
Expand Down
78 changes: 76 additions & 2 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,38 @@
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>

<dependencies>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-jdk14</artifactId>

This comment was marked as resolved.

Copy link
Contributor Author

@dmatej dmatej Oct 6, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is not, take a look to SLF4J website. It is the artifact name just to keep continuity. JUL was added to JDK at the time of Java 1.4, since then it has nearly the same api, but internally it changed over time. And it is also a default backend behind System Logger facade, which came in Java 11.

SLF4J can bind to both as an api or as an implementation. With all those platforms you basically have to choose your backend and sink all other to it. SLF4J is very capable in this discipline, so it this case:

  • TestContainers use slf4j-api
  • GlassFish uses JUL as the impl backend extended by own logmanager.
  • GlassFish and its dependencies use JUL, System. Logger and JBoss-Logging + some additonal custom apis as an api facade.

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah I see, this is the JUL implementation binding; I have avoided using JUL and was not familiar with that artifact. Your explanation makes sense. In the context of most elements of the stack using it, it makes sense to make it the target. I've avoided it due to it being the only implementation with a performance penalty for bridging away from it.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The penalty is only when an app logs using JUL and you want to translate that to slf4j and then log with something else, e.g. log4j. It’s the opposite case here. In this case, test containers use slf4j for logging and we want that to be logged via JUL, in the same way as our logs in tests. This doesn’t incur much performance penalty because JUL is called only when log messages are really logged and not always, as in the first case. Note that the slf4j-jdk14 artfact means slf4j logged via JUL, while jul-to-slf4j means JUL logged via slf4j and subsequently via some slf4j adapter (log4j, logback, etc)

<version>2.0.16</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-engine</artifactId>
<version>5.10.3</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.hamcrest</groupId>
<artifactId>hamcrest</artifactId>
<version>2.2</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.testcontainers</groupId>
<artifactId>testcontainers</artifactId>
<version>1.20.2</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.testcontainers</groupId>
<artifactId>junit-jupiter</artifactId>
<version>1.20.2</version>
</dependency>
</dependencies>

<build>
<resources>
<resource>
Expand Down Expand Up @@ -169,14 +201,56 @@
</images>
</configuration>
</plugin>
<plugin>
<artifactId>maven-failsafe-plugin</artifactId>
<executions>
<execution>
<id>execute</id>
<phase>integration-test</phase>
<goals>
<goal>integration-test</goal>
</goals>
</execution>
<execution>
<id>verify</id>
<phase>verify</phase>
<goals>
<goal>verify</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
<pluginManagement>
<plugins>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.11.0</version>
<version>3.13.0</version>
<configuration>
<release>21</release>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>3.5.0</version>
<configuration>
<includes>
<include>**/*Test.java</include>
</includes>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-failsafe-plugin</artifactId>
<version>3.5.0</version>
<configuration>
<release>17</release>
<systemPropertyVariables>
<docker.glassfish.image>${docker.glassfish.image}</docker.glassfish.image>
</systemPropertyVariables>
<includes>
<include>**/*IT.java</include>
</includes>
</configuration>
</plugin>
<plugin>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
/*
* Copyright (c) 2024 Contributors to the Eclipse Foundation.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v. 2.0, which is available at
* http://www.eclipse.org/legal/epl-2.0.
*
* This Source Code may also be made available under the following Secondary
* Licenses when the conditions for such availability set forth in the
* Eclipse Public License v. 2.0 are satisfied: GNU General Public License,
* version 2 with the GNU Classpath Exception, which is available at
* https://www.gnu.org/software/classpath/license.html.
*
* SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
*/

package org.glassfish.main.distributions.docker;

import java.io.InputStream;
import java.net.HttpURLConnection;
import java.net.URI;
import java.net.URL;
import java.nio.charset.StandardCharsets;

import org.junit.jupiter.api.Test;
import org.testcontainers.containers.GenericContainer;
import org.testcontainers.junit.jupiter.Container;
import org.testcontainers.junit.jupiter.Testcontainers;

import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.stringContainsInOrder;
import static org.junit.jupiter.api.Assertions.assertEquals;

/**
*
*/
@Testcontainers
public class AsadminIT {

@SuppressWarnings({"rawtypes", "resource"})
@Container
private final GenericContainer server = new GenericContainer<>(System.getProperty("docker.glassfish.image"))
.withCommand("asadmin start-domain").withExposedPorts(8080)
.withLogConsumer(o -> System.err.print("GF: " + o.getUtf8String()));

@Test
void getRoot() throws Exception {
URL url = URI.create("http://localhost:" + server.getMappedPort(8080) + "/").toURL();
HttpURLConnection connection = (HttpURLConnection) url.openConnection();
String content;
try {
connection.setRequestMethod("GET");
assertEquals(200, connection.getResponseCode(), "Response code");
try (InputStream in = connection.getInputStream()) {
content = new String(in.readAllBytes(), StandardCharsets.UTF_8);
}
} finally {
connection.disconnect();
}
assertThat(content, stringContainsInOrder("Eclipse GlassFish", "index.html", "production-quality"));
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
/*
* Copyright (c) 2024 Contributors to the Eclipse Foundation.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v. 2.0, which is available at
* http://www.eclipse.org/legal/epl-2.0.
*
* This Source Code may also be made available under the following Secondary
* Licenses when the conditions for such availability set forth in the
* Eclipse Public License v. 2.0 are satisfied: GNU General Public License,
* version 2 with the GNU Classpath Exception, which is available at
* https://www.gnu.org/software/classpath/license.html.
*
* SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
*/

package org.glassfish.main.distributions.docker;

import java.net.HttpURLConnection;
import java.net.URI;
import java.net.URL;

import org.junit.jupiter.api.Test;
import org.testcontainers.containers.GenericContainer;
import org.testcontainers.containers.output.OutputFrame.OutputType;
import org.testcontainers.junit.jupiter.Container;
import org.testcontainers.junit.jupiter.Testcontainers;

import static org.junit.jupiter.api.Assertions.assertEquals;

/**
*
*/
@Testcontainers
public class RunembeddedIT {

@SuppressWarnings({"rawtypes", "resource"})
@Container
private final GenericContainer server = new GenericContainer<>(System.getProperty("docker.glassfish.image"))
.withCommand("runembedded").withExposedPorts(8080).withLogConsumer(o -> {
// FIXME: If we don't use the interactive terminal, spams STDOUT. To be fixed in 7.0.19+.
if (o.getType() == OutputType.STDERR) {
System.err.print("GF: " + o.getUtf8String());
}
});

@Test
void getRoot() throws Exception {
URL url = URI.create("http://localhost:" + server.getMappedPort(8080) + "/").toURL();
HttpURLConnection connection = (HttpURLConnection) url.openConnection();
try {
connection.setRequestMethod("GET");
assertEquals(404, connection.getResponseCode(), "Response code");
} finally {
connection.disconnect();
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
/*
* Copyright (c) 2024 Contributors to the Eclipse Foundation.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v. 2.0, which is available at
* http://www.eclipse.org/legal/epl-2.0.
*
* This Source Code may also be made available under the following Secondary
* Licenses when the conditions for such availability set forth in the
* Eclipse Public License v. 2.0 are satisfied: GNU General Public License,
* version 2 with the GNU Classpath Exception, which is available at
* https://www.gnu.org/software/classpath/license.html.
*
* SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
*/

package org.glassfish.main.distributions.docker;

import java.io.InputStream;
import java.net.HttpURLConnection;
import java.net.URI;
import java.net.URL;
import java.nio.charset.StandardCharsets;

import org.junit.jupiter.api.Test;
import org.testcontainers.containers.GenericContainer;
import org.testcontainers.junit.jupiter.Container;
import org.testcontainers.junit.jupiter.Testcontainers;

import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.stringContainsInOrder;
import static org.junit.jupiter.api.Assertions.assertEquals;

/**
*
*/
@Testcontainers
public class StartServIT {

@SuppressWarnings({"rawtypes", "resource"})
@Container
private final GenericContainer server = new GenericContainer<>(System.getProperty("docker.glassfish.image"))
.withCommand("startserv").withExposedPorts(8080)
.withLogConsumer(o -> System.err.print("GF: " + o.getUtf8String()));

@Test
void getRoot() throws Exception {
URL url = URI.create("http://localhost:" + server.getMappedPort(8080) + "/").toURL();
HttpURLConnection connection = (HttpURLConnection) url.openConnection();
String content;
try {
connection.setRequestMethod("GET");
assertEquals(200, connection.getResponseCode(), "Response code");
try (InputStream in = connection.getInputStream()) {
content = new String(in.readAllBytes(), StandardCharsets.UTF_8);
}
} finally {
connection.disconnect();
}
assertThat(content, stringContainsInOrder("Eclipse GlassFish", "index.html", "production-quality"));
}
}