Skip to content

Combine Pulsar smoke tests #37196

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ description = "Spring Boot Pulsar smoke test"

dependencies {
implementation(project(":spring-boot-project:spring-boot-starters:spring-boot-starter-pulsar"))
implementation(project(":spring-boot-project:spring-boot-starters:spring-boot-starter-pulsar-reactive"))
testImplementation(project(":spring-boot-project:spring-boot-starters:spring-boot-starter-test"))
testImplementation(project(":spring-boot-project:spring-boot-tools:spring-boot-test-support"))
testImplementation("org.awaitility:awaitility")
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
/*
* Copyright 2012-2023 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package smoketest.pulsar;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

import org.springframework.boot.ApplicationRunner;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Profile;
import org.springframework.pulsar.annotation.PulsarListener;
import org.springframework.pulsar.core.PulsarTemplate;
import org.springframework.pulsar.core.PulsarTopic;

@Configuration(proxyBeanMethods = false)
@Profile("smoketest.pulsar.imperative")
class ImperativeAppConfig {

private static final Log LOG = LogFactory.getLog(ImperativeAppConfig.class);

private static final String TOPIC = "pulsar-smoke-test-topic";

@Bean
PulsarTopic pulsarTestTopic() {
return PulsarTopic.builder(TOPIC).numberOfPartitions(1).build();
}

@Bean
ApplicationRunner sendMessagesToPulsarTopic(PulsarTemplate<SampleMessage> template) {
return (args) -> {
for (int i = 0; i < 10; i++) {
template.send(TOPIC, new SampleMessage(i, "message:" + i));
LOG.info("++++++PRODUCE IMPERATIVE:(" + i + ")------");
}
};
}

@PulsarListener(topics = TOPIC)
void consumeMessagesFromPulsarTopic(SampleMessage msg) {
LOG.info("++++++CONSUME IMPERATIVE:(" + msg.id() + ")------");
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -14,22 +14,29 @@
* limitations under the License.
*/

package smoketest.pulsar.reactive;
package smoketest.pulsar;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.apache.pulsar.reactive.client.api.MessageSpec;
import reactor.core.publisher.Flux;
import reactor.core.publisher.Mono;

import org.springframework.boot.ApplicationRunner;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Profile;
import org.springframework.pulsar.core.PulsarTopic;
import org.springframework.pulsar.reactive.config.annotation.ReactivePulsarListener;
import org.springframework.pulsar.reactive.core.ReactivePulsarTemplate;

@SpringBootApplication
public class SampleReactivePulsarApplication {
@Configuration(proxyBeanMethods = false)
@Profile("smoketest.pulsar.reactive")
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Using the profile approach works well w/ the @ActiveProfiles on the @Nested SBT. I guess the alternative is to use the @SpringBootTest(classes = ... and point directly to a specific app class (imperative or reactive).

class ReactiveAppConfig {

static final String TOPIC = "pulsar-reactive-smoke-test-topic";
private static final Log LOG = LogFactory.getLog(ReactiveAppConfig.class);

private static final String TOPIC = "pulsar-reactive-smoke-test-topic";

@Bean
PulsarTopic pulsarTestTopic() {
Expand All @@ -42,12 +49,15 @@ ApplicationRunner sendMessagesToPulsarTopic(ReactivePulsarTemplate<SampleMessage
.map((i) -> new SampleMessage(i, "message:" + i))
.map(MessageSpec::of)
.as((msgs) -> template.send(TOPIC, msgs))
.doOnNext((sendResult) -> System.out.println("*** PRODUCE: " + sendResult.getMessageId()))
.doOnNext((sendResult) -> LOG
.info("++++++PRODUCE REACTIVE:(" + sendResult.getMessageSpec().getValue().id() + ")------"))
.subscribe();
}

public static void main(String[] args) {
SpringApplication.run(SampleReactivePulsarApplication.class, args);
@ReactivePulsarListener(topics = TOPIC)
Mono<Void> consumeMessagesFromPulsarTopic(SampleMessage msg) {
LOG.info("++++++CONSUME REACTIVE:(" + msg.id() + ")------");
return Mono.empty();
}

}

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -16,35 +16,12 @@

package smoketest.pulsar;

import org.apache.pulsar.client.api.MessageId;

import org.springframework.boot.ApplicationRunner;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.annotation.Bean;
import org.springframework.pulsar.core.PulsarTemplate;
import org.springframework.pulsar.core.PulsarTopic;

@SpringBootApplication
public class SamplePulsarApplication {

static final String TOPIC = "pulsar-smoke-test-topic";

@Bean
PulsarTopic pulsarTestTopic() {
return PulsarTopic.builder(TOPIC).numberOfPartitions(1).build();
}

@Bean
ApplicationRunner sendMessagesToPulsarTopic(PulsarTemplate<SampleMessage> template) {
return (args) -> {
for (int i = 0; i < 10; i++) {
MessageId msgId = template.send(TOPIC, new SampleMessage(i, "message:" + i));
System.out.println("*** PRODUCE: " + msgId);
}
};
}

public static void main(String[] args) {
SpringApplication.run(SamplePulsarApplication.class, args);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1 +1 @@
spring.pulsar.consumer.subscription-initial-position=earliest
spring.pulsar.consumer.subscription.initial-position=earliest
Loading