You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by "gnodet (via GitHub)" <gi...@apache.org> on 2026/10/16 15:41:24 UTC
[PR] CAMEL-25694: camel-milo - fix write/call service failures being reported as success [camel]
gnodet opened a new pull request, #27956:
URL: https://github.com/apache/camel/pull/27956
## Summary
Fix OPC-UA write/call/readValues/browse service failures being silently swallowed and reported as success when using the awaited (`CamelMiloAwait=true`) mode.
## Root Cause
`SubscriptionManager.write()`, `call()`, `readValues()`, and `browse()` all chained the underlying Milo client future with `handleAsync()`:
```java
return this.connected.write(nodeId, value).handleAsync((status, e) -> {
if (e != null) {
handleConnectionFailure(e);
}
return status; // returns null when e != null
}, this.executor);
```
When the OPC-UA operation fails (e.g. `Bad_Timeout` service fault), `handleAsync` receives a non-null exception. It calls `handleConnectionFailure(e)` for the reconnection side-effect, then **returns the value (null)**, converting the exceptional completion into a normal null completion.
`MiloClientProducer` awaits the returned future and only propagates errors when the throwable is non-null:
```java
future.whenComplete((result, throwable) -> {
if (throwable != null) exchange.setException(throwable);
else msg.setBody(result); // sets null body → reports success
});
```
Since `handleAsync` had already discarded the exception, the producer saw a null-completed future, set the body to `null`, and reported success. No error was raised to the Camel route.
## Fix
Replace `handleAsync()` with `whenCompleteAsync()` in all four methods. `whenCompleteAsync` runs the side-effect (reconnection) but propagates the original completion unchanged — exceptions stay exceptional, successes stay successful:
```java
return this.connected.write(nodeId, value).whenCompleteAsync((status, e) -> {
// handle outside the lock, running using
// whenCompleteAsync (preserves the original exceptional completion)
if (e != null) {
handleConnectionFailure(e);
}
}, this.executor);
```
## Tests
Two new test classes:
- **`MiloClientProducerWriteFailureTest`**: tests that `MiloClientProducer` correctly propagates awaited write/call failures as exchange exceptions, and that non-awaited (fire-and-forget) writes do not set exceptions. Uses a `MiloClientConnection` stub returning pre-arranged futures.
- **`SubscriptionManagerExceptionPropagationTest`**: tests the `whenCompleteAsync`-vs-`handleAsync` future completion contract directly (no server needed), and verifies that disconnected managers return exceptional futures from `write()`, `call()`, and `readValues()`.
Fixes https://issues.apache.org/jira/browse/CAMEL-25694
_Hermes Agent (Claude Sonnet 4.6) on behalf of Guillaume Nodet_
--
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: commits-unsubscribe@camel.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] CAMEL-25694: camel-milo - fix write/call service failures being reported as success [camel]
Posted by "github-actions[bot] (via GitHub)" <gi...@apache.org>.
github-actions[bot] commented on PR #27956:
URL: https://github.com/apache/camel/pull/27956#issuecomment-6219515236
<!-- ci-tested-modules -->
:test_tube: **CI tested the following changed modules:**
- `components/camel-milo`
---
<details><summary>:microscope: Scalpel shadow comparison — Scalpel: 8 of 706 tested, 27 compile-only — current: 8 all tested</summary>
[Maveniverse Scalpel](https://github.com/maveniverse/scalpel) detected **8 affected modules** (current approach: 8).
**Skip-tests mode would test 8 modules** (1 direct + 7 downstream), **skip tests for 27** (generated code, meta-modules)
<details><summary>Modules Scalpel would test (8)</summary>
- `camel-jbang-mcp` ← downstream of org.apache.camel:camel-catalog
- `camel-jbang-plugin-mcp` ← downstream of org.apache.camel:camel-jbang-core
- `camel-jbang-plugin-tui` ← downstream of org.apache.camel:camel-catalog
- `camel-jbang-plugin-validate` ← downstream of org.apache.camel:camel-yaml-dsl-validator
- `camel-launcher-container` ← downstream of org.apache.camel:camel-launcher
- `camel-milo` ← components/camel-milo/src/main/java/org/apache/camel/component/milo/client/internal/SubscriptionManager.java, components/camel-milo/src/test/java/org/apache/camel/component/milo/client/MiloClientProducerWriteFailureTest.java, components/camel-milo/src/test/java/org/apache/camel/component/milo/client/internal/SubscriptionManagerExceptionPropagationTest.java
- `camel-yaml-dsl-validator` ← downstream of org.apache.camel:camel-catalog
- `camel-yaml-dsl-validator-maven-plugin` ← downstream of org.apache.camel:camel-yaml-dsl-validator
</details>
<details><summary>Modules with tests skipped (27)</summary>
- `apache-camel`
- `camel-allcomponents`
- `camel-catalog`
- `camel-catalog-console`
- `camel-catalog-maven`
- `camel-catalog-suggest`
- `camel-componentdsl`
- `camel-endpointdsl`
- `camel-endpointdsl-support`
- `camel-itest`
- `camel-jbang-core`
- `camel-jbang-it`
- `camel-jbang-main`
- `camel-jbang-plugin-edit`
- `camel-jbang-plugin-generate`
- `camel-jbang-plugin-kubernetes`
- `camel-jbang-plugin-test`
- `camel-kamelet-main`
- `camel-launcher`
- `camel-report-maven-plugin`
- `camel-route-parser`
- `camel-yaml-dsl`
- `camel-yaml-dsl-deserializers`
- `camel-yaml-dsl-maven-plugin`
- `coverage`
- `docs`
- `dummy-component`
</details>
> :information_source: Shadow mode — Scalpel observes but does not affect test execution. [Learn more](https://github.com/maveniverse/scalpel)
</details>
<details><summary>All tested modules (35 modules, 0.0s total)</summary>
**Total reactor time:** 0.0s
| Module | Duration | Status |
| --- | --- | --- |
| Camel :: All Components Sync point | n/a | |
| Camel :: Assembly | n/a | |
| Camel :: Catalog :: Camel Catalog | n/a | |
| Camel :: Catalog :: Camel Report Maven Plugin | n/a | |
| Camel :: Catalog :: Camel Route Parser | n/a | |
| Camel :: Catalog :: Console | n/a | |
| Camel :: Catalog :: Dummy Component | n/a | |
| Camel :: Catalog :: Maven | n/a | |
| Camel :: Catalog :: Suggest (deprecated) | n/a | |
| Camel :: Component DSL | n/a | |
| Camel :: Coverage | n/a | |
| Camel :: Docs | n/a | |
| Camel :: Endpoint DSL | n/a | |
| Camel :: Endpoint DSL :: Support | n/a | |
| Camel :: Integration Tests | n/a | |
| Camel :: JBang :: Core | n/a | |
| Camel :: JBang :: Integration tests | n/a | |
| Camel :: JBang :: MCP | n/a | |
| Camel :: JBang :: Main | n/a | |
| Camel :: JBang :: Plugin :: Edit | n/a | |
| Camel :: JBang :: Plugin :: Generate | n/a | |
| Camel :: JBang :: Plugin :: Kubernetes | n/a | |
| Camel :: JBang :: Plugin :: MCP | n/a | |
| Camel :: JBang :: Plugin :: TUI | n/a | |
| Camel :: JBang :: Plugin :: Testing | n/a | |
| Camel :: JBang :: Plugin :: Validate | n/a | |
| Camel :: Kamelet Main | n/a | |
| Camel :: Launcher | n/a | |
| Camel :: Launcher :: Container | n/a | |
| Camel :: Milo | n/a | |
| Camel :: YAML DSL | n/a | |
| Camel :: YAML DSL :: Deserializers | n/a | |
| Camel :: YAML DSL :: Maven Plugins | n/a | |
| Camel :: YAML DSL :: Validator | n/a | |
| Camel :: YAML DSL :: Validator Maven Plugin | n/a | |
</details>
---
:gear: [View full build and test results](https://github.com/apache/camel/actions/runs/38925972729)
--
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: commits-unsubscribe@camel.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] CAMEL-25694: camel-milo - fix write/call service failures being reported as success [camel]
Posted by "davsclaus (via GitHub)" <gi...@apache.org>.
davsclaus commented on code in PR #27956:
URL: https://github.com/apache/camel/pull/27956#discussion_r4357670308
##########
docs/user-manual/modules/ROOT/pages/camel-4x-upgrade-guide-4_24.adoc:
##########
@@ -2366,6 +2366,16 @@ To keep the previous behaviour, filter the exchanges with a bad status out right
`filter(simple("${body.statusCode.bad} == false"))`. This also drops the other bad statuses, such as the refusal of a
node, and the current values delivered after an outage still arrive.
+=== camel-milo - an awaited write, call or read that fails now fails the exchange
+
+An awaited `milo-client` write, method call or read whose server-side operation fails, for example a write
+of a wrong type or a call that times out, now fails the exchange and lets the route's error handler run.
+Before, the exchange completed without an error and with a `null` body, silently discarding the failure.
Review Comment:
A write of a wrong type does not fail the exchange. `writeValuesAsync` answers it with a per-node `Bad_TypeMismatch` `StatusCode`, so the future completes normally and the `StatusCode` is the body, before and after this change. The JIRA asks to keep that per-node behaviour. Only service or transport failures (a `Bad_Timeout` service fault, a closed session, a lost connection) complete the future exceptionally. Maybe:
```suggestion
An awaited `milo-client` write, method call or read that fails at the service or transport level, for example a
request that times out (`Bad_Timeout`) or a lost connection, now fails the exchange and lets the route's error
handler run. Before, the exchange completed without an error and with a `null` body, silently discarding the failure.
A bad status for the node itself, such as `Bad_TypeMismatch` on a write, is not a failure of the operation and is
still returned as the body.
```
--
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: commits-unsubscribe@camel.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] CAMEL-25694: camel-milo - fix write/call service failures being reported as success [camel]
Posted by "davsclaus (via GitHub)" <gi...@apache.org>.
davsclaus commented on code in PR #27956:
URL: https://github.com/apache/camel/pull/27956#discussion_r4357363168
##########
components/camel-milo/src/test/java/org/apache/camel/component/milo/ServerCertificateValidationTest.java:
##########
@@ -126,7 +126,8 @@ protected RoutesBuilder createRouteBuilder() {
public void configure() {
from(DIRECT_START).to(MILO_SERVER_ITEM);
- // the consumers deliver the current value while they start, so the test starts these routes
+ // consumers deliver the current server value when they subscribe, so they are started
+ // only after the initial write to avoid receiving both the initial value and the write as two messages
Review Comment:
Main already has the `autoStartup(false)` fix from CAMEL-25645 (#27999), so this hunk and the one below only reword the comments. Could the file be left out of this PR, so the commit history does not suggest a second fix of this test?
##########
components/camel-milo/src/main/java/org/apache/camel/component/milo/client/internal/SubscriptionManager.java:
##########
@@ -1542,13 +1542,12 @@ public CompletableFuture<CallMethodResult> call(
return newNotConnectedResult();
}
- return this.connected.call(nodeId, methodId, inputArguments).handleAsync((status, e) -> {
+ return this.connected.call(nodeId, methodId, inputArguments).whenCompleteAsync((status, e) -> {
Review Comment:
Besides the failure propagation, this changes the success case: the old `handleAsync` returned `null` here even when the call succeeded, so an awaited `call` always left a `null` body. Now the route gets the `CallMethodResult` (including the `Bad_NodeIdUnknown` / `Bad_MethodInvalid` answer from CAMEL-25690 for an unknown namespace). That is the better behaviour, but it is what users will notice, so it deserves a test (an assertion on the body in `CallClientTest` fails before this change) and a line in the 4.24 upgrade guide.
--
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: commits-unsubscribe@camel.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] CAMEL-25694: camel-milo - fix write/call service failures being reported as success [camel]
Posted by "gnodet (via GitHub)" <gi...@apache.org>.
gnodet commented on PR #27956:
URL: https://github.com/apache/camel/pull/27956#issuecomment-6370753342
<!-- camel-backport-bot -->
### 🔄 Backport Bot
**Conflicts (🤖 agent dispatched to resolve):**
- ⚠️ `camel-4.22.x` — Cherry-pick conflict in: docs/user-manual/modules/ROOT/pages/camel-4x-upgrade-guide-4_24.adoc
- ⚠️ `camel-4.18.x` — Cherry-pick conflict in: docs/user-manual/modules/ROOT/pages/camel-4x-upgrade-guide-4_24.adoc
ℹ️ If you push additional commits after `/port`, use `/port` again to update the port PRs.
--
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: commits-unsubscribe@camel.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] CAMEL-25694: camel-milo - fix write/call service failures being reported as success [camel]
Posted by "gnodet (via GitHub)" <gi...@apache.org>.
gnodet commented on PR #27956:
URL: https://github.com/apache/camel/pull/27956#issuecomment-6370801941
✅ Backport to `camel-4.22.x` created: https://github.com/apache/camel/pull/28367
--
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: commits-unsubscribe@camel.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] CAMEL-25694: camel-milo - fix write/call service failures being reported as success [camel]
Posted by "etzel-mes (via GitHub)" <gi...@apache.org>.
etzel-mes commented on PR #27956:
URL: https://github.com/apache/camel/pull/27956#issuecomment-6247219632
For reference: #28045 (CAMEL-25690) changes how the write, call, read and browse requests of `SubscriptionManager.Connected` resolve a node ID with an unknown `nsu=`, and does not touch the four guards that this PR changes. The two merge without conflicts in either order, so I kept #28045 independent of this PR. With this PR, the method call answer of #28045 (`Bad_NodeIdUnknown` or `Bad_MethodInvalid`) also reaches the exchange; I left it out of that PR's docs and test for now and can add it once this PR is merged.
_Claude Code on behalf of etzel-mes_
--
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: commits-unsubscribe@camel.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] CAMEL-25694: camel-milo - fix write/call service failures being reported as success [camel]
Posted by "davsclaus (via GitHub)" <gi...@apache.org>.
davsclaus merged PR #27956:
URL: https://github.com/apache/camel/pull/27956
--
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: commits-unsubscribe@camel.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] CAMEL-25694: camel-milo - fix write/call service failures being reported as success [camel]
Posted by "github-actions[bot] (via GitHub)" <gi...@apache.org>.
github-actions[bot] commented on PR #27956:
URL: https://github.com/apache/camel/pull/27956#issuecomment-6219191595
:star2: Thank you for your contribution to the Apache Camel project! :star2:
:robot: CI automation will test this PR automatically.
:camel: Apache Camel Committers, please review the following items:
* First-time contributors **require MANUAL approval** for the GitHub Actions to run
* You can use the command `/component-test (camel-)component-name1 (camel-)component-name2..` to request a test from the test bot although they are normally detected and executed by CI.
* You can label PRs using `skip-tests` and `test-dependents` to fine-tune the checks executed by this PR.
* Build and test logs are available in the summary page. **Only** [Apache Camel committers](https://camel.apache.org/community/team/#committers) have access to the summary.
:warning: Be careful when sharing logs. Review their contents before sharing them publicly.
--
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: commits-unsubscribe@camel.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] CAMEL-25694: camel-milo - fix write/call service failures being reported as success [camel]
Posted by "gnodet-bot (via GitHub)" <gi...@apache.org>.
gnodet-bot commented on code in PR #27956:
URL: https://github.com/apache/camel/pull/27956#discussion_r4350511477
##########
components/camel-milo/src/test/java/org/apache/camel/component/milo/client/internal/SubscriptionManagerExceptionPropagationTest.java:
##########
@@ -0,0 +1,203 @@
+/*
+ * 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.component.milo.client.internal;
+
+import java.util.List;
+import java.util.concurrent.CompletableFuture;
+import java.util.concurrent.ExecutionException;
+import java.util.concurrent.Executors;
+import java.util.concurrent.ScheduledExecutorService;
+import java.util.concurrent.TimeUnit;
+
+import org.apache.camel.component.milo.client.MiloClientConfiguration;
+import org.eclipse.milo.opcua.stack.core.types.builtin.DataValue;
+import org.eclipse.milo.opcua.stack.core.types.builtin.ExpandedNodeId;
+import org.eclipse.milo.opcua.stack.core.types.builtin.Variant;
+import org.eclipse.milo.opcua.stack.core.types.structured.CallMethodResult;
+import org.junit.jupiter.api.AfterEach;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
+
+import static org.junit.jupiter.api.Assertions.assertFalse;
+import static org.junit.jupiter.api.Assertions.assertInstanceOf;
+import static org.junit.jupiter.api.Assertions.assertNotNull;
+import static org.junit.jupiter.api.Assertions.assertNull;
+import static org.junit.jupiter.api.Assertions.assertTrue;
+import static org.junit.jupiter.api.Assertions.fail;
+
+/**
+ * Unit tests for {@link SubscriptionManager} exception propagation through write() and call().
+ *
+ * <p>
+ * Regression tests for CAMEL-25694: {@code SubscriptionManager.write()} and {@code call()} previously used
+ * {@code handleAsync()} which converted exceptional completions into normal completions with null values. The fix
+ * replaces {@code handleAsync()} with {@code whenCompleteAsync()} to preserve the original exceptional completion.
+ *
+ * <p>
+ * The {@code whenCompleteAsync}-vs-{@code handleAsync} contract is tested via standalone helper methods (no real OPC UA
+ * connection needed). The disconnected-manager tests use a real {@link SubscriptionManager} to verify that
+ * {@code write()}, {@code call()}, and {@code readValues()} all return exceptional futures before any connection is
+ * established.
+ */
+class SubscriptionManagerExceptionPropagationTest {
+
+ private ScheduledExecutorService executor;
+
+ @BeforeEach
+ void setUp() {
+ executor = Executors.newSingleThreadScheduledExecutor();
+ }
+
+ @AfterEach
+ void tearDown() throws InterruptedException {
+ executor.shutdownNow();
+ assertTrue(executor.awaitTermination(5, TimeUnit.SECONDS),
+ "Executor must shut down cleanly within 5 seconds");
+ }
+
+ // -------------------------------------------------------------------------
+ // Contract tests: whenCompleteAsync vs handleAsync
+ //
+ // These do NOT instantiate SubscriptionManager (which would trigger a
+ // connection attempt in its constructor). Instead they exercise the same
+ // CompletableFuture chain used by the production fix.
+ // -------------------------------------------------------------------------
+
+ /**
Review Comment:
⚠️ **Two separate issues with the coverage:**
1. `testWhenCompleteAsyncPreservesExceptionalCompletion` and `testHandleAsyncSwallowsExceptionalCompletion` are pure `CompletableFuture` API contract tests — they don't call any `SubscriptionManager` method. They demonstrate *why* the fix works (the JDK contract), not *that* `SubscriptionManager` is correctly fixed.
2. `testWriteWhenDisconnectedReturnsExceptionalFuture` / `testCallWhenDisconnectedReturnsExceptionalFuture` / `testReadValuesWhenDisconnectedReturnsExceptionalFuture` test the `this.connected == null` guard (`newNotConnectedResult()`), not the `whenCompleteAsync` path. That path only executes when `this.connected != null` — i.e. on an active connection where the server-side operation fails. These tests verify pre-existing behavior, not the fix.
The tests that would actually validate the fix are those that create a `SubscriptionManager` in the *connected* state with a `Connected` whose inner Milo client operation returns an exceptional future.
##########
components/camel-milo/src/test/java/org/apache/camel/component/milo/client/MiloClientProducerWriteFailureTest.java:
##########
@@ -0,0 +1,221 @@
+/*
+ * 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.component.milo.client;
+
+import java.lang.reflect.Field;
+import java.util.List;
+import java.util.Map;
+import java.util.concurrent.CompletableFuture;
+import java.util.concurrent.CountDownLatch;
+import java.util.concurrent.TimeUnit;
+import java.util.concurrent.atomic.AtomicReference;
+
+import org.apache.camel.Exchange;
+import org.apache.camel.component.milo.MiloConstants;
+import org.apache.camel.impl.DefaultCamelContext;
+import org.apache.camel.support.DefaultExchange;
+import org.eclipse.milo.opcua.stack.core.types.builtin.ExpandedNodeId;
+import org.eclipse.milo.opcua.stack.core.types.builtin.StatusCode;
+import org.eclipse.milo.opcua.stack.core.types.enumerated.BrowseDirection;
+import org.eclipse.milo.opcua.stack.core.types.structured.BrowseResult;
+import org.eclipse.milo.opcua.stack.core.types.structured.CallMethodResult;
+import org.junit.jupiter.api.AfterEach;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
+
+import static org.junit.jupiter.api.Assertions.assertInstanceOf;
+import static org.junit.jupiter.api.Assertions.assertNotNull;
+import static org.junit.jupiter.api.Assertions.assertNull;
+import static org.junit.jupiter.api.Assertions.assertTrue;
+
+/**
Review Comment:
⚠️ **Test doesn't exercise the fixed code path.** `StubMiloClientConnection` overrides `writeValue()` and `call()` to return pre-arranged futures directly, completely bypassing `SubscriptionManager`. In production, `MiloClientConnection.writeValue()` delegates to `this.manager.write()` (line 217 of `MiloClientConnection.java`) — exactly where the `handleAsync` → `whenCompleteAsync` fix lives. The stub short-circuits that delegation.
This means the test would pass identically before and after this PR's fix. It tests that `MiloClientProducer.process()` propagates exceptions from the connection's `CompletableFuture` — which was never the bug. The bug was `SubscriptionManager` converting exceptions to `null` via `handleAsync`.
To validate the actual fix, a test needs to invoke `SubscriptionManager.write()`/`call()` on a *connected* manager whose `Connected.write()`/`call()` returns a failing `CompletableFuture`, then assert the returned future is still exceptional. Without this, if someone reverts the `handleAsync` → `whenCompleteAsync` change, all tests still pass.
##########
components/camel-milo/src/test/java/org/apache/camel/component/milo/client/internal/SubscriptionManagerExceptionPropagationTest.java:
##########
@@ -0,0 +1,203 @@
+/*
+ * 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.component.milo.client.internal;
+
+import java.util.List;
+import java.util.concurrent.CompletableFuture;
+import java.util.concurrent.ExecutionException;
+import java.util.concurrent.Executors;
+import java.util.concurrent.ScheduledExecutorService;
+import java.util.concurrent.TimeUnit;
+
+import org.apache.camel.component.milo.client.MiloClientConfiguration;
+import org.eclipse.milo.opcua.stack.core.types.builtin.DataValue;
+import org.eclipse.milo.opcua.stack.core.types.builtin.ExpandedNodeId;
+import org.eclipse.milo.opcua.stack.core.types.builtin.Variant;
+import org.eclipse.milo.opcua.stack.core.types.structured.CallMethodResult;
+import org.junit.jupiter.api.AfterEach;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
+
+import static org.junit.jupiter.api.Assertions.assertFalse;
+import static org.junit.jupiter.api.Assertions.assertInstanceOf;
+import static org.junit.jupiter.api.Assertions.assertNotNull;
+import static org.junit.jupiter.api.Assertions.assertNull;
+import static org.junit.jupiter.api.Assertions.assertTrue;
+import static org.junit.jupiter.api.Assertions.fail;
+
+/**
+ * Unit tests for {@link SubscriptionManager} exception propagation through write() and call().
+ *
+ * <p>
+ * Regression tests for CAMEL-25694: {@code SubscriptionManager.write()} and {@code call()} previously used
+ * {@code handleAsync()} which converted exceptional completions into normal completions with null values. The fix
+ * replaces {@code handleAsync()} with {@code whenCompleteAsync()} to preserve the original exceptional completion.
+ *
+ * <p>
+ * The {@code whenCompleteAsync}-vs-{@code handleAsync} contract is tested via standalone helper methods (no real OPC UA
+ * connection needed). The disconnected-manager tests use a real {@link SubscriptionManager} to verify that
+ * {@code write()}, {@code call()}, and {@code readValues()} all return exceptional futures before any connection is
+ * established.
+ */
+class SubscriptionManagerExceptionPropagationTest {
+
+ private ScheduledExecutorService executor;
+
+ @BeforeEach
+ void setUp() {
+ executor = Executors.newSingleThreadScheduledExecutor();
+ }
+
+ @AfterEach
+ void tearDown() throws InterruptedException {
+ executor.shutdownNow();
+ assertTrue(executor.awaitTermination(5, TimeUnit.SECONDS),
+ "Executor must shut down cleanly within 5 seconds");
+ }
+
+ // -------------------------------------------------------------------------
+ // Contract tests: whenCompleteAsync vs handleAsync
+ //
+ // These do NOT instantiate SubscriptionManager (which would trigger a
+ // connection attempt in its constructor). Instead they exercise the same
+ // CompletableFuture chain used by the production fix.
+ // -------------------------------------------------------------------------
+
+ /**
+ * Verifies that {@code whenCompleteAsync} (the fix) preserves an exceptional completion.
+ *
+ * <p>
+ * Before CAMEL-25694 was fixed, {@code SubscriptionManager.write()} used {@code handleAsync()}, which converted the
+ * exceptional completion into a normal null completion. This test verifies the correct behavior: a
+ * {@code whenCompleteAsync} side-effect chain over a failed future must stay failed.
+ */
+ @Test
+ void testWhenCompleteAsyncPreservesExceptionalCompletion() throws Exception {
+ RuntimeException serviceError = new RuntimeException("Bad_Timeout OPC-UA service fault");
+ CompletableFuture<Object> upstream = new CompletableFuture<>();
+ upstream.completeExceptionally(serviceError);
+
+ // Same chain as the fixed SubscriptionManager.write(): side-effect only, completion preserved
+ CompletableFuture<?> result = upstream.whenCompleteAsync((r, e) -> {
+ // side-effect (e.g. handleConnectionFailure); exception propagated by whenCompleteAsync
+ }, executor);
+
+ ExecutionException ex = null;
+ try {
+ result.get(5, TimeUnit.SECONDS);
+ } catch (ExecutionException e) {
+ ex = e;
+ } catch (Exception e) {
+ fail("Unexpected exception type: " + e);
+ }
+ assertNotNull(ex, "Get on a failed whenCompleteAsync future must throw ExecutionException");
+ assertInstanceOf(RuntimeException.class, ex.getCause());
+ assertTrue(result.isCompletedExceptionally(),
+ "whenCompleteAsync must preserve the exceptional completion");
+ }
+
Review Comment:
**Low severity / documentation gap:** This test exercises `newNotConnectedResult()`, not the `whenCompleteAsync` path. Consider adding a comment making this explicit:
```suggestion
/**
* Verifies that a disconnected manager returns an exceptional future from write(), ensuring producers fail fast
* when there is no connection.
*
* <p>Note: this tests the {@code this.connected == null} guard path ({@code newNotConnectedResult()}),
* not the {@code whenCompleteAsync} exception-preservation fix (which requires a connected manager
* with a failing upstream future).
*/
@Test
void testWriteWhenDisconnectedReturnsExceptionalFuture() {
```
--
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: commits-unsubscribe@camel.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] CAMEL-25694: camel-milo - fix write/call service failures being reported as success [camel]
Posted by "gnodet (via GitHub)" <gi...@apache.org>.
gnodet commented on PR #27956:
URL: https://github.com/apache/camel/pull/27956#issuecomment-6370806712
✅ Backport to `camel-4.18.x` created: https://github.com/apache/camel/pull/28368
--
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: commits-unsubscribe@camel.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org