allthingssecurity opened a new pull request, #28533:
URL: https://github.com/apache/camel/pull/28533

   # Description
   
   [CAMEL-26045](https://issues.apache.org/jira/browse/CAMEL-26045)
   
   `CosmosDbEndpoint.doStart` takes the `CosmosAsyncClient` of the 
configuration (the `cosmosAsyncClient` option, which is `@Metadata(autowired = 
true)`), or creates one. `doStop` closes whichever client it has. A client set 
on the component or autowired from the registry is shared by every 
azure-cosmosdb endpoint, and often by the application too (for example a Spring 
bean used by Spring Data Cosmos). When one endpoint stops, the client is closed 
for everyone. `AbstractCamelContext.removeRoute` stops the endpoints that only 
the removed route used, so removing or reloading one route breaks every other 
azure-cosmosdb endpoint, and the application, until it is restarted. 
azure-cosmos 4.75.0 `CosmosAsyncClient.close()` closes its 
`AsyncDocumentClient`.
   
   Changes:
   - `CosmosDbEndpoint` remembers whether it created the client, and closes 
only a client it created. A configured or autowired client is never closed by 
Camel. This is the same as what azure-servicebus, eventhubs and vertexai do, 
and as CAMEL-25288 (dapr).
   - A client the endpoint created is still closed when it stops, and a start 
after a stop creates a new one, as before.
   - Upgrade guide (4.24): a client set on the component or autowired is no 
longer closed by Camel. Users who relied on Camel to close it close it 
themselves (a Spring bean is closed by Spring).
   - No option or generated file change.
   - Backport: camel-4.23.x, 4.22.x and 4.18.x have the same endpoint.
   
   Not changed (follow-up JIRA if wanted): `CosmosDbConsumer` and 
`CosmosDbProducer` wrap the endpoint's client once, in `doInit`. When the 
endpoint creates its own client and the CamelContext is stopped and started 
again, the endpoint creates a new client while a consumer or producer that is 
started again keeps the closed one. That case is independent of this change.
   
   Tests:
   - New `CosmosDbEndpointClientLifecycleTest`, 2 tests, JUnit assertions as in 
the module.
   - `removingARouteDoesNotCloseTheSharedClient` binds a Mockito 
`CosmosAsyncClient` in the registry, which is autowired into two routes on two 
containers. It removes one route, checks that its endpoint stopped, and then 
checks that the client was not closed and is still the other endpoint's client. 
It fails on main with Mockito's `shared.close(); Never wanted here: ... But 
invoked here: ... CosmosDbEndpoint.doStop`.
   - `anEndpointClosesTheClientItCreated` is a control that passes on main and 
with the fix. It mocks `CosmosDbClientFactory` (Mockito `mockStatic`) and 
checks that an endpoint without a configured client (autowiring off, so it does 
not take the registry client) closes the client it created when it stops, and 
creates a new one when it is started again.
   - Unit tests of camel-azure-cosmosdb with the fix: 23 run, 0 failures, 0 
skipped.
   - The formatter and import-sort plugins ran. I built offline with 
`-Dasm-version=9.11` because asm 9.11.1 was not in my local repository.
   
   # Target
   
   - [x] I checked that the commit is targeting the correct branch (Camel 4 
uses the `main` branch)
   
   # Tracking
   - [x] If this is a large change, bug fix, or code improvement, I checked 
there is a [JIRA issue](https://issues.apache.org/jira/browse/CAMEL) filed for 
the change (usually before you start working on it): 
[CAMEL-26045](https://issues.apache.org/jira/browse/CAMEL-26045).
   
   # Apache Camel coding standards and style
   
   - [x] I checked that each commit in the pull request has a meaningful 
subject line and body.
   - [ ] I have run `mvn clean install -DskipTests` locally from root folder 
and I have committed all auto-generated changes.
     (I built camel-azure-cosmosdb and ran its tests, including the formatter 
and import-sort plugins. No generated file changes. I did not run the full root 
build.)
   
   # AI-assisted contributions
   
   - [x] If this PR includes AI-generated code, commits have proper 
co-authorship attribution (e.g., `Co-authored-by` trailers) and the PR 
description identifies the AI tool used.
     This PR was prepared with Claude Code (Claude Opus 5.5). The commit 
carries a `Co-Authored-By` trailer.
   
   _Claude Code on behalf of allthingssecurity_
   
   🤖 Generated with [Claude Code](https://claude.com/claude-code)
   


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