davsclaus commented on code in PR #29552:
URL: https://github.com/apache/camel/pull/29552#discussion_r4522841696
##########
components/camel-chaos/src/main/java/org/apache/camel/component/chaos/ChaosAdvisor.java:
##########
@@ -518,6 +521,76 @@ private static String uri(Endpoint endpoint) {
return query > 0 ? uri.substring(0, query) : uri;
}
+ /**
+ * Why an expectation of the messages lost between two routes ({@code
orders->shipping:lost<=0}) says nothing, or
+ * null when it does (CAMEL-26797). Lost counts what the first route
completed and the next did not, which tells
+ * only when the first hands the message off to the next (over seda, a
broker or a wireTap) and goes on: a route
+ * that calls the next over direct waits for it and fails with it, and a
route that does not send to it at all (such
+ * as an HTTP call to a platform-http route) loses nothing that lost
counts, while its own failures are not counted.
+ * The routes reached through a send that is known only when it sends
(toD, wireTap, recipientList...) are not
+ * known, so then it says nothing.
+ */
+ static String lostWithoutHandOff(CamelContext camelContext,
ChaosRule.Expectation expectation) {
+ if (expectation == null || expectation.toRoute == null ||
camelContext.getRoute(expectation.route) == null
+ || camelContext.getRoute(expectation.toRoute) == null) {
+ return null;
+ }
+ Map<String, String> consumers = new HashMap<>();
+ for (Route route : camelContext.getRoutes()) {
+ if (route.getEndpoint() != null) {
+ consumers.put(uri(route.getEndpoint()), route.getRouteId());
+ }
+ }
+ // the routes the first one reaches, and whether a hand-off was on the
way there (one that was wins)
+ Map<String, Boolean> reached = new HashMap<>();
+ reached.put(expectation.route, false);
+ Deque<String> todo = new ArrayDeque<>(List.of(expectation.route));
+ while (!todo.isEmpty()) {
+ String id = todo.poll();
+ Route route = camelContext.getRoute(id);
+ if (route == null) {
+ continue;
+ }
+ if (route.getRoute() instanceof RouteDefinition definition) {
+ List<String> dynamic = new ArrayList<>();
+ ChaosTargets.dynamicSends(definition.getOutputs(), dynamic);
+ if (!dynamic.isEmpty()) {
+ return null;
+ }
+ }
+ for (Processor processor : route.filter("*")) {
+ if (!(processor instanceof EndpointAware aware) ||
aware.getEndpoint() == null) {
+ continue;
+ }
+ String uri = uri(aware.getEndpoint());
+ String next = consumers.get(uri);
+ if (next == null) {
+ continue;
+ }
+ boolean handedOff = reached.get(id) ||
!"direct".equals(ChaosPatterns.scheme(uri));
+ Boolean before = reached.get(next);
+ if (before == null || !before && handedOff) {
Review Comment:
Done in 122ebcfe9541.
_Claude Code on behalf of Claus Ibsen_
--
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]