Skip to content
This repository has been archived by the owner on Sep 18, 2023. It is now read-only.

Commit

Permalink
Added lifecycle application module
Browse files Browse the repository at this point in the history
  • Loading branch information
Sgitario committed Apr 26, 2021
1 parent f9af89e commit e5a0073
Show file tree
Hide file tree
Showing 7 changed files with 193 additions and 0 deletions.
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -507,6 +507,10 @@ The Secret is exposed by mounting it into the container file system.
Checks that the application can read configuration from a Secret.
The Secret is obtained directly from the Kubernetes API server.

### `lifecycle-application`

Verifies lifecycle application features like `@QuarkusMain` and `@CommandLineArguments`.

### `sql-db`

Verifies that the application can connect to a SQL database and persist data using Hibernate ORM with Panache.
Expand Down
66 changes: 66 additions & 0 deletions lifecycle-application/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
<?xml version="1.0"?>
<project xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"
xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<modelVersion>4.0.0</modelVersion>

<parent>
<groupId>io.quarkus.ts.openshift</groupId>
<artifactId>parent</artifactId>
<version>1.0.0-SNAPSHOT</version>
<relativePath>..</relativePath>
</parent>

<artifactId>lifecycle-application</artifactId>
<packaging>jar</packaging>

<name>Quarkus OpenShift TS: Lifecycle Application</name>

<dependencies>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-openshift</artifactId>
</dependency>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-resteasy</artifactId>
</dependency>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-smallrye-health</artifactId>
</dependency>
<dependency>
<groupId>io.quarkus.ts.openshift</groupId>
<artifactId>app-metadata</artifactId>
</dependency>

<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-junit5</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>io.quarkus.ts.openshift</groupId>
<artifactId>common</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>io.rest-assured</groupId>
<artifactId>rest-assured</artifactId>
<scope>test</scope>
</dependency>
</dependencies>

<build>
<plugins>
<plugin>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-maven-plugin</artifactId>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-failsafe-plugin</artifactId>
</plugin>
</plugins>
</build>
</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package io.quarkus.ts.openshift.lifecycle;

import io.quarkus.runtime.annotations.CommandLineArguments;

import javax.inject.Inject;
import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;
import javax.ws.rs.core.MediaType;

import java.util.stream.Collectors;
import java.util.stream.Stream;

@Path("/args")
public class ArgsResource {
@Inject
@CommandLineArguments
String[] args;

@GET
@Produces(MediaType.TEXT_PLAIN)
public String get() {
return Stream.of(args).collect(Collectors.joining(","));
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package io.quarkus.ts.openshift.lifecycle;

import io.quarkus.runtime.Quarkus;
import io.quarkus.runtime.annotations.QuarkusMain;
import org.jboss.logging.Logger;

@QuarkusMain
public class Main {

public static final String ARGUMENTS_FROM_MAIN = "Received arguments: ";

private static final Logger LOG = Logger.getLogger(Main.class);

public static void main(String... args) {
LOG.info(ARGUMENTS_FROM_MAIN + String.join(",", args));
Quarkus.run(args);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
quarkus.openshift.expose=true

# We can't append arguments to the Java commend
# Not sure if the quarkus.openshift.arguments will be the right property to do this or there will be a new one.
# Related to https://github.com/quarkusio/quarkus/pull/15670#issuecomment-800857624.
# quarkus.openshift.arguments=ARG1,ARG2

quarkus.s2i.base-jvm-image=registry.access.redhat.com/ubi8/openjdk-11:latest
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
package io.quarkus.ts.openshift.lifecycle;

import io.fabric8.kubernetes.api.model.PodList;
import io.fabric8.openshift.client.OpenShiftClient;
import io.quarkus.ts.openshift.common.OpenShiftTest;
import io.quarkus.ts.openshift.common.injection.TestResource;
import org.apache.commons.lang3.StringUtils;
import org.junit.jupiter.api.Test;

import java.io.BufferedReader;
import java.io.StringReader;
import java.util.Arrays;
import java.util.List;
import java.util.Optional;
import java.util.stream.Stream;

import static io.restassured.RestAssured.when;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertTrue;

@OpenShiftTest
public class LifecycleApplicationOpenShiftIT {

private static final String LOGGING_PROPERTY = "-Djava.util.logging.manager=org.jboss.logmanager.LogManager";
private static final String RUNTIME_LABEL = "app.openshift.io/runtime";
private static final String RUNTIME_QUARKUS = "quarkus";
private static final List<String> EXPECTED_ARGUMENTS = Arrays.asList("ARG1", "ARG2");

@TestResource
private OpenShiftClient openshiftClient;

@Test
public void shouldArgumentsNotContainLoggingProperty() {
String actualArguments = when().get("/args")
.then().statusCode(200).extract().asString();

assertFalse(StringUtils.contains(actualArguments, LOGGING_PROPERTY),
"Actual arguments contain unexpected properties: " + actualArguments);
// Can't provide arguments to Java command: https://github.com/quarkusio/quarkus/pull/15670#issuecomment-800857624
// assertExpectedArguments(actualArguments);
}

@Test
public void shouldPrintMessagesFromQuarkusMain() {
PodList pods = openshiftClient.pods().withLabel(RUNTIME_LABEL, RUNTIME_QUARKUS).list();
assertEquals(1, pods.getItems().size(), "Found more than one pod with Quarkus runtime");

String actualLog = openshiftClient.pods().withName(pods.getItems().get(0).getMetadata().getName()).getLog();
Optional<String> argumentsLineOpt = toLines(actualLog).filter(line -> line.contains(Main.ARGUMENTS_FROM_MAIN))
.findFirst();

assertTrue(argumentsLineOpt.isPresent(),
"Pod log does not contain the received arguments. Actual content: " + actualLog);
String argumentsLine = argumentsLineOpt.get();
assertFalse(argumentsLine.contains(LOGGING_PROPERTY),
"Pod log contain unexpected properties. Actual content: " + argumentsLine);
// Can't provide arguments to Java command: https://github.com/quarkusio/quarkus/pull/15670#issuecomment-800857624
// assertExpectedArguments(argumentsLine);
}

private void assertExpectedArguments(String actualArguments) {
EXPECTED_ARGUMENTS.forEach(arg -> assertTrue(actualArguments.contains(arg),
"Expected argument " + arg + " was not found in actual arguments: " + actualArguments));
}

private static final Stream<String> toLines(String str) {
return new BufferedReader(new StringReader(str)).lines();
}

}
1 change: 1 addition & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
<module>configmap/file-system</module>
<module>config-secret/api-server</module>
<module>config-secret/file-system</module>
<module>lifecycle-application</module>
<module>messaging/artemis</module>
<module>messaging/artemis-jta</module>
<module>messaging/amqp-reactive</module>
Expand Down

0 comments on commit e5a0073

Please sign in to comment.