-
Notifications
You must be signed in to change notification settings - Fork 29
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
Provide a sample application using Spanner emulator #515
Comments
@magiccrafter Which authentication methods have you tried -- service account or default credentials? Does this sample work for you while logged in with Application Default Credentials? Having a sample going against the emulator is a good idea. |
@elefeint Thanks for the quick reply. I've checked all samples in |
I've added |
You would also have to set up an environment variable Upvote #200 for allowing programmatic customization of emulator. |
@elefeint Splendid. Many thanks for this hint. It works now. I was misled by this example: https://github.com/saturnism/testcontainers-gcloud-examples/blob/main/springboot/spanner-example/src/test/java/com/example/springboot/spanner/SpannerIntegrationTests.java |
Spring Cloud GCP already has the change that's needed in #200, so a configuration property is sufficient there. As it happens, our team supports both projects. |
Here is the workaround I came up with to bypass the requirement for SPANNER_EMULATOR_HOST env variable prior to the integration tests run: @Testcontainers
@ExtendWith(SystemStubsExtension.class)
@ExtendWith(SpringExtension.class)
@SpringBootTest
@ActiveProfiles("it")
@DirtiesContext
public class SpannerIT {
static final String PROJECT_ID = "nv-local";
static final String INSTANCE_ID = "test-instance";
static final String DATABASE_NAME = "trades";
@Container
private static final SpannerEmulatorContainer spannerContainer =
new SpannerEmulatorContainer(
DockerImageName.parse("gcr.io/cloud-spanner-emulator/emulator").withTag("1.4.1"));
@SystemStub
private static EnvironmentVariables environmentVariables;
@Autowired
ConnectionFactory connectionFactory;
@DynamicPropertySource
static void properties(DynamicPropertyRegistry r) {
environmentVariables.set("SPANNER_EMULATOR_HOST", spannerContainer.getEmulatorGrpcEndpoint());
r.add("spring.r2dbc.url", () -> "r2dbc:cloudspanner://" +
"/projects/" + PROJECT_ID + "/instances/" + INSTANCE_ID + "/databases/" + DATABASE_NAME);
} This way, we can have the Spanner emulator in Testcontainers without starting the spanner emulator separately and mapping a concrete port. The complete source code can be found here. @elefeint Many thanks for pointing out the direction. After successfully embedding the above in my POC app, I will contribute a different sample with the above setup. It is excellent that the spanner emulator doesn't have to be running to write or run integration tests locally or anywhere else. |
That's very cool, thank you! |
Hi,
I'm getting the following exception after running a simple integration test. I've tried various combinations and I always hit the same error. I'm not sure if it is a configuration issue on my end or a bug since the information during the debugging was not sufficient to come up to a conclusion on what exactly the problem is.
It would be super beneficial if there was a sample app using Spanner + Spring Boot + R2DBC + Testcontainers (Spanner Emulator). The same way we have it for Postgres for example.
I've created this simple minimalistic app with just the dependencies mentioned above to narrow down the perimeter:
https://github.com/magiccrafter/spanner-spring-boot-r2jdbc-app
I've followed the Credentials section in the README without luck.
https://github.com/GoogleCloudPlatform/cloud-spanner-r2dbc#authentication
The text was updated successfully, but these errors were encountered: