-
Notifications
You must be signed in to change notification settings - Fork 2.7k
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
Add tests for CT + Kafka + DevServices #19354
Merged
Merged
Changes from all commits
Commits
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
91 changes: 91 additions & 0 deletions
91
...reactivemessaging/kafka/deployment/testing/KafkaDevServicesContinuousTestingTestCase.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,91 @@ | ||
package io.quarkus.smallrye.reactivemessaging.kafka.deployment.testing; | ||
|
||
import java.util.function.Supplier; | ||
|
||
import org.jboss.shrinkwrap.api.ShrinkWrap; | ||
import org.jboss.shrinkwrap.api.asset.StringAsset; | ||
import org.jboss.shrinkwrap.api.spec.JavaArchive; | ||
import org.junit.jupiter.api.Assertions; | ||
import org.junit.jupiter.api.Test; | ||
import org.junit.jupiter.api.extension.RegisterExtension; | ||
|
||
import io.quarkus.test.QuarkusDevModeTest; | ||
import io.quarkus.vertx.http.testrunner.ContinuousTestingTestUtils; | ||
|
||
public class KafkaDevServicesContinuousTestingTestCase { | ||
|
||
static final String FINAL_APP_PROPERTIES = ContinuousTestingTestUtils.appProperties( | ||
"mp.messaging.outgoing.generated-price.connector=smallrye-kafka", | ||
"mp.messaging.outgoing.generated-price.topic=prices", | ||
"mp.messaging.outgoing.generated-price.value.serializer=org.apache.kafka.common.serialization.IntegerSerializer", | ||
"mp.messaging.incoming.prices.connector=smallrye-kafka", | ||
"mp.messaging.incoming.prices.health-readiness-enabled=false", | ||
"mp.messaging.incoming.prices.topic=prices", | ||
"mp.messaging.incoming.prices.value.deserializer=org.apache.kafka.common.serialization.IntegerDeserializer"); | ||
|
||
@RegisterExtension | ||
public static QuarkusDevModeTest test = new QuarkusDevModeTest() | ||
.setArchiveProducer(new Supplier<JavaArchive>() { | ||
@Override | ||
public JavaArchive get() { | ||
return ShrinkWrap.create(JavaArchive.class) | ||
.addClasses(PriceConverter.class, PriceResource.class, PriceGenerator.class) | ||
.addAsResource(new StringAsset(ContinuousTestingTestUtils.appProperties("")), | ||
"application.properties"); | ||
} | ||
}).setTestArchiveProducer(new Supplier<JavaArchive>() { | ||
@Override | ||
public JavaArchive get() { | ||
return ShrinkWrap.create(JavaArchive.class).addClass(PriceResourceET.class); | ||
} | ||
}); | ||
|
||
//see https://github.com/quarkusio/quarkus/issues/19180 | ||
@Test | ||
public void testContinuousTestingScenario1() { | ||
ContinuousTestingTestUtils utils = new ContinuousTestingTestUtils(); | ||
var result = utils.waitForNextCompletion(); | ||
Assertions.assertEquals(0, result.getTotalTestsPassed()); | ||
Assertions.assertEquals(1, result.getTotalTestsFailed()); | ||
test.modifySourceFile(PriceResource.class, s -> s.replaceAll("//", "")); | ||
result = utils.waitForNextCompletion(); | ||
Assertions.assertEquals(0, result.getTotalTestsPassed()); | ||
Assertions.assertEquals(1, result.getTotalTestsFailed()); | ||
test.modifySourceFile(PriceConverter.class, s -> s.replaceAll("//", "")); | ||
result = utils.waitForNextCompletion(); | ||
Assertions.assertEquals(0, result.getTotalTestsPassed()); | ||
Assertions.assertEquals(1, result.getTotalTestsFailed()); | ||
test.modifySourceFile(PriceGenerator.class, s -> s.replaceAll("//", "")); | ||
result = utils.waitForNextCompletion(); | ||
Assertions.assertEquals(0, result.getTotalTestsPassed()); | ||
Assertions.assertEquals(1, result.getTotalTestsFailed()); | ||
test.modifyResourceFile("application.properties", s -> FINAL_APP_PROPERTIES); | ||
result = utils.waitForNextCompletion(); | ||
Assertions.assertEquals(1, result.getTotalTestsPassed()); | ||
Assertions.assertEquals(0, result.getTotalTestsFailed()); | ||
} | ||
|
||
@Test | ||
public void testContinuousTestingScenario2() { | ||
ContinuousTestingTestUtils utils = new ContinuousTestingTestUtils(); | ||
var result = utils.waitForNextCompletion(); | ||
Assertions.assertEquals(0, result.getTotalTestsPassed()); | ||
Assertions.assertEquals(1, result.getTotalTestsFailed()); | ||
test.modifyResourceFile("application.properties", s -> FINAL_APP_PROPERTIES); | ||
result = utils.waitForNextCompletion(); | ||
Assertions.assertEquals(0, result.getTotalTestsPassed()); | ||
Assertions.assertEquals(1, result.getTotalTestsFailed()); | ||
test.modifySourceFile(PriceConverter.class, s -> s.replaceAll("//", "")); | ||
result = utils.waitForNextCompletion(); | ||
Assertions.assertEquals(0, result.getTotalTestsPassed()); | ||
Assertions.assertEquals(1, result.getTotalTestsFailed()); | ||
test.modifySourceFile(PriceGenerator.class, s -> s.replaceAll("//", "")); | ||
result = utils.waitForNextCompletion(); | ||
Assertions.assertEquals(0, result.getTotalTestsPassed()); | ||
Assertions.assertEquals(1, result.getTotalTestsFailed()); | ||
test.modifySourceFile(PriceResource.class, s -> s.replaceAll("//", "")); | ||
result = utils.waitForNextCompletion(); | ||
Assertions.assertEquals(1, result.getTotalTestsPassed()); | ||
Assertions.assertEquals(0, result.getTotalTestsFailed()); | ||
} | ||
} |
59 changes: 59 additions & 0 deletions
59
...ng/kafka/deployment/testing/KafkaDevServicesContinuousTestingWorkingAppPropsTestCase.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,59 @@ | ||
package io.quarkus.smallrye.reactivemessaging.kafka.deployment.testing; | ||
|
||
import java.util.function.Supplier; | ||
|
||
import org.jboss.shrinkwrap.api.ShrinkWrap; | ||
import org.jboss.shrinkwrap.api.asset.StringAsset; | ||
import org.jboss.shrinkwrap.api.spec.JavaArchive; | ||
import org.junit.jupiter.api.Assertions; | ||
import org.junit.jupiter.api.Test; | ||
import org.junit.jupiter.api.extension.RegisterExtension; | ||
|
||
import io.quarkus.test.QuarkusDevModeTest; | ||
import io.quarkus.vertx.http.testrunner.ContinuousTestingTestUtils; | ||
|
||
public class KafkaDevServicesContinuousTestingWorkingAppPropsTestCase { | ||
|
||
@RegisterExtension | ||
public static QuarkusDevModeTest test = new QuarkusDevModeTest() | ||
.setArchiveProducer(new Supplier<JavaArchive>() { | ||
@Override | ||
public JavaArchive get() { | ||
return ShrinkWrap.create(JavaArchive.class) | ||
.addClasses(PriceConverter.class, PriceResource.class, PriceGenerator.class) | ||
.addAsResource(new StringAsset(KafkaDevServicesContinuousTestingTestCase.FINAL_APP_PROPERTIES), | ||
"application.properties"); | ||
} | ||
}).setTestArchiveProducer(new Supplier<JavaArchive>() { | ||
@Override | ||
public JavaArchive get() { | ||
return ShrinkWrap.create(JavaArchive.class).addClass(PriceResourceET.class); | ||
} | ||
}); | ||
|
||
/** | ||
* Similar to {@link KafkaDevServicesContinuousTestingTestCase} however it starts with application.properties configued | ||
* | ||
* see https://github.com/quarkusio/quarkus/issues/19180 | ||
*/ | ||
@Test | ||
public void testContinuousTestingScenario3() { | ||
ContinuousTestingTestUtils utils = new ContinuousTestingTestUtils(); | ||
var result = utils.waitForNextCompletion(); | ||
Assertions.assertEquals(0, result.getTotalTestsPassed()); | ||
Assertions.assertEquals(1, result.getTotalTestsFailed()); | ||
test.modifySourceFile(PriceResource.class, s -> s.replaceAll("//", "")); | ||
result = utils.waitForNextCompletion(); | ||
Assertions.assertEquals(0, result.getTotalTestsPassed()); | ||
Assertions.assertEquals(1, result.getTotalTestsFailed()); | ||
test.modifySourceFile(PriceConverter.class, s -> s.replaceAll("//", "")); | ||
result = utils.waitForNextCompletion(); | ||
Assertions.assertEquals(0, result.getTotalTestsPassed()); | ||
Assertions.assertEquals(1, result.getTotalTestsFailed()); | ||
test.modifySourceFile(PriceGenerator.class, s -> s.replaceAll("//", "")); | ||
result = utils.waitForNextCompletion(); | ||
Assertions.assertEquals(1, result.getTotalTestsPassed()); | ||
Assertions.assertEquals(0, result.getTotalTestsFailed()); | ||
} | ||
|
||
} |
20 changes: 20 additions & 0 deletions
20
...t/java/io/quarkus/smallrye/reactivemessaging/kafka/deployment/testing/PriceConverter.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,20 @@ | ||
package io.quarkus.smallrye.reactivemessaging.kafka.deployment.testing; | ||
|
||
// | ||
//import io.smallrye.reactive.messaging.annotations.Broadcast; | ||
//import org.eclipse.microprofile.reactive.messaging.Incoming; | ||
//import org.eclipse.microprofile.reactive.messaging.Outgoing; | ||
// | ||
//import javax.enterprise.context.ApplicationScoped; | ||
// | ||
//@ApplicationScoped | ||
public class PriceConverter { | ||
// private static final double CONVERSION_RATE = 0.88; | ||
// | ||
// @Incoming("prices") | ||
// @Outgoing("processed-prices") | ||
// @Broadcast | ||
// public double process(int priceInUsd) { | ||
// return priceInUsd * CONVERSION_RATE; | ||
// } | ||
} |
20 changes: 20 additions & 0 deletions
20
...t/java/io/quarkus/smallrye/reactivemessaging/kafka/deployment/testing/PriceGenerator.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,20 @@ | ||
package io.quarkus.smallrye.reactivemessaging.kafka.deployment.testing; | ||
|
||
//import io.smallrye.mutiny.Multi; | ||
//import org.eclipse.microprofile.reactive.messaging.Outgoing; | ||
// | ||
//import javax.enterprise.context.ApplicationScoped; | ||
//import java.time.Duration; | ||
//import java.util.Random; | ||
// | ||
//@ApplicationScoped | ||
public class PriceGenerator { | ||
// private final Random random = new Random(); | ||
// | ||
// @Outgoing("generated-price") | ||
// public Multi<Integer> generate() { | ||
// return Multi.createFrom().ticks().every(Duration.ofMillis(10)) | ||
// .onOverflow().drop() | ||
// .map(tick -> this.random.nextInt(100)); | ||
// } | ||
} |
26 changes: 26 additions & 0 deletions
26
...st/java/io/quarkus/smallrye/reactivemessaging/kafka/deployment/testing/PriceResource.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,26 @@ | ||
package io.quarkus.smallrye.reactivemessaging.kafka.deployment.testing; | ||
|
||
// | ||
//import org.eclipse.microprofile.reactive.messaging.Channel; | ||
//import org.reactivestreams.Publisher; | ||
// | ||
//import javax.ws.rs.GET; | ||
//import javax.ws.rs.Path; | ||
//import javax.ws.rs.Produces; | ||
//import javax.ws.rs.core.MediaType; | ||
// | ||
//@Path("/prices") | ||
public class PriceResource { | ||
// private final Publisher<Double> processedPrices; | ||
// | ||
// public PriceResource(@Channel("processed-prices") Publisher<Double> processedPrices) { | ||
// this.processedPrices = processedPrices; | ||
// } | ||
// | ||
// @GET | ||
// @Path("/stream") | ||
// @Produces(MediaType.SERVER_SENT_EVENTS) | ||
// public Publisher<Double> ssePrices() { | ||
// return this.processedPrices; | ||
// } | ||
} |
47 changes: 47 additions & 0 deletions
47
.../java/io/quarkus/smallrye/reactivemessaging/kafka/deployment/testing/PriceResourceET.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,47 @@ | ||
package io.quarkus.smallrye.reactivemessaging.kafka.deployment.testing; | ||
|
||
import java.net.URI; | ||
import java.time.Duration; | ||
import java.util.List; | ||
import java.util.concurrent.CopyOnWriteArrayList; | ||
|
||
import javax.ws.rs.client.Client; | ||
import javax.ws.rs.client.ClientBuilder; | ||
import javax.ws.rs.client.WebTarget; | ||
import javax.ws.rs.sse.SseEventSource; | ||
|
||
import org.assertj.core.api.Assertions; | ||
import org.awaitility.Awaitility; | ||
import org.junit.jupiter.api.Test; | ||
|
||
import io.quarkus.test.common.http.TestHTTPEndpoint; | ||
import io.quarkus.test.common.http.TestHTTPResource; | ||
import io.quarkus.test.junit.QuarkusTest; | ||
|
||
@QuarkusTest | ||
class PriceResourceET { | ||
@TestHTTPEndpoint(PriceResource.class) | ||
@TestHTTPResource("/stream") | ||
URI uri; | ||
|
||
@Test | ||
public void sseStream() { | ||
Client client = ClientBuilder.newClient(); | ||
WebTarget target = client.target(this.uri); | ||
|
||
List<Double> received = new CopyOnWriteArrayList<>(); | ||
|
||
try (SseEventSource source = SseEventSource.target(target).build()) { | ||
source.register(inboundSseEvent -> received.add(Double.valueOf(inboundSseEvent.readData()))); | ||
source.open(); | ||
|
||
Awaitility.await() | ||
.atMost(Duration.ofSeconds(1)) | ||
.until(() -> received.size() >= 2); | ||
} | ||
|
||
Assertions.assertThat(received) | ||
.hasSizeGreaterThan(2) | ||
.allMatch(value -> (value >= 0) && (value < 100)); | ||
} | ||
} |
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.
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.
Is this normal all this code is commented out?
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.
Yes, it simulates starting with an empty class and then adding the code. In the dev mode test I just remove the comments.