Skip to content

Commit e8dad9e

Browse files
authored
Publish the spring-pulsar-test module (#600)
This commit makes the spring-pulsar-test module available externally. Additionally: * Add missing package-info.java in several packages * Update doc on how to use PulsarTestContainerSupport
1 parent 32739c3 commit e8dad9e

File tree

10 files changed

+96
-6
lines changed

10 files changed

+96
-6
lines changed

README.adoc

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,8 @@ Provides the API to access Apache Pulsar using a Reactive client.
9898
=== spring-pulsar-sample-apps
9999
Provides sample applications to illustrate Spring for Apache Pulsar functionality as well as provide ability for quick manual verification during development.
100100

101+
=== spring-pulsar-test
102+
Provides utilities to help with testing Spring for Apache Pulsar applications.
101103

102104
== License
103105
Spring for Apache Pulsar is Open Source software released under the https://www.apache.org/licenses/LICENSE-2.0.html[Apache 2.0 license].

spring-pulsar-docs/src/main/antora/modules/ROOT/pages/reference/testing-applications.adoc

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,3 +44,39 @@ List<Message<String>> messages = PulsarConsumerTestUtil.consumeMessages(consumer
4444
.until(ConsumedMessagesConditions.atLeastOneMessageMatches("boom"))
4545
.get();
4646
----
47+
48+
== PulsarTestContainerSupport
49+
50+
The `org.springframework.pulsar.test.support.PulsarTestContainerSupport` interface provides a static Pulsar Testcontainer.
51+
When using Junit Jupiter, the container is automatically started once per test class via `@BeforeAll` annotation.
52+
53+
The following example shows how you can use the container support in a `@SpringBootTest` in conjunction with the previously mentioned `PulsarConsumerTestUtil`.
54+
55+
[source,java,indent=0,subs="verbatim"]
56+
----
57+
@SpringBootTest
58+
class MyApplicationTests implements PulsarTestContainerSupport {
59+
60+
@DynamicPropertySource
61+
static void pulsarProperties(DynamicPropertyRegistry registry) {
62+
registry.add("spring.pulsar.client.service-url", PULSAR_CONTAINER::getPulsarBrokerUrl);
63+
registry.add("spring.pulsar.admin.service-url", PULSAR_CONTAINER::getHttpServiceUrl);
64+
}
65+
66+
@Test
67+
void sendAndReceiveWorksAsExpected(
68+
@Autowired PulsarTemplate<String> template,
69+
@Autowired PulsarConsumerFactory<String> consumerFactory) {
70+
var topic = "some-topic";
71+
var msg = "foo-5150";
72+
template.send(topic, msg);
73+
var matchedUsers = PulsarConsumerTestUtil.consumeMessages(consumerFactory)
74+
.fromTopic(topic)
75+
.withSchema(Schema.STRING)
76+
.awaitAtMost(Duration.ofSeconds(2))
77+
.until(ConsumedMessagesConditions.atLeastOneMessageMatches(msg))
78+
.get();
79+
assertThat(matchedUsers).hasSize(1);
80+
}
81+
}
82+
----

spring-pulsar-docs/src/main/antora/modules/ROOT/pages/whats-new.adoc

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,3 +21,7 @@ The APIs provided by the framework no longer throw the checked `PulsarClientExce
2121

2222
WARNING: If you were previously catching or rethrowing `PulsarClientException` just to appease the compiler and were not actually handling the exception, you can simply remove your `catch` or `throws` clause.
2323
If you were actually handling the exception then you will need to replace `PulsarClientException` with `PulsarException` in your catch clause.
24+
25+
=== Testing support
26+
The `spring-pulsar-test` module is now available to help test your Spring for Apache Pulsar applications.
27+
See xref:./reference/testing-applications.adoc#testing-applications[Testing Applications] for more details.
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
/**
2+
* Package containing Reactive AOT runtime hints used by the framework.
3+
*/
4+
@NonNullApi
5+
@NonNullFields
6+
package org.springframework.pulsar.reactive.aot;
7+
8+
import org.springframework.lang.NonNullApi;
9+
import org.springframework.lang.NonNullFields;
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
/**
2+
* Package containing support classes for processing Pulsar messages.
3+
*/
4+
@NonNullApi
5+
@NonNullFields
6+
package org.springframework.pulsar.reactive.support;
7+
8+
import org.springframework.lang.NonNullApi;
9+
import org.springframework.lang.NonNullFields;

spring-pulsar-test/spring-pulsar-test.gradle

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
plugins {
2-
id 'org.springframework.pulsar.spring-unpublished-module'
2+
id 'org.springframework.pulsar.spring-module'
33
}
44

5-
description = 'Spring Pulsar Test Module'
5+
description = 'Spring Pulsar Test Utilities Module'
66

77
dependencies {
88
implementation 'org.junit.jupiter:junit-jupiter-api'

spring-pulsar-test/src/main/java/org/springframework/pulsar/test/support/PulsarTestContainerSupport.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,10 @@ public interface PulsarTestContainerSupport {
3131

3232
PulsarContainer PULSAR_CONTAINER = new PulsarContainer(getPulsarImage());
3333

34+
static DockerImageName getPulsarImage() {
35+
return DockerImageName.parse("apachepulsar/pulsar:latest");
36+
}
37+
3438
@BeforeAll
3539
static void startContainer() {
3640
PULSAR_CONTAINER.start();
@@ -40,10 +44,6 @@ static String getPulsarBrokerUrl() {
4044
return PULSAR_CONTAINER.getPulsarBrokerUrl();
4145
}
4246

43-
static DockerImageName getPulsarImage() {
44-
return DockerImageName.parse("apachepulsar/pulsar:3.2.0");
45-
}
46-
4747
static String getHttpServiceUrl() {
4848
return PULSAR_CONTAINER.getHttpServiceUrl();
4949
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
/**
2+
* Package containing model classes to ease testing Spring for Apache Pulsar applications.
3+
* @since 1.1.0
4+
*/
5+
@NonNullApi
6+
@NonNullFields
7+
package org.springframework.pulsar.test.support.model;
8+
9+
import org.springframework.lang.NonNullApi;
10+
import org.springframework.lang.NonNullFields;
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
/**
2+
* Package containing convenience utilities for testing Spring for Apache Pulsar
3+
* applications.
4+
* @since 1.1.0
5+
*/
6+
@NonNullApi
7+
@NonNullFields
8+
package org.springframework.pulsar.test.support;
9+
10+
import org.springframework.lang.NonNullApi;
11+
import org.springframework.lang.NonNullFields;
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
/**
2+
* Package containing AOT runtime hints used by the framework.
3+
*/
4+
@NonNullApi
5+
@NonNullFields
6+
package org.springframework.pulsar.aot;
7+
8+
import org.springframework.lang.NonNullApi;
9+
import org.springframework.lang.NonNullFields;

0 commit comments

Comments
 (0)