Skip to content

Commit 9497f3d

Browse files
committed
Polish "Combine Pulsar smoke tests"
See gh-37196
1 parent eacf92b commit 9497f3d

File tree

3 files changed

+32
-26
lines changed

3 files changed

+32
-26
lines changed

spring-boot-tests/spring-boot-smoke-tests/spring-boot-smoke-test-pulsar/src/main/java/smoketest/pulsar/ImperativeAppConfig.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@
3131
@Profile("smoketest.pulsar.imperative")
3232
class ImperativeAppConfig {
3333

34-
private static final Log LOG = LogFactory.getLog(ImperativeAppConfig.class);
34+
private static final Log logger = LogFactory.getLog(ImperativeAppConfig.class);
3535

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

@@ -45,14 +45,14 @@ ApplicationRunner sendMessagesToPulsarTopic(PulsarTemplate<SampleMessage> templa
4545
return (args) -> {
4646
for (int i = 0; i < 10; i++) {
4747
template.send(TOPIC, new SampleMessage(i, "message:" + i));
48-
LOG.info("++++++PRODUCE IMPERATIVE:(" + i + ")------");
48+
logger.info("++++++PRODUCE IMPERATIVE:(" + i + ")------");
4949
}
5050
};
5151
}
5252

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

5858
}

spring-boot-tests/spring-boot-smoke-tests/spring-boot-smoke-test-pulsar/src/main/java/smoketest/pulsar/ReactiveAppConfig.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@
3434
@Profile("smoketest.pulsar.reactive")
3535
class ReactiveAppConfig {
3636

37-
private static final Log LOG = LogFactory.getLog(ReactiveAppConfig.class);
37+
private static final Log logger = LogFactory.getLog(ReactiveAppConfig.class);
3838

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

@@ -49,14 +49,14 @@ ApplicationRunner sendMessagesToPulsarTopic(ReactivePulsarTemplate<SampleMessage
4949
.map((i) -> new SampleMessage(i, "message:" + i))
5050
.map(MessageSpec::of)
5151
.as((msgs) -> template.send(TOPIC, msgs))
52-
.doOnNext((sendResult) -> LOG
52+
.doOnNext((sendResult) -> logger
5353
.info("++++++PRODUCE REACTIVE:(" + sendResult.getMessageSpec().getValue().id() + ")------"))
5454
.subscribe();
5555
}
5656

5757
@ReactivePulsarListener(topics = TOPIC)
5858
Mono<Void> consumeMessagesFromPulsarTopic(SampleMessage msg) {
59-
LOG.info("++++++CONSUME REACTIVE:(" + msg.id() + ")------");
59+
logger.info("++++++CONSUME REACTIVE:(" + msg.id() + ")------");
6060
return Mono.empty();
6161
}
6262

spring-boot-tests/spring-boot-smoke-tests/spring-boot-smoke-test-pulsar/src/test/java/smoketest/pulsar/SamplePulsarApplicationTests.java

Lines changed: 26 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -44,48 +44,54 @@
4444
class SamplePulsarApplicationTests {
4545

4646
@Container
47-
static final PulsarContainer PULSAR_CONTAINER = new PulsarContainer(DockerImageNames.pulsar())
48-
.withStartupAttempts(2)
47+
static final PulsarContainer container = new PulsarContainer(DockerImageNames.pulsar()).withStartupAttempts(2)
4948
.withStartupTimeout(Duration.ofMinutes(3));
5049

5150
@DynamicPropertySource
5251
static void pulsarProperties(DynamicPropertyRegistry registry) {
53-
registry.add("spring.pulsar.client.service-url", PULSAR_CONTAINER::getPulsarBrokerUrl);
54-
registry.add("spring.pulsar.admin.service-url", PULSAR_CONTAINER::getHttpServiceUrl);
52+
registry.add("spring.pulsar.client.service-url", container::getPulsarBrokerUrl);
53+
registry.add("spring.pulsar.admin.service-url", container::getHttpServiceUrl);
5554
}
5655

57-
@Nested
58-
@SpringBootTest
59-
@ActiveProfiles("smoketest.pulsar.imperative")
60-
class ImperativeApp {
56+
abstract class PulsarApplication {
57+
58+
private final String type;
59+
60+
PulsarApplication(String type) {
61+
this.type = type;
62+
}
6163

6264
@Test
6365
void appProducesAndConsumesMessages(CapturedOutput output) {
6466
List<String> expectedOutput = new ArrayList<>();
6567
IntStream.range(0, 10).forEachOrdered((i) -> {
66-
expectedOutput.add("++++++PRODUCE IMPERATIVE:(" + i + ")------");
67-
expectedOutput.add("++++++CONSUME IMPERATIVE:(" + i + ")------");
68+
expectedOutput.add("++++++PRODUCE %s:(%s)------".formatted(this.type, i));
69+
expectedOutput.add("++++++CONSUME %s:(%s)------".formatted(this.type, i));
6870
});
6971
Awaitility.waitAtMost(Duration.ofSeconds(30))
7072
.untilAsserted(() -> assertThat(output).contains(expectedOutput));
7173
}
7274

7375
}
7476

77+
@Nested
78+
@SpringBootTest
79+
@ActiveProfiles("smoketest.pulsar.imperative")
80+
class ImperativePulsarApplication extends PulsarApplication {
81+
82+
ImperativePulsarApplication() {
83+
super("IMPERATIVE");
84+
}
85+
86+
}
87+
7588
@Nested
7689
@SpringBootTest
7790
@ActiveProfiles("smoketest.pulsar.reactive")
78-
class ReactiveApp {
91+
class ReactivePulsarApplication extends PulsarApplication {
7992

80-
@Test
81-
void appProducesAndConsumesMessagesReactively(CapturedOutput output) {
82-
List<String> expectedOutput = new ArrayList<>();
83-
IntStream.range(0, 10).forEachOrdered((i) -> {
84-
expectedOutput.add("++++++PRODUCE REACTIVE:(" + i + ")------");
85-
expectedOutput.add("++++++CONSUME REACTIVE:(" + i + ")------");
86-
});
87-
Awaitility.waitAtMost(Duration.ofSeconds(30))
88-
.untilAsserted(() -> assertThat(output).contains(expectedOutput));
93+
ReactivePulsarApplication() {
94+
super("REACTIVE");
8995
}
9096

9197
}

0 commit comments

Comments
 (0)