Skip to content

Commit

Permalink
Fix custom test PulsarProducerFactory
Browse files Browse the repository at this point in the history
Spring Pulsar 1.1.x introduced a new method `getPulsarClient`
on `PulsarProducerFactory` and the PulsarBinderIntegrationTests
has a custom factory that must be updated in order to run
on both Pulsar 1.0.x and 1.1.x (i.e. Spring Boot 3.2.x and 3.3.x).
  • Loading branch information
onobc authored Apr 15, 2024
1 parent 3298d0d commit 3d679c4
Showing 1 changed file with 19 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
import java.util.function.Supplier;

import org.apache.pulsar.client.api.Producer;
import org.apache.pulsar.client.api.PulsarClient;
import org.apache.pulsar.client.api.Schema;
import org.apache.pulsar.client.impl.schema.JSONSchema;
import org.apache.pulsar.common.schema.KeyValue;
Expand Down Expand Up @@ -637,8 +638,8 @@ public Consumer<String> textLogger() {
static class BinderAndBindingPropsTestConfig {

@Bean
TrackingProducerFactoryBeanPostProcessor trackingProducerFactory() {
return new TrackingProducerFactoryBeanPostProcessor();
TrackingProducerFactoryBeanPostProcessor trackingProducerFactory(PulsarClient pulsarClient) {
return new TrackingProducerFactoryBeanPostProcessor(pulsarClient);
}

@Bean
Expand All @@ -650,10 +651,16 @@ TrackingConsumerFactoryBeanPostProcessor trackingConsumerFactory() {

static class TrackingProducerFactoryBeanPostProcessor implements BeanPostProcessor {

private final PulsarClient pulsarClient;

TrackingProducerFactoryBeanPostProcessor(PulsarClient pulsarClient) {
this.pulsarClient = pulsarClient;
}

@Override
public Object postProcessAfterInitialization(Object bean, String beanName) throws BeansException {
if (bean instanceof DefaultPulsarProducerFactory defaultFactory) {
return new TrackingProducerFactory(defaultFactory);
return new TrackingProducerFactory(defaultFactory, this.pulsarClient);
}
return bean;
}
Expand All @@ -664,10 +671,18 @@ static class TrackingProducerFactory implements PulsarProducerFactory<String> {

private final DefaultPulsarProducerFactory<String> trackedProducerFactory;

private final PulsarClient pulsarClient;

List<Producer<String>> producersCreated = new ArrayList<>();

TrackingProducerFactory(DefaultPulsarProducerFactory<String> trackedProducerFactory) {
TrackingProducerFactory(DefaultPulsarProducerFactory<String> trackedProducerFactory, PulsarClient pulsarClient) {
this.trackedProducerFactory = trackedProducerFactory;
this.pulsarClient = pulsarClient;
}

// This is required in PulsarProducerFactory in Spring Pulsar 1.1.x (i.e. Spring Boot 3.3.x)
public PulsarClient getPulsarClient() {
return this.pulsarClient;
}

@Override
Expand Down

0 comments on commit 3d679c4

Please sign in to comment.