Skip to content

Conversation

wind57
Copy link
Contributor

@wind57 wind57 commented Feb 4, 2025

No description provided.

Signed-off-by: wind57 <[email protected]>
Signed-off-by: wind57 <[email protected]>
Signed-off-by: wind57 <[email protected]>
@@ -49,6 +49,13 @@
</dependency>

<!-- Testing Dependencies -->

<dependency>
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I don't know what you think about this.. In order to properly test that things are indeed fixed, I need this dependency as test scope. It surely looks a bit weird, since the discovery pom is requesting config one, even if it does so for tests only. Let me know your thoughts here please

Copy link
Contributor

Choose a reason for hiding this comment

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

Why does the test need to be in the discovery module?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

In order to reproduce the issue in a test, we need two classes :

  • Fabric8ConfigServerBootstrapper
  • KubernetesConfigDataLocationResolver. Since this one is abstract, we need an implementation, so I chose : Fabric8ConfigDataLocationResolver, thus the maven module spring-cloud-kubernetes-fabric8-config as a test dependency here.

So the test is either here with that test dependency, or I move it to the integration tests project. Though I did not try that, so not sure if extra work would not be needed, but this is the explanation. I hope it makes sense

Copy link
Contributor

Choose a reason for hiding this comment

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

In the unit test could we provide an implementation of KubernetesConfigDataLocationResolver to simulate a real implementation and test it that way?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

ah nice! just did that, thank you

kubernetesClientProperties = context.getBootstrapContext()
.get(KubernetesClientProperties.class)
.withNamespace(namespace);
if (bootstrapContext.isRegistered(PROPERTIES_CLASS) && bootstrapContext.get(PROPERTIES_CLASS) != null) {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

we used to do :

if ( bootstrapContext.isRegistered(PROPERTIES_CLASS) { ... } 

but now, we will do :

bootstrapContext.isRegistered(PROPERTIES_CLASS) && bootstrapContext.get(PROPERTIES_CLASS) != null

.getBeanFactory()
.registerSingleton(name, event.getBootstrapContext().get(cls));

T singleton = event.getBootstrapContext().get(cls);
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I would have missed this one if it was not for the test tbh.

@wind57 wind57 marked this pull request as ready for review February 4, 2025 21:30
@wind57
Copy link
Contributor Author

wind57 commented Feb 4, 2025

@ryanjbaxter ready to be looked at. Thank you

*
* @author wind57
*/
@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT, properties = {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

without the fix, this test fails

@wind57 wind57 requested a review from ryanjbaxter February 5, 2025 13:01
Signed-off-by: wind57 <[email protected]>
@ryanjbaxter ryanjbaxter linked an issue Feb 6, 2025 that may be closed by this pull request
@ryanjbaxter ryanjbaxter merged commit 9518285 into spring-cloud:3.1.x Feb 6, 2025
13 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

NullPointerException on startup
3 participants