-
Notifications
You must be signed in to change notification settings - Fork 34
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add new module, which uses Vert.X-based HTTP server Verify, that it works, and that it creates all required metrics Required for https://issues.redhat.com/browse/QUARKUS-2829
- Loading branch information
Showing
14 changed files
with
342 additions
and
0 deletions.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> | ||
<modelVersion>4.0.0</modelVersion> | ||
<parent> | ||
<groupId>io.quarkus.ts.qe</groupId> | ||
<artifactId>parent</artifactId> | ||
<version>1.0.0-SNAPSHOT</version> | ||
<relativePath>../..</relativePath> | ||
</parent> | ||
<artifactId>vertx</artifactId> | ||
<packaging>jar</packaging> | ||
<name>Quarkus QE TS: HTTP: Vert.X</name> | ||
<dependencies> | ||
<dependency> | ||
<groupId>io.quarkus</groupId> | ||
<artifactId>quarkus-resteasy-reactive-jackson</artifactId> | ||
</dependency> | ||
<dependency> | ||
<groupId>io.quarkus</groupId> | ||
<artifactId>quarkus-vertx</artifactId> | ||
</dependency> | ||
<dependency> | ||
<groupId>io.quarkus</groupId> | ||
<artifactId>quarkus-micrometer-registry-prometheus</artifactId> | ||
</dependency> | ||
</dependencies> | ||
<profiles> | ||
<profile> | ||
<id>deploy-to-openshift-using-extension</id> | ||
<dependencies> | ||
<dependency> | ||
<groupId>io.quarkus</groupId> | ||
<artifactId>quarkus-openshift</artifactId> | ||
</dependency> | ||
</dependencies> | ||
</profile> | ||
</profiles> | ||
</project> |
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,14 @@ | ||
package io.quarkus.ts.vertx; | ||
|
||
public class Hello { | ||
|
||
private final String content; | ||
|
||
public Hello(String content) { | ||
this.content = content; | ||
} | ||
|
||
public String getContent() { | ||
return content; | ||
} | ||
} |
33 changes: 33 additions & 0 deletions
33
http/vertx/src/main/java/io/quarkus/ts/vertx/HelloResource.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,33 @@ | ||
package io.quarkus.ts.vertx; | ||
|
||
import javax.inject.Inject; | ||
import javax.ws.rs.DefaultValue; | ||
import javax.ws.rs.GET; | ||
import javax.ws.rs.Path; | ||
import javax.ws.rs.Produces; | ||
import javax.ws.rs.QueryParam; | ||
import javax.ws.rs.core.MediaType; | ||
|
||
import io.smallrye.mutiny.Uni; | ||
import io.vertx.mutiny.core.Vertx; | ||
import io.vertx.mutiny.core.buffer.Buffer; | ||
|
||
@Path("/hello") | ||
public class HelloResource { | ||
private final Vertx vertx; | ||
|
||
@Inject | ||
public HelloResource(Vertx vertx) { | ||
this.vertx = vertx; | ||
} | ||
|
||
@GET | ||
@Produces(MediaType.APPLICATION_JSON) | ||
public Uni<Hello> getMessage(@QueryParam("name") @DefaultValue("World") String name) { | ||
return vertx.fileSystem() | ||
.readFile("message.template") | ||
.map(Buffer::toString) | ||
.map(string -> String.format(string, name).trim()) | ||
.map(Hello::new); | ||
} | ||
} |
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,6 @@ | ||
quarkus.application.name=test-http | ||
|
||
%ServerlessExtensionOpenShiftHttpMinimumIT.quarkus.kubernetes.deployment-target=knative | ||
%ServerlessExtensionOpenShiftHttpMinimumIT.quarkus.container-image.registry=image-registry.openshift-image-registry.svc:5000 | ||
%ServerlessExtensionDockerBuildStrategyOpenShiftHttpMinimumIT.quarkus.kubernetes.deployment-target=knative | ||
%ServerlessExtensionDockerBuildStrategyOpenShiftHttpMinimumIT.quarkus.container-image.registry=image-registry.openshift-image-registry.svc:5000 |
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 @@ | ||
Hello, %s! |
121 changes: 121 additions & 0 deletions
121
http/vertx/src/test/java/io/quarkus/ts/vertx/AbstractVertxIT.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,121 @@ | ||
package io.quarkus.ts.vertx; | ||
|
||
import static org.hamcrest.CoreMatchers.is; | ||
import static org.junit.jupiter.api.Assertions.assertEquals; | ||
import static org.junit.jupiter.api.Assertions.assertTrue; | ||
import static org.testcontainers.shaded.org.hamcrest.MatcherAssert.assertThat; | ||
import static org.testcontainers.shaded.org.hamcrest.Matchers.containsString; | ||
|
||
import java.nio.charset.StandardCharsets; | ||
import java.util.Arrays; | ||
import java.util.HashMap; | ||
import java.util.Map; | ||
import java.util.Objects; | ||
|
||
import org.apache.http.HttpStatus; | ||
import org.junit.jupiter.api.Test; | ||
|
||
import io.restassured.response.Response; | ||
import io.restassured.specification.RequestSpecification; | ||
|
||
public abstract class AbstractVertxIT { | ||
|
||
@Test | ||
public void httpServerAndMetrics() { | ||
requests().get("/hello").then() | ||
.statusCode(HttpStatus.SC_OK) | ||
.body("content", is("Hello, World!")); | ||
|
||
Response response = requests().get("/q/metrics"); | ||
assertEquals(HttpStatus.SC_OK, response.statusCode()); | ||
assertThat(response.getContentType(), containsString("application/openmetrics-text")); | ||
String body = response.body().asString(); | ||
Map<String, Metric> metrics = parseMetrics(body); | ||
assertTrue(metrics.containsKey("worker_pool_active")); | ||
assertTrue(metrics.containsKey("worker_pool_completed_total")); | ||
assertTrue(metrics.containsKey("worker_pool_queue_size")); | ||
} | ||
|
||
@Test | ||
public void httpServerParsing() { | ||
requests().get("/hello?name=you").then().statusCode(HttpStatus.SC_OK).body("content", is("Hello, you!")); | ||
} | ||
|
||
public abstract RequestSpecification requests(); | ||
|
||
private Map<String, Metric> parseMetrics(String body) { | ||
Map<String, Metric> metrics = new HashMap<>(128); | ||
Arrays.stream(body.split("\n")) | ||
.filter(line -> !line.startsWith("#")) | ||
.map(Metric::new) | ||
.forEach(metric -> metrics.put(metric.name, metric)); | ||
return metrics; | ||
} | ||
|
||
private class Metric { | ||
private final String value; | ||
private final String name; | ||
|
||
/** | ||
* | ||
* @param source metric from the file, eg: | ||
* worker_pool_queue_size{pool_name="vert.x-internal-blocking",pool_type="worker"} 0.0 | ||
* content in curly brackets is ignored (for now) | ||
* since we do not care about values, we store them as strings, and ignore duplicated keys. | ||
*/ | ||
public Metric(String source) { | ||
final int DEFAULT = -1; | ||
int space = DEFAULT; | ||
int closing = DEFAULT; | ||
int opening = DEFAULT; | ||
byte[] bytes = source.getBytes(StandardCharsets.UTF_8); | ||
for (int i = bytes.length - 1; i >= 0; i--) { | ||
byte current = bytes[i]; | ||
if (current == ' ' && space == DEFAULT) { | ||
space = i; | ||
} | ||
if (current == '}' && closing == DEFAULT) { | ||
closing = i; | ||
} | ||
if (current == '{' && opening == DEFAULT) { | ||
opening = i; | ||
} | ||
} | ||
String key; | ||
if (space > 0) { | ||
value = source.substring(space); | ||
key = source.substring(0, space); | ||
} else { | ||
throw new IllegalArgumentException("Metric " + source + " doesn't contain a value"); | ||
} | ||
if (closing < space && opening < closing && opening > 0) { | ||
name = source.substring(0, opening); | ||
} else { | ||
name = key; | ||
} | ||
} | ||
|
||
public String getValue() { | ||
return value; | ||
} | ||
|
||
public String getName() { | ||
return name; | ||
} | ||
|
||
@Override | ||
public boolean equals(Object o) { | ||
if (this == o) | ||
return true; | ||
if (o == null || getClass() != o.getClass()) | ||
return false; | ||
Metric metric = (Metric) o; | ||
return value.equals(metric.value) && name.equals(metric.name); | ||
} | ||
|
||
@Override | ||
public int hashCode() { | ||
return Objects.hash(value, name); | ||
} | ||
} | ||
} |
18 changes: 18 additions & 0 deletions
18
http/vertx/src/test/java/io/quarkus/ts/vertx/LocalVertxIT.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,18 @@ | ||
package io.quarkus.ts.vertx; | ||
|
||
import io.quarkus.test.bootstrap.RestService; | ||
import io.quarkus.test.scenarios.QuarkusScenario; | ||
import io.quarkus.test.services.QuarkusApplication; | ||
import io.restassured.specification.RequestSpecification; | ||
|
||
@QuarkusScenario | ||
public class LocalVertxIT extends AbstractVertxIT { | ||
|
||
@QuarkusApplication | ||
static RestService app = new RestService(); | ||
|
||
@Override | ||
public RequestSpecification requests() { | ||
return app.given(); | ||
} | ||
} |
21 changes: 21 additions & 0 deletions
21
.../src/test/java/io/quarkus/ts/vertx/OpenShiftUsingExtensionDockerBuildStrategyVertxIT.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,21 @@ | ||
package io.quarkus.ts.vertx; | ||
|
||
import org.junit.jupiter.api.Tag; | ||
|
||
import io.quarkus.test.bootstrap.RestService; | ||
import io.quarkus.test.scenarios.OpenShiftDeploymentStrategy; | ||
import io.quarkus.test.scenarios.OpenShiftScenario; | ||
import io.quarkus.test.services.QuarkusApplication; | ||
import io.restassured.specification.RequestSpecification; | ||
|
||
@Tag("use-quarkus-openshift-extension") | ||
@OpenShiftScenario(deployment = OpenShiftDeploymentStrategy.UsingOpenShiftExtensionAndDockerBuildStrategy) | ||
public class OpenShiftUsingExtensionDockerBuildStrategyVertxIT extends AbstractVertxIT { | ||
@QuarkusApplication | ||
static RestService app = new RestService(); | ||
|
||
@Override | ||
public RequestSpecification requests() { | ||
return app.given(); | ||
} | ||
} |
21 changes: 21 additions & 0 deletions
21
http/vertx/src/test/java/io/quarkus/ts/vertx/OpenShiftUsingExtensionVertxIT.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,21 @@ | ||
package io.quarkus.ts.vertx; | ||
|
||
import org.junit.jupiter.api.Tag; | ||
|
||
import io.quarkus.test.bootstrap.RestService; | ||
import io.quarkus.test.scenarios.OpenShiftDeploymentStrategy; | ||
import io.quarkus.test.scenarios.OpenShiftScenario; | ||
import io.quarkus.test.services.QuarkusApplication; | ||
import io.restassured.specification.RequestSpecification; | ||
|
||
@Tag("use-quarkus-openshift-extension") | ||
@OpenShiftScenario(deployment = OpenShiftDeploymentStrategy.UsingOpenShiftExtension) | ||
public class OpenShiftUsingExtensionVertxIT extends AbstractVertxIT { | ||
@QuarkusApplication | ||
static RestService app = new RestService(); | ||
|
||
@Override | ||
public RequestSpecification requests() { | ||
return app.given(); | ||
} | ||
} |
17 changes: 17 additions & 0 deletions
17
http/vertx/src/test/java/io/quarkus/ts/vertx/OpenShiftVertxIT.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,17 @@ | ||
package io.quarkus.ts.vertx; | ||
|
||
import io.quarkus.test.bootstrap.RestService; | ||
import io.quarkus.test.scenarios.OpenShiftScenario; | ||
import io.quarkus.test.services.QuarkusApplication; | ||
import io.restassured.specification.RequestSpecification; | ||
|
||
@OpenShiftScenario | ||
public class OpenShiftVertxIT extends AbstractVertxIT { | ||
@QuarkusApplication | ||
static RestService app = new RestService(); | ||
|
||
@Override | ||
public RequestSpecification requests() { | ||
return app.given(); | ||
} | ||
} |
22 changes: 22 additions & 0 deletions
22
...test/java/io/quarkus/ts/vertx/ServerlessExtensionDockerBuildStrategyOpenShiftVertxIT.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,22 @@ | ||
package io.quarkus.ts.vertx; | ||
|
||
import org.junit.jupiter.api.Tag; | ||
|
||
import io.quarkus.test.bootstrap.RestService; | ||
import io.quarkus.test.scenarios.OpenShiftDeploymentStrategy; | ||
import io.quarkus.test.scenarios.OpenShiftScenario; | ||
import io.quarkus.test.services.QuarkusApplication; | ||
import io.restassured.specification.RequestSpecification; | ||
|
||
@Tag("use-quarkus-openshift-extension") | ||
@Tag("serverless") | ||
@OpenShiftScenario(deployment = OpenShiftDeploymentStrategy.UsingOpenShiftExtensionAndDockerBuildStrategy) | ||
public class ServerlessExtensionDockerBuildStrategyOpenShiftVertxIT extends AbstractVertxIT { | ||
@QuarkusApplication | ||
static RestService app = new RestService(); | ||
|
||
@Override | ||
public RequestSpecification requests() { | ||
return app.given().relaxedHTTPSValidation(); | ||
} | ||
} |
22 changes: 22 additions & 0 deletions
22
http/vertx/src/test/java/io/quarkus/ts/vertx/ServerlessExtensionOpenShiftVertxIT.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,22 @@ | ||
package io.quarkus.ts.vertx; | ||
|
||
import org.junit.jupiter.api.Tag; | ||
|
||
import io.quarkus.test.bootstrap.RestService; | ||
import io.quarkus.test.scenarios.OpenShiftDeploymentStrategy; | ||
import io.quarkus.test.scenarios.OpenShiftScenario; | ||
import io.quarkus.test.services.QuarkusApplication; | ||
import io.restassured.specification.RequestSpecification; | ||
|
||
@Tag("use-quarkus-openshift-extension") | ||
@Tag("serverless") | ||
@OpenShiftScenario(deployment = OpenShiftDeploymentStrategy.UsingOpenShiftExtension) | ||
public class ServerlessExtensionOpenShiftVertxIT extends AbstractVertxIT { | ||
@QuarkusApplication | ||
static RestService app = new RestService(); | ||
|
||
@Override | ||
public RequestSpecification requests() { | ||
return app.given().relaxedHTTPSValidation(); | ||
} | ||
} |
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