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


##########
components/camel-azure/camel-azure-servicebus/src/test/java/org/apache/camel/component/azure/servicebus/ServiceBusConsumerTest.java:
##########
@@ -385,6 +385,103 @@ private void 
synchronizationDeadLettersMessageWithOptionsWhenExceptionPresent(Su
         }
     }
 
+    @Test
+    void synchronizationBoundsTheDeadLetterReasonAndDescription() throws 
Exception {
+        try (ServiceBusConsumer consumer = new ServiceBusConsumer(endpoint, 
processor)) {
+            
when(configuration.getServiceBusReceiveMode()).thenReturn(ServiceBusReceiveMode.PEEK_LOCK);
+            when(configuration.isEnableDeadLettering()).thenReturn(true);
+
+            consumer.doStart();
+            when(messageContext.getMessage()).thenReturn(message);
+            processMessageCaptor.getValue().accept(messageContext);
+
+            Exchange exchange = exchangeCaptor.getValue();
+            
exchange.setException(exceptionWithALongMessageAndADeepStackTrace());
+
+            Synchronization synchronization = 
exchange.getExchangeExtension().handoverCompletions().get(0);
+            synchronization.onFailure(exchange);
+
+            ArgumentCaptor<DeadLetterOptions> captor = ArgumentCaptor.captor();
+            verify(messageContext).deadLetter(captor.capture());
+            DeadLetterOptions options = captor.getValue();
+
+            // the .NET and JavaScript SDKs cap both fields at 4096 
(MaxDeadLetterReasonLength, applied to the
+            // description too); the Java SDK does not check, so an over-long 
value would only fail at the broker
+            assertThat(options.getDeadLetterReason())
+                    .hasSizeLessThanOrEqualTo(4096)
+                    .startsWith(IllegalStateException.class.getName())
+                    .endsWith("...");
+            assertThat(options.getDeadLetterErrorDescription())
+                    .hasSizeLessThanOrEqualTo(4096)
+                    .contains(getClass().getName())
+                    .endsWith("...");
+        }
+    }
+
+    @Test
+    void synchronizationReportsARejectedDeadLetterInsteadOfThrowing() throws 
Exception {
+        try (ServiceBusConsumer consumer = new ServiceBusConsumer(endpoint, 
processor)) {
+            
when(configuration.getServiceBusReceiveMode()).thenReturn(ServiceBusReceiveMode.PEEK_LOCK);
+            when(configuration.isEnableDeadLettering()).thenReturn(true);
+            consumer.setExceptionHandler(exceptionHandler);
+
+            consumer.doStart();
+            when(messageContext.getMessage()).thenReturn(message);
+            processMessageCaptor.getValue().accept(messageContext);
+
+            Exchange exchange = exchangeCaptor.getValue();
+            final Exception routeFailure = new Exception("Test exception");
+            exchange.setException(routeFailure);
+
+            // the broker refuses the request, for instance because the 
message is over the size quota
+            final RuntimeException rejected = new 
IllegalStateException("Dead-lettering rejected");
+            
doThrow(rejected).when(messageContext).deadLetter(any(DeadLetterOptions.class));
+
+            Synchronization synchronization = 
exchange.getExchangeExtension().handoverCompletions().get(0);
+            // must not escape into the SDK's processor callback, where 
nothing would report it

Review Comment:
   This comment still has the old wording: the exception never reached the SDK 
callback, it was logged as a WARN by `UnitOfWorkHelper.doneSynchronization`.
   
   ```suggestion
               // must go to the consumer's exception handler, not the generic 
onCompletion WARN of the unit of work
   ```



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