Croway commented on code in PR #29828: URL: https://github.com/apache/camel/pull/29828#discussion_r4584303871
########## test-infra/camel-test-infra-google-firestore/src/main/java/org/apache/camel/test/infra/google/firestore/services/GoogleFirestoreLocalContainerInfraService.java: ########## @@ -0,0 +1,101 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.camel.test.infra.google.firestore.services; + +import org.apache.camel.spi.annotations.InfraService; +import org.apache.camel.test.infra.common.LocalPropertyResolver; +import org.apache.camel.test.infra.common.services.ContainerEnvironmentUtil; +import org.apache.camel.test.infra.common.services.ContainerService; +import org.apache.camel.test.infra.google.common.GoogleProperties; +import org.apache.camel.test.infra.google.common.services.FlociGcpContainer; +import org.apache.camel.test.infra.google.firestore.common.GoogleFirestoreProperties; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +/** + * A local Firestore service on Floci GCP, which the clients reach as an emulator: in plain text, with any credentials. + */ +@InfraService(service = GoogleFirestoreInfraService.class, + description = "Local Google Cloud Firestore service with Floci GCP", + serviceAlias = "google", serviceImplementationAlias = "firestore") +public class GoogleFirestoreLocalContainerInfraService + implements GoogleFirestoreInfraService, ContainerService<FlociGcpContainer> { + + private static final Logger LOG = LoggerFactory.getLogger(GoogleFirestoreLocalContainerInfraService.class); + private static final String DEFAULT_PROJECT_ID = "test-project"; + + private final FlociGcpContainer container; + + public GoogleFirestoreLocalContainerInfraService() { + this(LocalPropertyResolver.getProperty(FlociGcpContainer.class, GoogleProperties.GOOGLE_CONTAINER)); + } + + public GoogleFirestoreLocalContainerInfraService(String imageName) { + container = initContainer(imageName); + String name = ContainerEnvironmentUtil.containerName(this.getClass()); + if (name != null) { + container.withCreateContainerCmdModifier(cmd -> cmd.withName(name)); + } + } + + public GoogleFirestoreLocalContainerInfraService(FlociGcpContainer container) { + this.container = container; + } + + protected FlociGcpContainer initContainer(String imageName) { + return new FlociGcpContainer(imageName, ContainerEnvironmentUtil.isFixedPort(this.getClass())); + } + + @Override + public void registerProperties() { + System.setProperty(GoogleFirestoreProperties.PROJECT_ID, projectId()); + System.setProperty(GoogleFirestoreProperties.ENDPOINT, endpoint()); + } + + @Override + public void initialize() { + container.start(); + + LOG.info("Floci GCP running at address {}", container.serviceAddress()); + + registerProperties(); + } + + @Override + public void shutdown() { + container.stop(); + } + + @Override + public FlociGcpContainer getContainer() { + return container; + } + + /** + * The id of the project: {@code test-project}, as Floci GCP accepts any + */ + @Override + public String projectId() { + return DEFAULT_PROJECT_ID; Review Comment: **The command from the removed javadoc now passes on Floci, without reading the key, and the project id is overwritten** Before this PR, the javadoc gave this command to run the ITs against a real project: ``` mvn verify -pl components/camel-google/camel-google-firestore \ -Dgoogle.firestore.serviceAccountKey=/path/to/service-account.json \ -Dgoogle.firestore.projectId=my-project-id ``` Without `-Dgoogle.instance.type=remote`, this command now gets the Floci service. The key is never read. `registerProperties()` overwrites `google.firestore.projectId` with `test-project`, because `projectId()` here always returns `DEFAULT_PROJECT_ID`. The tests pass, so a developer or a job set up with the old command believes the real project was tested, when it was not. I ran the old command with a key file that does not exist: `-Dgoogle.firestore.serviceAccountKey=/nonexistent/key.json -Dgoogle.firestore.projectId=my-real-project`. - On f6e9355, `GoogleFirestoreProducerIT` and `GoogleFirestoreConsumerIT` both pass: `Tests run: 9, Failures: 0, Errors: 0`. The failsafe reports show `google.firestore.projectId=test-project`. I also ran a small IT that extends `GoogleFirestoreITSupport`. It shows that the component got the Floci client, with `serviceAccountKey=null` and `projectId=test-project`, even though `-Dgoogle.firestore.projectId=my-real-project` was set. - On the base commit 21b8ed8e9613, `GoogleFirestoreProducerIT` gives 8 errors: `FileNotFoundException: /nonexistent/key.json does not exist`. So before this PR, the key was used. Suggestions: 1. In `GoogleFirestoreITSupport`, fail fast when `google.firestore.serviceAccountKey` is set without `-Dgoogle.instance.type=remote`. Logging a warning that the tests run on Floci and the key is ignored would be the minimum. This closes the gap. 2. For consistency with `GoogleStorageLocalContainerInfraService.projectId()`, honour the property here: `return System.getProperty(GoogleFirestoreProperties.PROJECT_ID, DEFAULT_PROJECT_ID);`. Floci accepts any project id. _Claude Code on behalf of Croway_ -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected]
