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


##########
test-infra/camel-test-infra-google-common/src/main/java/org/apache/camel/test/infra/google/common/services/FlociGcpContainer.java:
##########
@@ -47,4 +76,86 @@ public FlociGcpContainer(String imageName, boolean 
fixedPort) {
     public String serviceAddress() {
         return String.format("http://%s:%d";, getHost(), 
getMappedPort(SERVICE_PORT));
     }
+
+    /**
+     * Lets Floci GCP start containers of its own, such as the SQL engine of 
BigQuery: mounts the Docker socket of the
+     * host, and gives the containers that Floci GCP starts a resource 
namespace of this container, by which
+     * {@link #stop()} removes them. Each container has a namespace of its 
own: when it starts, Floci GCP removes the
+     * containers of its namespace that it finds, as left over.
+     */
+    public FlociGcpContainer withDockerSocket() {
+        resourceNamespace = "camel" + 
UUID.randomUUID().toString().replace("-", "").substring(0, 12);
+        withEnv(RESOURCE_NAMESPACE_ENV, resourceNamespace);
+        return 
withCreateContainerCmdModifier(FlociGcpContainer::bindDockerSocket);
+    }
+
+    /**
+     * Has Floci GCP run the queries of BigQuery on the floci-duck image of
+     * {@link GoogleProperties#BIGQUERY_ENGINE_CONTAINER}, which this method 
pulls as Testcontainers pulls its own
+     * images, so that image substitution and registry authentication apply: 
Floci GCP would pull it itself otherwise.
+     * Needs {@link #withDockerSocket()}.
+     */
+    public FlociGcpContainer withBigQueryEngine() {

Review Comment:
   ⚠️ `withBigQueryEngine()` has no runtime guard ensuring `withDockerSocket()` 
was called first. The Javadoc says *"Needs `withDockerSocket()`"*, but nothing 
enforces it at runtime — a caller who omits `withDockerSocket()` will silently 
pass the env var to Floci GCP without the Docker socket bind, resulting in a 
confusing container failure at start-up rather than a clear error at 
configuration time.
   
   Consider adding an explicit guard:
   ```suggestion
       public FlociGcpContainer withBigQueryEngine() {
           if (resourceNamespace == null) {
               throw new IllegalStateException("withDockerSocket() must be 
called before withBigQueryEngine()");
           }
           String image = 
LocalPropertyResolver.getProperty(FlociGcpContainer.class,
                   GoogleProperties.BIGQUERY_ENGINE_CONTAINER);
           return withEnv(BIGQUERY_ENGINE_IMAGE_ENV, new 
RemoteDockerImage(DockerImageName.parse(image)).get());
       }
   ```



##########
components/camel-google/camel-google-bigquery/src/test/java/org/apache/camel/component/google/bigquery/integration/BigQueryITSupport.java:
##########
@@ -99,9 +106,7 @@ protected void addBigquerySqlComponent(CamelContext context) 
{
 
         GoogleBigQuerySQLConfiguration configuration = new 
GoogleBigQuerySQLConfiguration()
                 .setServiceAccountKey(CREDENTIALS_FILE_LOCATION);
-        connectionFactory = new GoogleBigQueryConnectionFactory()
-                .setServiceAccountKeyFile(configuration.getServiceAccountKey())
-                .setCamelContext(context);
+        connectionFactory = createConnectionFactory(context);

Review Comment:
   ℹ️ `createConnectionFactory()` is called twice per test run — once in 
`addBigqueryComponent()` (line 95) and once here in 
`addBigquerySqlComponent()`. In local mode each call returns `new 
LocalConnectionFactory()`, which eagerly constructs a `BigQuery` client via 
`BigQueryOptions.newBuilder()…build().getService()`. The first instance is 
immediately overwritten by the second assignment to `connectionFactory` and 
becomes eligible for GC.
   
   This is a minor inefficiency (the first client is wasted). Both components 
end up sharing the same `connectionFactory` reference after the second call, 
which is correct. Consider factoring out the factory creation to a single call 
before the two `add*` methods.



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