googleapis / google-cloud-java

Google Cloud Client Library for Java
https://cloud.google.com/java/docs/reference
Apache License 2.0
1.89k stars 1.06k forks source link

FR - Consistent programmatic configurations to use Emulators #7391

Open saturnism opened 3 years ago

saturnism commented 3 years ago

Is your feature request related to a problem? Please describe. Client libraries currently can use emulators by configuring respective environmental variables. However, in the case of dynamically launching emulators during unit/integration tests using JUnit and Testcontainers, each client library needs to be configured programatically. For all of the supported emulators, client library configurations are very different from each other, and mostly not well documented.

See examples:

Client Library Configure Endpoint
Datastore setHost(hostport) + setCredentials
Firestore setHost(hostport) + setCredentials
Spanner setEmulatorHost(hostport)
Pub/Sub setChannelProvider + setCredentialsProvider
Bigtable setChannelProvider + setCredentialsProvider and also newBuilderForEmulator(host, port)

Describe the solution you'd like A consistent way of setting emulator host and auto configures the emulator credentials. Spanner is the cleanest/best example of this, which is simply setEmulatorHost(hostport).

Describe alternatives you've considered

Additional context https://github.com/spring-cloud/spring-cloud-gcp/issues/2589

PeterUlb commented 3 years ago

Additional question regarding this. Pub/Sub Subscriber and Publisher both have a setEndpoint method now. But both are not really useful, since the emulator needs plaintext. Is there any chance to set this NegotiationType on the Builders too? Configuring a channelProvider is not really great. The prod code will not set the channelProvider, so I need to introduce such a bean injection just for the test case, and null for the prod case.