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
This commit is contained in:
Chris Bono
2024-03-10 16:18:14 -05:00
committed by GitHub
parent 32739c3ec2
commit e8dad9e06a
10 changed files with 96 additions and 6 deletions

View File

@@ -98,6 +98,8 @@ Provides the API to access Apache Pulsar using a Reactive client.
=== spring-pulsar-sample-apps
Provides sample applications to illustrate Spring for Apache Pulsar functionality as well as provide ability for quick manual verification during development.
=== spring-pulsar-test
Provides utilities to help with testing Spring for Apache Pulsar applications.
== License
Spring for Apache Pulsar is Open Source software released under the https://www.apache.org/licenses/LICENSE-2.0.html[Apache 2.0 license].

View File

@@ -44,3 +44,39 @@ List<Message<String>> messages = PulsarConsumerTestUtil.consumeMessages(consumer
.until(ConsumedMessagesConditions.atLeastOneMessageMatches("boom"))
.get();
----
== PulsarTestContainerSupport
The `org.springframework.pulsar.test.support.PulsarTestContainerSupport` interface provides a static Pulsar Testcontainer.
When using Junit Jupiter, the container is automatically started once per test class via `@BeforeAll` annotation.
The following example shows how you can use the container support in a `@SpringBootTest` in conjunction with the previously mentioned `PulsarConsumerTestUtil`.
[source,java,indent=0,subs="verbatim"]
----
@SpringBootTest
class MyApplicationTests implements PulsarTestContainerSupport {
@DynamicPropertySource
static void pulsarProperties(DynamicPropertyRegistry registry) {
registry.add("spring.pulsar.client.service-url", PULSAR_CONTAINER::getPulsarBrokerUrl);
registry.add("spring.pulsar.admin.service-url", PULSAR_CONTAINER::getHttpServiceUrl);
}
@Test
void sendAndReceiveWorksAsExpected(
@Autowired PulsarTemplate<String> template,
@Autowired PulsarConsumerFactory<String> consumerFactory) {
var topic = "some-topic";
var msg = "foo-5150";
template.send(topic, msg);
var matchedUsers = PulsarConsumerTestUtil.consumeMessages(consumerFactory)
.fromTopic(topic)
.withSchema(Schema.STRING)
.awaitAtMost(Duration.ofSeconds(2))
.until(ConsumedMessagesConditions.atLeastOneMessageMatches(msg))
.get();
assertThat(matchedUsers).hasSize(1);
}
}
----

View File

@@ -21,3 +21,7 @@ The APIs provided by the framework no longer throw the checked `PulsarClientExce
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.
If you were actually handling the exception then you will need to replace `PulsarClientException` with `PulsarException` in your catch clause.
=== Testing support
The `spring-pulsar-test` module is now available to help test your Spring for Apache Pulsar applications.
See xref:./reference/testing-applications.adoc#testing-applications[Testing Applications] for more details.

View File

@@ -0,0 +1,9 @@
/**
* Package containing Reactive AOT runtime hints used by the framework.
*/
@NonNullApi
@NonNullFields
package org.springframework.pulsar.reactive.aot;
import org.springframework.lang.NonNullApi;
import org.springframework.lang.NonNullFields;

View File

@@ -0,0 +1,9 @@
/**
* Package containing support classes for processing Pulsar messages.
*/
@NonNullApi
@NonNullFields
package org.springframework.pulsar.reactive.support;
import org.springframework.lang.NonNullApi;
import org.springframework.lang.NonNullFields;

View File

@@ -1,8 +1,8 @@
plugins {
id 'org.springframework.pulsar.spring-unpublished-module'
id 'org.springframework.pulsar.spring-module'
}
description = 'Spring Pulsar Test Module'
description = 'Spring Pulsar Test Utilities Module'
dependencies {
implementation 'org.junit.jupiter:junit-jupiter-api'

View File

@@ -31,6 +31,10 @@ public interface PulsarTestContainerSupport {
PulsarContainer PULSAR_CONTAINER = new PulsarContainer(getPulsarImage());
static DockerImageName getPulsarImage() {
return DockerImageName.parse("apachepulsar/pulsar:latest");
}
@BeforeAll
static void startContainer() {
PULSAR_CONTAINER.start();
@@ -40,10 +44,6 @@ public interface PulsarTestContainerSupport {
return PULSAR_CONTAINER.getPulsarBrokerUrl();
}
static DockerImageName getPulsarImage() {
return DockerImageName.parse("apachepulsar/pulsar:3.2.0");
}
static String getHttpServiceUrl() {
return PULSAR_CONTAINER.getHttpServiceUrl();
}

View File

@@ -0,0 +1,10 @@
/**
* Package containing model classes to ease testing Spring for Apache Pulsar applications.
* @since 1.1.0
*/
@NonNullApi
@NonNullFields
package org.springframework.pulsar.test.support.model;
import org.springframework.lang.NonNullApi;
import org.springframework.lang.NonNullFields;

View File

@@ -0,0 +1,11 @@
/**
* Package containing convenience utilities for testing Spring for Apache Pulsar
* applications.
* @since 1.1.0
*/
@NonNullApi
@NonNullFields
package org.springframework.pulsar.test.support;
import org.springframework.lang.NonNullApi;
import org.springframework.lang.NonNullFields;

View File

@@ -0,0 +1,9 @@
/**
* Package containing AOT runtime hints used by the framework.
*/
@NonNullApi
@NonNullFields
package org.springframework.pulsar.aot;
import org.springframework.lang.NonNullApi;
import org.springframework.lang.NonNullFields;