Skip to content
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

No parameter resolver for EmbeddedKafkaZKBroker #2927

Closed
Sh1ftry opened this issue Dec 8, 2023 · 3 comments · Fixed by #2931
Closed

No parameter resolver for EmbeddedKafkaZKBroker #2927

Sh1ftry opened this issue Dec 8, 2023 · 3 comments · Fixed by #2931
Milestone

Comments

@Sh1ftry
Copy link
Contributor

Sh1ftry commented Dec 8, 2023

In what version(s) of Spring for Apache Kafka are you seeing this issue?
3.1.0

Describe the bug

Starting a test without spring context with embeded kafka without kraft enabled and EmbeddedKafkaZKBroker as a test's parameter results in an exception.

No ParameterResolver registered for parameter [org.springframework.kafka.test.EmbeddedKafkaZKBroker broker] in method [public void test.SomeTest.test(org.springframework.kafka.test.EmbeddedKafkaZKBroker)].
org.junit.jupiter.api.extension.ParameterResolutionException: No ParameterResolver registered for parameter [org.springframework.kafka.test.EmbeddedKafkaZKBroker broker] in method [public void test.SomeTest.test(org.springframework.kafka.test.EmbeddedKafkaZKBroker)].
	at java.base/java.util.ArrayList.forEach(ArrayList.java:1511)
	at java.base/java.util.ArrayList.forEach(ArrayList.java:1511)

To Reproduce

import org.junit.jupiter.api.Test;
import org.springframework.kafka.test.EmbeddedKafkaZKBroker;
import org.springframework.kafka.test.context.EmbeddedKafka;

@EmbeddedKafka(kraft = false)
public class SomeTest {

  @Test
  public void test(EmbeddedKafkaZKBroker broker) {}
}

Expected behavior

EmbeddedKafkaZKBroker is resolved properly.

@artembilan
Copy link
Member

Confirmed as a bug.
Looks like EmbeddedKafkaCondition.supportsParameter() must be fixed for something like:

return EmbeddedKafkaBroker.class.isAssignableFrom(parameterContext.getParameter().getType());

Feel free to contribute the fix!

As a workaround you can just use public void test(EmbeddedKafkaBroker broker).

@artembilan artembilan added this to the 3.1.1 milestone Dec 8, 2023
@Sh1ftry
Copy link
Contributor Author

Sh1ftry commented Dec 9, 2023

Thanks for quick response @artembilan. Should the supportsParameter method take into account whether kraft is enabled or not? I guess it shouldn’t support EmbeddedKafkaKraftBroker when kraft is not enabled and it shouldn’t support EmbeddedKafkaZKBroker when kraft is enabled.

@artembilan
Copy link
Member

Sounds reasonable , but if we cannot reach that logic easily in the condition , I wouldn’t spend too much time on that. Rather simple fix as we have discussed before . Or even better to say: let’s fix the bug first! The logic you are asking for could be considered as an improvement afterwards.

Sh1ftry added a commit to Sh1ftry/spring-kafka that referenced this issue Dec 11, 2023
Sh1ftry added a commit to Sh1ftry/spring-kafka that referenced this issue Dec 15, 2023
artembilan pushed a commit that referenced this issue Dec 15, 2023
Fixes: #2927

Starting a test without spring context with Embeded Lafka without `kraft` enabled and `EmbeddedKafkaZKBroker` as a test's parameter results in an exception:
```
No ParameterResolver registered for parameter [org.springframework.kafka.test.EmbeddedKafkaZKBroker broker] in method [public void test.SomeTest.test(org.springframework.kafka.test.EmbeddedKafkaZKBroker)].
org.junit.jupiter.api.extension.ParameterResolutionException: No ParameterResolver registered for parameter [org.springframework.kafka.test.EmbeddedKafkaZKBroker broker] in method [public void test.SomeTest.test(org.springframework.kafka.test.EmbeddedKafkaZKBroker)].
```
For test config:
```
@test
public void test(EmbeddedKafkaZKBroker broker)
```

* Fix `EmbeddedKafkaCondition` to use `EmbeddedKafkaBroker.class.isAssignableFrom(parameterContext.getParameter().getType());` instead of just `parameterContext.getParameter().getType().equals(EmbeddedKafkaBroker.class)`
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants