allthingssecurity opened a new pull request, #30996: URL: https://github.com/apache/camel/pull/30996
# Description [CAMEL-27604](https://issues.apache.org/jira/browse/CAMEL-27604) The ticket lists four problems of camel-google-firestore that came up while the option descriptions were written for CAMEL-23832 (#30939). I checked each one against main. Three are fixed here, one is left as it is. Fixed: 1. **Realtime listener errors were only logged, and the start waited 30 seconds.** With `realtimeUpdates=true`, an error event of the snapshot listener was logged at ERROR level and never reached the exception handler of the consumer or `bridgeErrorHandler`. When the error was the first event, the latch was not counted down, so `doStart()` waited the full 30 seconds, ignored the result of the wait and logged that the listener had started. The Firestore SDK does not call a listener again after an error (its `Watch` closes the stream on a permanent error and retries the others without telling the listener), so the route ran with a closed listener. Now: - an error that arrives while `doStart()` waits for the first event fails the start of the consumer with that `FirestoreException`, and the listener registration is removed; - a later error goes to `getExceptionHandler()`, with a message that the listener receives no more changes; - when no event arrives within 30 seconds, a WARN is logged instead of the "started" message, and the consumer still starts, as before. The listener is now started before the scheduler of the consumer, so a failed start does not leave the scheduler running. The start state that the listener thread and `doStart()` share is guarded by its own lock. Polling mode is not touched. 2. **CamelGoogleFirestoreMergeFields could not address nested fields.** Each name went through `FieldPath.of(name)`, which takes the name as one segment, so `address.city` was a top-level field literally named `address.city`. Names are now parsed with `FieldPath.fromDotSeparatedString`, as the field paths of `updateDocument`. A `FieldPath` element in the list is used as it is, so a top-level field whose name contains a dot can still be merged. A name that is not a valid dot-separated path (one with `~ * / [ ]`, which `fromDotSeparatedString` rejects with an `IllegalArgumentException`, or with an empty segment such as `a..b`) is still taken with `FieldPath.of(name)` as one top-level field, so such names keep working as before. 3. **operation had no defaultValue.** It is now `setDocument`, the operation the producer performs when neither the option nor the header is set. Not changed: 4. **firestoreClient has no label.** Setting `label = "advanced"` would move the option to the Advanced builders of the Endpoint DSL, so `googleFirestore("users").firestoreClient(client)` would stop compiling. The doc page now describes the listener errors and the dotted merge field names. Upgrade guide (4.24): a realtime consumer whose first listener event is an error fails to start, later errors go to the exception handler, and merge field names are dot-separated paths (names that are not valid paths are still one top-level field). The entry sits after the camel-google-storage entry instead of at the end of the list. Overlap with #30939: both change the `@UriParam` of `operation`, the `@Metadata` of `CamelGoogleFirestoreMergeFields`, the doc page and the generated files, so whichever is merged second needs a small rebase. Its new description of `CamelGoogleFirestoreMergeFields` says "The names of the fields that setDocument merges"; with this change they are dot-separated field paths (or `FieldPath` objects), so `address.city` is the nested field. Its description of `operation` ("If not set, the producer performs setDocument") fits the new default. Tests (new, unit tests with a mocked Firestore client, no emulator or credentials; mockito-core is added as a test dependency): - `GoogleFirestoreRealtimeListenerErrorTest`: an error as the first listener event fails the start with that exception and removes the registration; an error after the start reaches the exception handler of the consumer. - `GoogleFirestoreProducerMergeFieldsTest`: `address.city` is passed to `set` as the path `address`, `city`; a `FieldPath` element is passed as it is; `price/unit` and `address..city` are each passed as one top-level field; the component JSON has the `setDocument` default. - Against the main sources the 5 tests of the listener error and dotted name changes fail: the start succeeds after waiting 30 seconds, the handler is not called, the dotted name is one segment, a `FieldPath` element fails with a `ClassCastException`, and the default is missing. The test for names that are not valid paths keeps the behaviour of main (it passes there) and fails with a plain `fromDotSeparatedString` (`IllegalArgumentException` for `price/unit`). Results (offline, module build of camel-google-firestore, test phase, integration tests skipped as they need the emulator): 20 tests run, 0 failures, 0 errors. The two new test classes pass 5 runs in a row. Note: the local repository here only had google-cloud-firestore 3.49.0 and grpc 1.84.2, so I built with those versions instead of 3.53.0 and 1.85.1. The APIs used (`FieldPath.fromDotSeparatedString`, `addSnapshotListener`, `FirestoreException.forServerRejection`) are the same in both. Generated files: `google-firestore.json` of the component and its catalog copy, the catalog copy of the doc page, and the javadoc of `operation` and the merge fields header in the component and endpoint DSL. # 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-27604](https://issues.apache.org/jira/browse/CAMEL-27604). # 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-google-firestore and ran its unit tests, and committed the regenerated component files. The catalog copies and the DSL javadoc were updated to match, as an offline build of those modules was not possible here; the DSL files were generated by the camel-package-maven-plugin goals from the updated catalog JSON. 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]
