Skip to content

Commit

Permalink
Improve Native coverage for several modules (#238)
Browse files Browse the repository at this point in the history
From quarkusio/quarkus#13154, the `@TestProfile` annotation supports Native tests, therefore the modules 001, 301 and 303 can be extended for Native test coverage.
As part of this work, we have supported also the test resources for Native: quarkusio/quarkus#18077

And also, I've removed the workaround for quarkusio/quarkus#16810 that had been fixed a while ago.

Moreover, for 301:
- We've fixed the native failures and got rid of the application.properties file in the test resources. This can be closed now: quarkusio/quarkus#17829.
- Reduce the number of traces to ease the troubleshot of failures.

And for 303:
- Refactored the test resources to not rely on system properties to load/unload application properties.
  • Loading branch information
Sgitario authored Jul 14, 2021
1 parent 293e6ec commit b0d7435
Show file tree
Hide file tree
Showing 23 changed files with 103 additions and 167 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@

import org.junit.jupiter.api.Test;

import io.quarkus.test.junit.DisabledOnNativeImage;
import io.quarkus.test.junit.QuarkusTest;
import io.quarkus.test.junit.QuarkusTestProfile;
import io.quarkus.test.junit.TestProfile;
Expand All @@ -17,7 +16,6 @@
import io.restassured.specification.MultiPartSpecification;

@QuarkusTest
@DisabledOnNativeImage // @TestProfile works in JVM mode
@TestProfile(AsciiMultipartResourceTest.AsciiTestProfile.class)
public class AsciiMultipartResourceTest {

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package io.quarkus.qe.core;

import io.quarkus.test.junit.NativeImageTest;

@NativeImageTest
public class NativeAsciiMultipartResourceIT extends AsciiMultipartResourceTest {

}
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
import static org.junit.Assert.assertTrue;

import java.io.File;
import java.net.MalformedURLException;
import java.nio.file.Paths;

import org.junit.jupiter.api.Test;
Expand All @@ -16,7 +15,7 @@ public class ChuckNorrisResourceIT extends ChuckNorrisResourceTest {
private static final String DEBUG_SYMBOLS_FILE_NAME = "300-quarkus-vertx-webclient-1.0.0-SNAPSHOT-runner.debug";

@Test
public void checkNativeDebugSymbols() throws MalformedURLException {
public void checkNativeDebugSymbols() {
File debugFile = Paths.get("target", DEBUG_SYMBOLS_FILE_NAME).toFile();
assertTrue("Missing debug symbols file: " + DEBUG_SYMBOLS_FILE_NAME, debugFile.exists());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,15 +41,15 @@ public Uni<Void> asyncStart() {
@Broadcast
public String process(StockPrice next) {
next.setStatus(status.COMPLETED);
LOG.infov("CONSUMER -> ID: {0}, PRICE: {1}", next.getId(), next.getPrice());
emitter.send(next).whenComplete(handlerEmitterResponse(KStockPriceConsumer.class.getName()));
LOG.debugv("CONSUMER -> ID: {0}, PRICE: {1}", next.getId(), next.getPrice());
emitter.send(next).whenComplete(handlerEmitterResponse());
return next.getId() + "-" + next.getPrice() + "-" + next.getStatus();
}

private BiConsumer<Void, Throwable> handlerEmitterResponse(final String owner) {
private BiConsumer<Void, Throwable> handlerEmitterResponse() {
return (success, failure) -> {
if (failure != null) {
LOG.info(String.format("D'oh! %s", failure.getMessage()));
LOG.debugv("D'oh! {0}", failure.getMessage());
}
};
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ public Uni<Void> generate() {
IntStream.range(0, config.batchSize()).forEach(next -> {
StockPrice event = StockPrice.newBuilder().setId("IBM").setPrice(random.nextDouble()).setStatus(status.PENDING)
.build();
LOG.infov("PRODUCER -> ID: {0}, PRICE: {1}", event.getId(), event.getPrice());
LOG.debugv("PRODUCER -> ID: {0}, PRICE: {1}", event.getId(), event.getPrice());
emitter.send(event).whenComplete(handlerEmitterResponse(StockPriceProducer.class.getName()));
});

Expand All @@ -46,9 +46,9 @@ public Uni<Void> generate() {
private BiConsumer<Void, Throwable> handlerEmitterResponse(final String owner) {
return (success, failure) -> {
if (failure != null) {
LOG.info(String.format("D'oh! %s", failure.getMessage()));
LOG.debugv("D'oh! {0}", failure.getMessage());
} else {
LOG.info(String.format("Message sent successfully. Owner %s", owner));
LOG.debugv("Message sent successfully. Owner {0}", owner);
}
};
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,4 @@
quarkus.test.native-image-profile=test
# TODO https://github.com/quarkusio/quarkus/issues/16810
quarkus.test.flat-class-path=true
# Configuration file - Quarkus profile: Strimzi [Default]

kafka.bootstrap.servers=localhost:9092

# Kafka AVRO scenario
Expand Down Expand Up @@ -33,12 +29,14 @@ mp.messaging.outgoing.sink-stock-price.apicurio.registry.artifact-id=io.apicurio
mp.messaging.outgoing.sink-stock-price.apicurio.registry.global-id=io.apicurio.registry.utils.serde.strategy.GetOrCreateIdStrategy
mp.messaging.outgoing.sink-stock-price.apicurio.registry.avro-datum-provider=io.apicurio.registry.utils.serde.avro.ReflectAvroDatumProvider

# Jaeger
quarkus.opentelemetry.tracer.exporter.jaeger.endpoint=http://localhost:14250/api/traces

# Configuration file - Quarkus profile: Confluent

%confluent.kafka.bootstrap.servers=localhost:9092

%confluent.vertx.kafka.producer.delay-ms=5
%confluent.vertx.kafka.producer.delay-ms=100
%confluent.vertx.kafka.producer.batch-size=1

%confluent.mp.messaging.outgoing.source-stock-price.connector=smallrye-kafka
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,14 @@
import io.quarkus.qe.kafka.resources.ConfluentTestProfile;
import io.quarkus.qe.kafka.resources.JaegerTestResource;
import io.quarkus.test.common.QuarkusTestResource;
import io.quarkus.test.junit.DisabledOnNativeImage;
import io.quarkus.test.junit.QuarkusTest;
import io.quarkus.test.junit.TestProfile;

@QuarkusTest
@TestProfile(ConfluentTestProfile.class)
@QuarkusTestResource(JaegerTestResource.class)
@DisabledOnNativeImage
public class ConfluentKafkaTest extends KafkaCommonTest {
private static final String STOCK_MONITOR_SSE_ENDPOINT = "http://localhost:8083/stock/stream";
private static final String STOCK_MONITOR_SSE_ENDPOINT = "http://localhost:8081/stock/stream";

@Override
protected String getServerSentEventURL() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,7 @@
import io.restassured.response.Response;

abstract class KafkaCommonTest {
private final static String jaegerEndpoint = "http://localhost:16686/api/traces";
static final String NATIVE = "native";
static final String QUARKUS_PROFILE = "quarkus.profile";
static final boolean IS_NATIVE = System.getProperty(QUARKUS_PROFILE, "").equals(NATIVE);
private final static String JAEGER_ENDPOINT = "http://localhost:16686/api/traces";

private Response resp;

Expand All @@ -46,7 +43,7 @@ public void kafkaProducerShouldTrace() {
final int pageLimit = 50;
final String expectedOperationName = "stock-price send";
await().atMost(1, TimeUnit.MINUTES).pollInterval(Duration.ofSeconds(1)).untilAsserted(() -> {
thenRetrieveTraces(pageLimit, "1h", getServiceName(), expectedOperationName);
thenRetrieveTraces(pageLimit, "1h", expectedOperationName);
thenStatusCodeMustBe(HttpStatus.SC_OK);
thenTraceDataSizeMustBe(greaterThan(0));
thenTraceSpanSizeMustBe(greaterThan(0));
Expand All @@ -62,7 +59,7 @@ public void kafkaConsumerShouldTrace() throws InterruptedException {
final int pageLimit = 50;
final String expectedOperationName = "stock-price receive";
await().atMost(1, TimeUnit.MINUTES).pollInterval(Duration.ofSeconds(1)).untilAsserted(() -> {
thenRetrieveTraces(pageLimit, "1h", getServiceName(), expectedOperationName);
thenRetrieveTraces(pageLimit, "1h", expectedOperationName);
thenStatusCodeMustBe(HttpStatus.SC_OK);
thenTraceDataSizeMustBe(greaterThan(0));
thenTraceSpanSizeMustBe(greaterThan(0));
Expand All @@ -72,13 +69,13 @@ public void kafkaConsumerShouldTrace() throws InterruptedException {
});
}

private void thenRetrieveTraces(int pageLimit, String lookBack, String serviceName, String operationName) {
private void thenRetrieveTraces(int pageLimit, String lookBack, String operationName) {
resp = given().when()
.queryParam("limit", pageLimit)
.queryParam("lookback", lookBack)
.queryParam("service", serviceName)
.queryParam("service", getServiceName())
.queryParam("operation", operationName)
.get(jaegerEndpoint);
.get(JAEGER_ENDPOINT);
}

private void thenStatusCodeMustBe(int expectedStatusCode) {
Expand Down Expand Up @@ -108,7 +105,7 @@ private void thenCheckThatAllOperationNamesAreEqualTo(String expectedOperationNa

private String getServiceName() {
// TODO https://github.com/quarkusio/quarkus/issues/16499
return (IS_NATIVE) ? "301-quarkus-vertx-kafka" : "<<unset>>";
return isNativeTest() ? "301-quarkus-vertx-kafka" : "<<unset>>";
}

private void sendAndReceiveEvents(int timeoutMin, int expectedEventsAmount) throws InterruptedException {
Expand All @@ -125,5 +122,9 @@ private void sendAndReceiveEvents(int timeoutMin, int expectedEventsAmount) thro
source.close();
}

protected boolean isNativeTest() {
return false;
}

protected abstract String getServerSentEventURL();
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package io.quarkus.qe.kafka;

import io.quarkus.test.junit.NativeImageTest;

@NativeImageTest
public class NativeConfluentKafkaIT extends ConfluentKafkaTest {

@Override
protected boolean isNativeTest() {
return true;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package io.quarkus.qe.kafka;

import io.quarkus.test.junit.NativeImageTest;

@NativeImageTest
public class NativeStrimziKafkaIT extends StrimziKafkaTest {

@Override
protected boolean isNativeTest() {
return true;
}
}

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
@QuarkusTestResource(JaegerTestResource.class)
public class StrimziKafkaTest extends KafkaCommonTest {

private static final String STOCK_MONITOR_SSE_ENDPOINT = "http://localhost:8083/stock/stream";
private static final String STOCK_MONITOR_SSE_ENDPOINT = "http://localhost:8081/stock/stream";

@Override
protected String getServerSentEventURL() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

public class JaegerContainer extends GenericContainer<JaegerContainer> {
public static final int REST_PORT = 16686;
private static final int TRACE_PORT = 14250;
public static final int TRACE_PORT = 14250;

public JaegerContainer() {
super("jaegertracing/all-in-one:latest");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,9 @@ public Map<String, String> start() {
container = new JaegerContainer();
container.start();

return Collections.emptyMap();
return Collections.singletonMap(
"quarkus.opentelemetry.tracer.exporter.jaeger.endpoint",
String.format("http://%s:%s/api/traces", container.getContainerIpAddress(), JaegerContainer.TRACE_PORT));
}

@Override
Expand Down
65 changes: 0 additions & 65 deletions 301-quarkus-vertx-kafka/src/test/resources/application.properties

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package io.quarkus.qe.vertx.sql.handlers;

import io.quarkus.test.junit.NativeImageTest;

@NativeImageTest
public class NativeDb2HandlerIT extends Db2HandlerTest {
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package io.quarkus.qe.vertx.sql.handlers;

import io.quarkus.test.junit.NativeImageTest;

@NativeImageTest
public class NativeMysqlHandlerIT extends MysqlHandlerTest {
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package io.quarkus.qe.vertx.sql.handlers;

import io.quarkus.test.junit.NativeImageTest;

@NativeImageTest
public class NativePostgresqlHandlerIT extends PostgresqlHandlerTest {
}

This file was deleted.

Loading

0 comments on commit b0d7435

Please sign in to comment.