davsclaus commented on code in PR #27247:
URL: https://github.com/apache/camel/pull/27247#discussion_r4163317572


##########
docs/user-manual/modules/ROOT/pages/camel-4x-upgrade-guide-4_23.adoc:
##########
@@ -737,6 +737,15 @@ in the charset that the `Content-Type` declares, so the 
bytes match the header.
 the declared charset and read such a response as UTF-8 must now use the 
declared charset, and characters that the
 declared charset cannot represent are written as `?`.
 
+=== camel-grpc - failed exchanges with the AGGREGATION and PROPAGATION 
consumer strategies

Review Comment:
   Nit (optional, non-blocking): the 4.23 guide already has a `=== camel-grpc` 
section (around line 2243, about `muteException`). Could this note go there as 
a `====` subsection, or at least sit next to it? Right now it sits between the 
platform-http-vertx and "Components and Language removal" sections, far from 
the other gRPC notes.



##########
components/camel-grpc/src/test/java/org/apache/camel/component/grpc/GrpcConsumerStreamingExceptionTest.java:
##########
@@ -0,0 +1,151 @@
+/*
+ * 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.grpc;
+
+import java.util.List;
+import java.util.concurrent.CountDownLatch;
+import java.util.concurrent.TimeUnit;
+
+import io.grpc.ManagedChannel;
+import io.grpc.ManagedChannelBuilder;
+import io.grpc.Status;
+import io.grpc.StatusRuntimeException;
+import io.grpc.stub.StreamObserver;
+import org.apache.camel.CamelException;
+import org.apache.camel.builder.RouteBuilder;
+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.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertInstanceOf;
+import static org.junit.jupiter.api.Assertions.assertNull;
+import static org.junit.jupiter.api.Assertions.assertTrue;
+
+/**
+ * With the AGGREGATION and PROPAGATION consumer strategies a failed exchange 
must end the call with an error, as for
+ * unary calls, and not send the message body as a response.
+ */
+public class GrpcConsumerStreamingExceptionTest extends GrpcTestSupport {
+
+    private static final String ROUTE_EXCEPTION_MESSAGE = "GRPC Camel 
streaming exception message";
+
+    private ManagedChannel aggregationChannel;
+    private ManagedChannel propagationChannel;
+
+    @BeforeEach
+    public void startGrpcChannels() {
+        aggregationChannel = ManagedChannelBuilder.forAddress("localhost", 
getRoutePort("grpc-aggregation"))
+                .usePlaintext().build();
+        propagationChannel = ManagedChannelBuilder.forAddress("localhost", 
getRoutePort("grpc-propagation"))
+                .usePlaintext().build();
+    }
+
+    @AfterEach
+    public void stopGrpcChannels() {
+        if (aggregationChannel != null) {
+            aggregationChannel.shutdown().shutdownNow();
+        }
+        if (propagationChannel != null) {
+            propagationChannel.shutdown().shutdownNow();
+        }
+    }
+
+    @Test
+    public void testAggregationFailureIsSentAsError() throws Exception {
+        PongResponseStreamObserver responseObserver = 
call(PingPongGrpc.newStub(aggregationChannel));
+
+        assertNull(responseObserver.pongResponse, "no response must be sent 
for a failed exchange");
+        assertInternalError(responseObserver.error);
+    }
+
+    @Test
+    public void testPropagationFailureIsSentAsError() throws Exception {
+        PongResponseStreamObserver responseObserver = 
call(PingPongGrpc.newStub(propagationChannel));
+
+        assertNull(responseObserver.pongResponse, "no response must be sent 
for a failed exchange");

Review Comment:
   Thanks for the regression test. Each test sends only one message, so it 
doesn't show the new propagation behaviour described in the upgrade guide: 
messages after the failure are not routed, and the call isn't closed twice. 
Could you add a case that sends two messages before `onCompleted()` and checks 
the route ran only once (for example with a mock endpoint or a counter)?
   
   A case for the default `muteException=true` (description `Exchange 
processing failed`) on a streaming route would also cover the shared 
`toStatusException` path. Optional: a route using 
`onException(...).handled(true)` that keeps the stream open, since the upgrade 
note recommends it.



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