Skip to content

Commit 3289f66

Browse files
Merge pull request #48555 from holly-cummins/more-kafka-devservice-tests
Add more kafka dev service tests
2 parents b857e19 + 43a064a commit 3289f66

20 files changed

+768
-6
lines changed

integration-tests/kafka-devservices/pom.xml

Lines changed: 35 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,16 @@
5757
<artifactId>quarkus-junit5</artifactId>
5858
<scope>test</scope>
5959
</dependency>
60+
<dependency>
61+
<groupId>io.quarkus</groupId>
62+
<artifactId>quarkus-junit5-internal</artifactId>
63+
<scope>test</scope>
64+
</dependency>
65+
<dependency>
66+
<groupId>io.quarkus</groupId>
67+
<artifactId>quarkus-devservices-common</artifactId>
68+
<scope>test</scope>
69+
</dependency>
6070
<dependency>
6171
<groupId>io.rest-assured</groupId>
6272
<artifactId>rest-assured</artifactId>
@@ -205,7 +215,31 @@
205215
<configuration>
206216
<skip>false</skip>
207217
</configuration>
208-
</plugin>
218+
<executions>
219+
<execution>
220+
<id>default-test</id>
221+
<goals>
222+
<goal>test</goal>
223+
</goals>
224+
<configuration>
225+
<excludes>
226+
<exclude>**/continuoustesting/**/*.java</exclude>
227+
</excludes>
228+
</configuration>
229+
</execution>
230+
<execution>
231+
<id>devmode-test</id>
232+
<goals>
233+
<goal>test</goal>
234+
</goals>
235+
<configuration>
236+
<includes>
237+
<include>**/continuoustesting/**/*.java</include>
238+
</includes>
239+
</configuration>
240+
</execution>
241+
</executions>
242+
</plugin>
209243
<plugin>
210244
<artifactId>maven-failsafe-plugin</artifactId>
211245
<configuration>

integration-tests/kafka-devservices/src/main/java/io/quarkus/it/kafka/KafkaAdminManager.java

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ void cleanup() {
4141
}
4242

