Skip to content

Re-enable Spring Pulsar interceptor tests #39912

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
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
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,6 @@
import org.apache.pulsar.client.api.ReaderBuilder;
import org.apache.pulsar.client.api.interceptor.ProducerInterceptor;
import org.apache.pulsar.common.schema.SchemaType;
import org.assertj.core.api.InstanceOfAssertFactories;
import org.junit.jupiter.api.Disabled;
import org.junit.jupiter.api.Nested;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.condition.EnabledForJreRange;
Expand Down Expand Up @@ -285,24 +283,29 @@ void injectsExpectedBeans() {
}

@Test
@Disabled("Changes in https://github.com/spring-projects/spring-pulsar/issues/593 prevent introspection of the interceptors")
void whenHasUseDefinedProducerInterceptorInjectsBean() {
<T> void whenHasUseDefinedProducerInterceptorInjectsBean() {
ProducerInterceptor interceptor = mock(ProducerInterceptor.class);
this.contextRunner.withBean("customProducerInterceptor", ProducerInterceptor.class, () -> interceptor)
.run((context) -> assertThat(context).getBean(PulsarTemplate.class)
.extracting("interceptorsCustomizers")
.asInstanceOf(InstanceOfAssertFactories.LIST)
.contains(interceptor));
.run((context) -> {
PulsarTemplate<?> pulsarTemplate = context.getBean(PulsarTemplate.class);
Customizers<ProducerBuilderCustomizer<T>, ProducerBuilder<T>> customizers = Customizers
Copy link
Contributor Author

Choose a reason for hiding this comment

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

@philwebb added this Customizers testing utility to ease the burden of verifying customizers. Basically because they are lambdas we have to execute them and see if they "customized" what we expected them to customizer (and in order). In this case, we know our producer builder customizers are going to call ProducerBuilder.intercept with the specified interceptor.

.of(ProducerBuilder.class, ProducerBuilderCustomizer::customize);
assertThat(customizers.fromField(pulsarTemplate, "interceptorsCustomizers"))
.callsInOrder(ProducerBuilder::intercept, interceptor);
});
}

@Test
@Disabled("Changes in https://github.com/spring-projects/spring-pulsar/issues/593 prevent introspection of the interceptors")
void whenHasUseDefinedProducerInterceptorsInjectsBeansInCorrectOrder() {
this.contextRunner.withUserConfiguration(InterceptorTestConfiguration.class)
.run((context) -> assertThat(context).getBean(PulsarTemplate.class)
.extracting("interceptorsCustomizers")
.asInstanceOf(InstanceOfAssertFactories.LIST)
.containsExactly(context.getBean("interceptorBar"), context.getBean("interceptorFoo")));
<T> void whenHasUseDefinedProducerInterceptorsInjectsBeansInCorrectOrder() {
this.contextRunner.withUserConfiguration(InterceptorTestConfiguration.class).run((context) -> {
ProducerInterceptor interceptorFoo = context.getBean("interceptorFoo", ProducerInterceptor.class);
ProducerInterceptor interceptorBar = context.getBean("interceptorBar", ProducerInterceptor.class);
PulsarTemplate<?> pulsarTemplate = context.getBean(PulsarTemplate.class);
Customizers<ProducerBuilderCustomizer<T>, ProducerBuilder<T>> customizers = Customizers
.of(ProducerBuilder.class, ProducerBuilderCustomizer::customize);
assertThat(customizers.fromField(pulsarTemplate, "interceptorsCustomizers"))
.callsInOrder(ProducerBuilder::intercept, interceptorBar, interceptorFoo);
});
}

@Test
Expand Down