-
Notifications
You must be signed in to change notification settings - Fork 4
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
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
c1edd42
Added trivial test for every besic variant of execution
dmatej 3d28580
Use Java 21 for build. GF still uses 17 inside the docker container.
dmatej 38ad5c2
Run also integration tests on CI
dmatej 6d4802f
Removed redundant withExposedPorts and toString
dmatej File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
62 changes: 62 additions & 0 deletions
62
src/test/java/org/glassfish/main/distributions/docker/AsadminIT.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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")); | ||
} | ||
} |
58 changes: 58 additions & 0 deletions
58
src/test/java/org/glassfish/main/distributions/docker/RunembeddedIT.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
} | ||
} | ||
} |
62 changes: 62 additions & 0 deletions
62
src/test/java/org/glassfish/main/distributions/docker/StartServIT.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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")); | ||
} | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This comment was marked as resolved.
Sorry, something went wrong.
There was a problem hiding this comment.
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:
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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)