4343
public int partitions(String topic) {
44+
4445
TopicDescription topicDescription;
4546
try {
4647
Map<String, TopicDescription> partitions = admin.describeTopics(Collections.singletonList(topic))
@@ -55,4 +56,15 @@ public int partitions(String topic) {
5556
return topicDescription.partitions().size();
5657
}
5758

59+
int port() throws InterruptedException, ExecutionException {
60+
return admin.describeCluster().controller().get().port();
61+
}
62+
63+
String image() throws InterruptedException, ExecutionException {
64+
// By observation, the red panda does not return anything for the supported features call
65+
// It would be nice to have a more robust check, but hopefully this fragile check is good enough
66+
boolean isRedPanda = admin.describeFeatures().featureMetadata().get().supportedFeatures().size() == 0;
67+
return isRedPanda ? "redpanda" : "kafka-native";
68+
}
69+
5870
}

integration-tests/kafka-devservices/src/main/java/io/quarkus/it/kafka/KafkaEndpoint.java

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
package io.quarkus.it.kafka;
22

3+
import java.util.concurrent.ExecutionException;
4+
35
import jakarta.inject.Inject;
46
import jakarta.ws.rs.GET;
57
import jakarta.ws.rs.Path;
@@ -16,4 +18,16 @@ public class KafkaEndpoint {
1618
public Integer partitions(@PathParam("topic") String topic) {
1719
return admin.partitions(topic);
1820
}
21+
22+
@GET
23+
@Path("/port")
24+
public Integer partitions() throws ExecutionException, InterruptedException {
25+
return admin.port();
26+
}
27+
28+
@GET
29+
@Path("/image")
30+
public String image() throws ExecutionException, InterruptedException {
31+
return admin.image();
32+
}
1933
}

integration-tests/kafka-devservices/src/main/resources/application.properties

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,3 +9,6 @@ quarkus.kafka.devservices.provider=kafka-native
99
quarkus.kafka.devservices.topic-partitions.test=2
1010
quarkus.kafka.devservices.topic-partitions.test-consumer=3
1111
quarkus.kafka.devservices.topic-partitions-timeout=4S
12+
13+
# When running this project itself in dev or test mode, don't try and layer in the dev mode tests
14+
quarkus.test.exclude-pattern=io.quarkus.it.kafka.continuoustesting.*
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
package io.quarkus.it.kafka;
2+
3+
import java.util.concurrent.ExecutionException;
4+
5+
import jakarta.inject.Inject;
6+
import jakarta.ws.rs.GET;
7+
import jakarta.ws.rs.Path;
8+
import jakarta.ws.rs.PathParam;
9+
10+
@Path("/kafka")
11+
public class BundledEndpoint {
12+
13+
@Inject
14+
KafkaAdminManager admin;
15+
16+
@GET
17+
@Path("/partitions/{topic}")
18+
public Integer partitions(@PathParam("topic") String topic) {
19+
return admin.partitions(topic);
20+
}
21+
22+
@GET
23+
@Path("/port")
24+
public Integer port() throws ExecutionException, InterruptedException {
25+
return admin.port();
26+
}
27+
}
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
package io.quarkus.it.kafka;
2+
3+
import org.hamcrest.Matchers;
4+
import org.junit.jupiter.api.Assertions;
5+
import org.junit.jupiter.api.DisplayName;
6+
import org.junit.jupiter.api.Test;
7+
8+
import io.quarkus.it.kafka.devservices.profiles.DevServicesCustomPortProfile;
9+
import io.quarkus.test.junit.QuarkusTest;
10+
import io.quarkus.test.junit.TestProfile;
11+
import io.quarkus.test.ports.SocketKit;
12+
import io.restassured.RestAssured;
13+
14+
@QuarkusTest
15+
@TestProfile(DevServicesCustomPortProfile.class)
16+
public class DevServicesKafkaCustomPortITest {
17+
18+
@Test
19+
@DisplayName("should start kafka container with the given custom port")
20+
public void shouldStartKafkaContainer() {
21+
Assertions.assertTrue(SocketKit.isPortAlreadyUsed(5050));
22+
RestAssured.when().get("/kafka/port").then().body(Matchers.is("5050"));
23+
}
24+
25+
@Test
26+
public void shouldBeCorrectImage() {
27+
RestAssured.when().get("/kafka/image").then().body(Matchers.is("kafka-native"));
28+
}
29+
30+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
package io.quarkus.it.kafka;
2+
3+
import org.hamcrest.Matchers;
4+
import org.junit.jupiter.api.Assertions;
5+
import org.junit.jupiter.api.Disabled;
6+
import org.junit.jupiter.api.DisplayName;
7+
import org.junit.jupiter.api.Test;
8+
9+
import io.quarkus.it.kafka.devservices.profiles.DevServicesCustomPortReusableServiceProfile;
10+
import io.quarkus.test.junit.QuarkusTest;
11+
import io.quarkus.test.junit.TestProfile;
12+
import io.quarkus.test.ports.SocketKit;
13+
import io.restassured.RestAssured;
14+
15+
@Disabled("https://github.com/quarkusio/quarkus/issues/47627")
16+
@QuarkusTest
17+
@TestProfile(DevServicesCustomPortReusableServiceProfile.class)
18+
public class DevServicesKafkaCustomPortReusableServiceITest {
19+
20+
@Test
21+
@DisplayName("should start kafka container with the given custom port")
22+
public void shouldStartKafkaContainer() {
23+
// We could strengthen this test to make sure the container is the same as seen by other tests, but it's hard since we won't know the order
24+
Assertions.assertTrue(SocketKit.isPortAlreadyUsed(5050));
25+
RestAssured.when().get("/kafka/port").then().body(Matchers.is("5050"));
26+
}
27+
28+
}
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
package io.quarkus.it.kafka;
2+
3+
import org.hamcrest.Matchers;
4+
import org.junit.jupiter.api.Assertions;
5+
import org.junit.jupiter.api.Disabled;
6+
import org.junit.jupiter.api.DisplayName;
7+
import org.junit.jupiter.api.Test;
8+
9+
import io.quarkus.it.kafka.devservices.profiles.DevServicesNonUniquePortProfile;
10+
import io.quarkus.test.junit.QuarkusTest;
11+
import io.quarkus.test.junit.TestProfile;
12+
import io.quarkus.test.ports.SocketKit;
13+
import io.restassured.RestAssured;
14+
15+
@Disabled("https://github.com/quarkusio/quarkus/issues/47627")
16+
@QuarkusTest
17+
@TestProfile(DevServicesNonUniquePortProfile.class)
18+
public class DevServicesKafkaNonUniquePortITest {
19+
20+
@Test
21+
@DisplayName("should start kafka container with the given custom port")
22+
public void shouldStartKafkaContainer() {
23+
Assertions.assertTrue(SocketKit.isPortAlreadyUsed(5050));
24+
RestAssured.when().get("/kafka/port").then().body(Matchers.is("5050"));
25+
}
26+
27+
@Test
28+
public void shouldBeCorrectImage() {
29+
RestAssured.when().get("/kafka/image").then().body(Matchers.is("redpanda"));
30+
}
31+
32+
}

0 commit comments

Comments
 (0)