Skip to content

Commit

Permalink
Publish the spring-pulsar-test module (#600)
Browse files Browse the repository at this point in the history
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
  • Loading branch information
onobc authored Mar 10, 2024
1 parent 32739c3 commit e8dad9e
Show file tree
Hide file tree
Showing 10 changed files with 96 additions and 6 deletions.
2 changes: 2 additions & 0 deletions README.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -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].
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
----
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Original file line number Diff line number Diff line change
@@ -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;
Original file line number Diff line number Diff line change
@@ -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;
4 changes: 2 additions & 2 deletions spring-pulsar-test/spring-pulsar-test.gradle
Original file line number Diff line number Diff line change
@@ -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'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -40,10 +44,6 @@ static String getPulsarBrokerUrl() {
return PULSAR_CONTAINER.getPulsarBrokerUrl();
}

static DockerImageName getPulsarImage() {
return DockerImageName.parse("apachepulsar/pulsar:3.2.0");
}

static String getHttpServiceUrl() {
return PULSAR_CONTAINER.getHttpServiceUrl();
}
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
Original file line number Diff line number Diff line change
@@ -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;
Original file line number Diff line number Diff line change
@@ -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;

0 comments on commit e8dad9e

Please sign in to comment.