Croway commented on code in PR #27380:
URL: https://github.com/apache/camel/pull/27380#discussion_r4185800378


##########
core/camel-console/src/main/java/org/apache/camel/impl/console/EventConsole.java:
##########
@@ -71,6 +71,12 @@ public int getCapacity() {
 
     public void setCapacity(int capacity) {

Review Comment:
   Done in 2451c064853f: when the buffers are already allocated, `setCapacity` 
runs the same check as `doInit()` (shared `ConsoleHelper.checkCapacity`, same 
message) before resizing, and leaves the capacity unchanged when it fails. A 
value from Camel Main outside 25-1000 now fails at startup; the upgrade guide 
says so, including values below the minimum that were accepted before.
   
   _Claude Code on behalf of Croway_



##########
core/camel-console/src/main/java/org/apache/camel/impl/console/SqlTraceDevConsole.java:
##########
@@ -95,6 +95,10 @@ public int getCapacity() {
 
     public void setCapacity(int capacity) {

Review Comment:
   Same fix as in `EventConsole` (2451c064853f).
   
   _Claude Code on behalf of Croway_



##########
core/camel-console/src/main/java/org/apache/camel/impl/console/TraceDevConsole.java:
##########
@@ -79,6 +79,11 @@ public int getCapacity() {
 
     public void setCapacity(int capacity) {

Review Comment:
   Same fix as in `EventConsole` (2451c064853f).
   
   _Claude Code on behalf of Croway_



##########
core/camel-console/src/main/java/org/apache/camel/impl/console/ReceiveDevConsole.java:
##########
@@ -110,6 +110,11 @@ public int getCapacity() {
 
     public void setCapacity(int capacity) {

Review Comment:
   Same fix as in `EventConsole` (2451c064853f).
   
   _Claude Code on behalf of Croway_



##########
core/camel-console/src/test/java/org/apache/camel/impl/console/DevConsoleCapacityTest.java:
##########
@@ -0,0 +1,144 @@
+/*
+ * 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.impl.console;
+
+import java.util.List;
+import java.util.Map;
+
+import org.apache.camel.CamelContext;
+import org.apache.camel.ContextTestSupport;
+import org.apache.camel.builder.RouteBuilder;
+import org.apache.camel.console.DevConsole;
+import org.apache.camel.console.DevConsoleRegistry;
+import org.apache.camel.util.json.JsonObject;
+import org.junit.jupiter.api.Test;
+
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertTrue;
+
+/**
+ * Camel Main sets {@code camel.devConsole.<id>.capacity} on a console the 
registry has already started, so the console
+ * must resize the buffers it allocated with the default capacity.
+ */
+public class DevConsoleCapacityTest extends ContextTestSupport {
+
+    @Override
+    protected CamelContext createCamelContext() throws Exception {
+        CamelContext context = super.createCamelContext();
+        context.setBacklogTracing(true);
+        return context;
+    }
+
+    @Override
+    protected RouteBuilder createRouteBuilder() {
+        return new RouteBuilder() {
+            @Override
+            public void configure() {
+                
from("direct:start").routeId("myRoute").log("${body}").to("mock:result");
+            }
+        };
+    }
+
+    private <T extends DevConsole> T resolve(String id) {
+        // the registry starts the console, as when Camel Main configures it
+        return (T) 
context.getCamelContextExtension().getContextPlugin(DevConsoleRegistry.class).resolveById(id);
+    }
+
+    private void sendMessages(String uri, int count) {
+        for (int i = 0; i < count; i++) {
+            template.sendBody(uri, "Hello " + i);
+        }
+    }
+
+    @Test
+    public void testTraceCapacitySetAfterStart() {
+        TraceDevConsole console = resolve("trace");
+        console.setCapacity(1000);
+
+        // each dump takes up to 100 events from the tracer (its backlog 
size): the second one used to fail with
+        // "Queue full" as the queue still had the default 100 slots
+        int traces = 0;
+        for (int round = 0; round < 3; round++) {
+            sendMessages("direct:start", 50);
+            JsonObject out = (JsonObject) 
console.call(DevConsole.MediaType.JSON, Map.of("dump", "true"));
+            traces = out.getCollection("traces").size();
+        }
+        assertEquals(300, traces);
+    }
+
+    @Test
+    public void testTraceCapacityLoweredAfterStart() {
+        TraceDevConsole console = resolve("trace");
+        sendMessages("direct:start", 50);
+        console.call(DevConsole.MediaType.JSON, Map.of("dump", "true"));
+
+        console.setCapacity(50);
+        sendMessages("direct:start", 50);
+        JsonObject out = (JsonObject) console.call(DevConsole.MediaType.JSON, 
Map.of("dump", "true"));
+        assertEquals(50, out.getCollection("traces").size());
+    }
+
+    @Test
+    public void testReceiveCapacitySetAfterStart() {
+        ReceiveDevConsole console = resolve("receive");
+        console.setCapacity(1000);
+        console.call(DevConsole.MediaType.JSON, Map.of("enabled", "true", 
"endpoint", "direct:incoming"));
+
+        sendMessages("direct:incoming", 150);
+
+        JsonObject out = (JsonObject) console.call(DevConsole.MediaType.JSON, 
Map.of("dump", "true"));
+        List<JsonObject> messages = out.getCollection("messages");
+        assertEquals(150, messages.size());
+        assertEquals(150, messages.get(149).getLong("uid"));
+    }
+
+    @Test
+    public void testEventCapacitySetAfterStart() {
+        EventConsole console = resolve("event");
+        console.setCapacity(1000);
+
+        // used to fail with ArrayIndexOutOfBoundsException once past the 
default 25 slots
+        sendMessages("direct:start", 50);
+
+        JsonObject out = (JsonObject) console.call(DevConsole.MediaType.JSON);
+        assertTrue(out.getCollection("exchangeEvents").size() > 25);
+        assertTrue(((String) 
console.call(DevConsole.MediaType.TEXT)).contains("Exchange Events"));
+    }
+
+    @Test
+    public void testEventCapacityLoweredAfterStart() {
+        EventConsole console = resolve("event");
+        sendMessages("direct:start", 10);
+
+        console.setCapacity(10);

Review Comment:
   Changed: the test raises the capacity to 100, sends 30 messages, lowers it 
to 25 and checks that the newest 25 exchange events are kept. 
`testInvalidCapacitySetAfterStart` now covers below-minimum and above-1000 
values on all four consoles.
   
   _Claude Code on behalf of Croway_



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