Skip to content

Commit

Permalink
Add Pulsar Binder to Spring Cloud Stream
Browse files Browse the repository at this point in the history
This commit ensures the Spring Cloud Stream Pulsar binder dependency is
automatically added when the user chooses Spring Boot >= 3.2.0-M3 and
adds the Pulsar and Cloud Stream dependencies.

See gh-1322
  • Loading branch information
onobc authored and snicoll committed Oct 23, 2023
1 parent 11e3ed3 commit 748148f
Show file tree
Hide file tree
Showing 2 changed files with 76 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,11 @@ public void customize(Build build) {
.add("cloud-stream-binder-kafka", "org.springframework.cloud", "spring-cloud-stream-binder-kafka",
DependencyScope.COMPILE);
}
if (isSpringBoot3xWithPulsarSupport() && hasDependency("pulsar", build)) {
build.dependencies()
.add("cloud-stream-binder-pulsar", "org.springframework.cloud", "spring-cloud-stream-binder-pulsar",
DependencyScope.COMPILE);
}
}
// Spring Cloud Stream specific
if (hasDependency("cloud-stream", build)) {
Expand Down Expand Up @@ -92,4 +97,9 @@ protected boolean isSpringBoot3x() {
return platformVersion.compareTo(Version.parse("3.0.0-M1")) > 0;
}

protected boolean isSpringBoot3xWithPulsarSupport() {
Version platformVersion = this.description.getPlatformVersion();
return platformVersion.compareTo(Version.parse("3.2.0-M3")) >= 0;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
*
* @author Stephane Nicoll
* @author Brian Clozel
* @author Chris Bono
*/
class SpringCloudStreamBuildCustomizerTests extends AbstractExtensionTests {

Expand All @@ -43,6 +44,9 @@ class SpringCloudStreamBuildCustomizerTests extends AbstractExtensionTests {
private static final Dependency KAFKA_STREAMS_BINDER = Dependency.withId("cloud-stream-binder-kafka-streams",
"org.springframework.cloud", "spring-cloud-stream-binder-kafka-streams");

private static final Dependency PULSAR_BINDER = Dependency.withId("cloud-stream-binder-pulsar",
"org.springframework.cloud", "spring-cloud-stream-binder-pulsar");

private static final Dependency RABBIT_BINDER = Dependency.withId("cloud-stream-binder-rabbit",
"org.springframework.cloud", "spring-cloud-stream-binder-rabbit");

Expand Down Expand Up @@ -85,6 +89,19 @@ void springCloudStreamWithKafkaStreams(Version springBootVersion, Dependency tes
.hasDependenciesSize(5);
}

@ParameterizedTest
@MethodSource("springCloudStreamWithPulsarArguments")
void springCloudStreamWithPulsar(Version springBootVersion, Dependency testDependency) {
ProjectRequest request = createProjectRequest("cloud-stream", "pulsar");
request.setBootVersion(springBootVersion.toString());
assertThat(mavenPom(request)).hasDependency(getDependency("cloud-stream"))
.hasDependency(getDependency("pulsar"))
.hasDependency(PULSAR_BINDER)
.hasDependency(Dependency.createSpringBootStarter("test", Dependency.SCOPE_TEST))
.hasDependency(testDependency)
.hasDependenciesSize(5);
}

@ParameterizedTest
@MethodSource("springCloudStreamArguments")
void springCloudStreamWithAllBinders(Version springBootVersion, Dependency testDependency) {
Expand All @@ -103,20 +120,27 @@ void springCloudStreamWithAllBinders(Version springBootVersion, Dependency testD
}

@ParameterizedTest
@MethodSource("springCloudStreamArguments")
void springCloudBusWithRabbit(Version springBootVersion, Dependency testDependency) {
ProjectRequest request = createProjectRequest("cloud-bus", "amqp");
@MethodSource("springCloudStreamWithPulsarArguments")
void springCloudStreamWithAllBindersInBoot32x(Version springBootVersion, Dependency testDependency) {
ProjectRequest request = createProjectRequest("cloud-stream", "amqp", "kafka", "kafka-streams", "pulsar");
request.setBootVersion(springBootVersion.toString());
assertThat(mavenPom(request)).hasDependency(getDependency("cloud-bus"))
assertThat(mavenPom(request)).hasDependency(getDependency("cloud-stream"))
.hasDependency(getDependency("amqp"))
.hasDependency(getDependency("kafka"))
.hasDependency(getDependency("kafka-streams"))
.hasDependency(getDependency("pulsar"))
.hasDependency(RABBIT_BINDER)
.hasDependency(KAFKA_BINDER)
.hasDependency(KAFKA_STREAMS_BINDER)
.hasDependency(PULSAR_BINDER)
.hasDependency(Dependency.createSpringBootStarter("test", Dependency.SCOPE_TEST))
.hasDependenciesSize(5);
.hasDependency(testDependency)
.hasDependenciesSize(13);
}

@ParameterizedTest
@MethodSource("springCloudStreamArguments")
void springCloudBusWithKafka(Version springBootVersion, Dependency testDependency) {
void springCloudBusWithRabbit(Version springBootVersion, Dependency ignoredTestDependency) {
ProjectRequest request = createProjectRequest("cloud-bus", "amqp");
request.setBootVersion(springBootVersion.toString());
assertThat(mavenPom(request)).hasDependency(getDependency("cloud-bus"))
Expand All @@ -128,17 +152,43 @@ void springCloudBusWithKafka(Version springBootVersion, Dependency testDependenc

@ParameterizedTest
@MethodSource("springCloudStreamArguments")
void springCloudBusWithAllBinders(Version springBootVersion, Dependency testDependency) {
ProjectRequest request = createProjectRequest("cloud-bus", "amqp", "kafka", "kafka-streams");
void springCloudBusWithKafka(Version springBootVersion, Dependency ignoredTestDependency) {
ProjectRequest request = createProjectRequest("cloud-bus", "kafka");
request.setBootVersion(springBootVersion.toString());
assertThat(mavenPom(request)).hasDependency(getDependency("cloud-bus"))
.hasDependency(getDependency("kafka"))
.hasDependency(KAFKA_BINDER)
.hasDependency(Dependency.createSpringBootStarter("test", Dependency.SCOPE_TEST))
.hasDependenciesSize(5);
}

@ParameterizedTest
@MethodSource("springCloudStreamWithPulsarArguments")
void springCloudBusWithPulsar(Version springBootVersion, Dependency ignoredTestDependency) {
ProjectRequest request = createProjectRequest("cloud-bus", "pulsar");
request.setBootVersion(springBootVersion.toString());
assertThat(mavenPom(request)).hasDependency(getDependency("cloud-bus"))
.hasDependency(getDependency("pulsar"))
.hasDependency(PULSAR_BINDER)
.hasDependency(Dependency.createSpringBootStarter("test", Dependency.SCOPE_TEST))
.hasDependenciesSize(4);
}

@ParameterizedTest
@MethodSource("springCloudStreamWithPulsarArguments")
void springCloudBusWithAllBindersInBoot32x(Version springBootVersion, Dependency ignoredTestDependency) {
ProjectRequest request = createProjectRequest("cloud-bus", "amqp", "kafka", "kafka-streams", "pulsar");
request.setBootVersion(springBootVersion.toString());
assertThat(mavenPom(request)).hasDependency(getDependency("cloud-bus"))
.hasDependency(getDependency("amqp"))
.hasDependency(getDependency("kafka"))
.hasDependency(getDependency("kafka-streams"))
.hasDependency(getDependency("pulsar"))
.hasDependency(RABBIT_BINDER)
.hasDependency(KAFKA_BINDER)
.hasDependency(PULSAR_BINDER)
.hasDependency(Dependency.createSpringBootStarter("test", Dependency.SCOPE_TEST))
.hasDependenciesSize(9);
.hasDependenciesSize(11);
}

@Test
Expand All @@ -159,4 +209,11 @@ private static Stream<Arguments> springCloudStreamArguments() {
Arguments.of(Version.parse("3.0.0"), testBinder));
}

private static Stream<Arguments> springCloudStreamWithPulsarArguments() {
Dependency testBinder = Dependency.withId("cloud-stream-test", "org.springframework.cloud",
"spring-cloud-stream-test-binder", null, Dependency.SCOPE_TEST);
return Stream.of(Arguments.of(Version.parse("3.2.0-M3"), testBinder),
Arguments.of(Version.parse("3.2.0-RC1"), testBinder));
}

}

0 comments on commit 748148f

Please sign in to comment.