gnodet-bot commented on code in PR #29828:
URL: https://github.com/apache/camel/pull/29828#discussion_r4584009703


##########
components/camel-google/camel-google-firestore/src/test/java/org/apache/camel/component/google/firestore/integration/GoogleFirestoreITSupport.java:
##########
@@ -82,15 +82,31 @@ protected CamelContext createCamelContext() throws 
Exception {
      */
     protected void addFirestoreComponent(CamelContext context) {
         GoogleFirestoreConfiguration configuration = new 
GoogleFirestoreConfiguration();
+        configuration.setProjectId(service.projectId());
 
-        if (SERVICE_ACCOUNT_KEY != null) {
-            configuration.setServiceAccountKey("file:" + SERVICE_ACCOUNT_KEY);
-        }
-        if (PROJECT_ID != null) {
-            configuration.setProjectId(PROJECT_ID);
-        }
-        if (DATABASE_ID != null) {
-            configuration.setDatabaseId(DATABASE_ID);
+        if (isRemote()) {
+            configuration.setServiceAccountKey(
+                    "file:" + 
System.getProperty(GoogleFirestoreProperties.SERVICE_ACCOUNT_KEY));

Review Comment:
   If `isRemote()` returns `true` but `google.firestore.serviceAccountKey` is 
not set, `System.getProperty(...)` returns `null`, producing 
`setServiceAccountKey("file:null")`. Consider adding a null-check with a 
descriptive failure:
   ```java
   String key = 
System.getProperty(GoogleFirestoreProperties.SERVICE_ACCOUNT_KEY);
   if (key == null) {
       throw new IllegalStateException("System property 
google.firestore.serviceAccountKey is required when 
google.instance.type=remote");
   }
   configuration.setServiceAccountKey("file:" + key);
   ```



##########
components/camel-google/camel-google-firestore/src/test/java/org/apache/camel/component/google/firestore/integration/GoogleFirestoreITSupport.java:
##########
@@ -82,15 +82,31 @@ protected CamelContext createCamelContext() throws 
Exception {
      */
     protected void addFirestoreComponent(CamelContext context) {
         GoogleFirestoreConfiguration configuration = new 
GoogleFirestoreConfiguration();
+        configuration.setProjectId(service.projectId());
 
-        if (SERVICE_ACCOUNT_KEY != null) {
-            configuration.setServiceAccountKey("file:" + SERVICE_ACCOUNT_KEY);
-        }
-        if (PROJECT_ID != null) {
-            configuration.setProjectId(PROJECT_ID);
-        }
-        if (DATABASE_ID != null) {
-            configuration.setDatabaseId(DATABASE_ID);
+        if (isRemote()) {
+            configuration.setServiceAccountKey(
+                    "file:" + 
System.getProperty(GoogleFirestoreProperties.SERVICE_ACCOUNT_KEY));
+            String databaseId = 
System.getProperty(GoogleFirestoreProperties.DATABASE_ID);
+            if (databaseId != null) {
+                configuration.setDatabaseId(databaseId);
+            }
+        } else {
+            // Floci GCP is reached as an emulator: in plain text, with any 
credentials
+            Firestore client = FirestoreOptions.newBuilder()
+                    .setProjectId(service.projectId())
+                    .setEmulatorHost(service.endpoint())
+                    .build()
+                    .getService();
+            configuration.setFirestoreClient(client);
+            // the endpoints do not close a client that they did not build: it 
goes with the context
+            
context.addLifecycleStrategy(LifecycleStrategySupport.adapt((OnCamelContextStopped)
 stopped -> {
+                try {
+                    client.close();
+                } catch (Exception e) {
+                    throw new IllegalStateException(e);

Review Comment:
   Re-throwing as `IllegalStateException` during `OnCamelContextStopped` 
propagates out of the shutdown callback, which can interfere with the remaining 
context teardown. For best-effort cleanup (closing a client the test 
infrastructure injected), logging is typically preferred:
   ```java
   } catch (Exception e) {
       LOG.warn("Failed to close Firestore client", e);
   }
   ```



-- 
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]

Reply via email to