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

Disable in-process transport by default and add @AutoConfigureInProcessTransport annotation #88

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

panic08
Copy link
Contributor

@panic08 panic08 commented Jan 1, 2025

Here I have added the AutoConfigureInProcessTransport annotation which should be set over the test where we want in-process transport to be enabled. I also added the class InProcessTransportEnvironmentPostProcessor which implements EnvironmentPostProcessor and where I use AnnotationUtils.findAnnotation to check if the startup class is marked with an annotation or not. If yes, then we need to enable in-process transport and we set spring.grpc.inprocess.enabled=true. I also set matchIfMissing to false in InProcessGrpcServerFactoryAutoConfiguration (ignored as it is by default) so that in-process will default to false.

Closes #77

import org.springframework.grpc.test.LocalGrpcPort;
import org.springframework.test.annotation.DirtiesContext;

@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT,
properties = { "spring.grpc.server.servlet.enabled=false", "spring.grpc.server.port=0" })
@AutoConfigureInProcessTransport
Copy link
Collaborator

Choose a reason for hiding this comment

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

This is wrong? I think we need it to be off in this test.

import org.springframework.grpc.test.LocalGrpcPort;
import org.springframework.test.annotation.DirtiesContext;

@SpringBootTest(webEnvironment = WebEnvironment.RANDOM_PORT, properties = "spring.grpc.server.reactive.enabled=false")
@AutoConfigureInProcessTransport
Copy link
Collaborator

Choose a reason for hiding this comment

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

This is not intended to be an in-process test, I think?


@Target(ElementType.TYPE)
@Retention(RetentionPolicy.RUNTIME)
public @interface AutoConfigureInProcessTransport {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Isn't this supposed to be @ImportAutoConfiguration? Copy the annotations from one of the existing @AutoConfigure* annotations.

import org.springframework.core.env.ConfigurableEnvironment;
import org.springframework.core.env.MapPropertySource;

public class InProcessTransportEnvironmentPostProcessor implements EnvironmentPostProcessor {
Copy link
Collaborator

Choose a reason for hiding this comment

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

I'm not sure this is going to work. Don't we need something that is aware of the test environment? Look at the existing @AutoConfigure* annotations to see how they are implemented.

Copy link
Contributor Author

@panic08 panic08 Jan 2, 2025

Choose a reason for hiding this comment

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

Thanks so much for the tip. I've looked into it more, tested it, and I'd like to say. Could we create an InProcessFactory that will implement ContextCustomizerFactory? That is, make a class like ObservabilityContextCustomizerFactory

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.

Test apps should not use in-process transport
2 participants