gnodet-bot commented on code in PR #30912:
URL: https://github.com/apache/camel/pull/30912#discussion_r4716765288
##########
core/camel-support/src/main/java/org/apache/camel/support/cluster/RebalancingCamelClusterService.java:
##########
@@ -104,13 +125,45 @@ public void setDelegate(CamelPreemptiveClusterService
delegate) {
this.delegate = delegate;
}
+ /**
+ * Runs a rebalancing pass, and schedules the next one on the same
executor while it is the executor of this
Review Comment:
🔍 **Stack trace only at DEBUG on repeated failures.** The WARN message logs
only `e.toString()` with no stack trace — the stack is at DEBUG. For a novel
exception type with an unhelpful `toString()`, this is hard to diagnose without
enabling DEBUG. Consider including `e.getMessage()` plus the root cause type
(e.g. `": " + e.getClass().getSimpleName()`) at WARN level for the first
occurrence.
##########
core/camel-core/src/test/java/org/apache/camel/cluster/RebalancingClusterServiceLoopTest.java:
##########
@@ -0,0 +1,331 @@
+/*
+ * 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.cluster;
+
+import java.util.Collection;
+import java.util.List;
+import java.util.Optional;
+import java.util.Queue;
+import java.util.UUID;
+import java.util.concurrent.ConcurrentLinkedQueue;
+import java.util.concurrent.CopyOnWriteArrayList;
+import java.util.concurrent.CountDownLatch;
+import java.util.concurrent.TimeUnit;
+import java.util.concurrent.atomic.AtomicInteger;
+import java.util.concurrent.atomic.AtomicReference;
+
+import org.apache.camel.CamelContext;
+import org.apache.camel.impl.DefaultCamelContext;
+import org.apache.camel.support.cluster.AbstractCamelClusterService;
+import org.apache.camel.support.cluster.AbstractCamelClusterView;
+import org.apache.camel.support.cluster.RebalancingCamelClusterService;
+import org.apache.logging.log4j.Level;
+import org.apache.logging.log4j.LogManager;
+import org.apache.logging.log4j.core.LogEvent;
+import org.apache.logging.log4j.core.LoggerContext;
+import org.apache.logging.log4j.core.appender.AbstractAppender;
+import org.apache.logging.log4j.core.config.Property;
+import org.junit.jupiter.api.AfterEach;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
+
+import static org.awaitility.Awaitility.await;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertTrue;
+
+/**
+ * The passes of the rebalancing cluster service form one chain: a failing
pass does not end it, and a stop and start of
+ * the service does not leave the chain of the previous start running next to
the new one.
+ */
+class RebalancingClusterServiceLoopTest {
+
+ private static final long PERIOD_MILLIS = 200;
+
+ private CamelContext context;
+ private TestClusterService delegate;
+ private CountingRebalancingClusterService service;
+
+ @BeforeEach
+ void setUp() throws Exception {
+ context = new DefaultCamelContext();
+ delegate = new TestClusterService("node-1");
+ service = new CountingRebalancingClusterService(delegate);
+ context.addService(service);
+ }
+
+ @AfterEach
+ void tearDown() {
+ context.stop();
+ }
+
+ @Test
+ void failingPassDoesNotEndRebalancing() throws Exception {
+ context.start();
+ delegate.getView("my-ns");
+ await().atMost(10, TimeUnit.SECONDS).until(() -> service.passes.get()
>= 2);
+
+ delegate.failures.set(1);
+ await().atMost(10, TimeUnit.SECONDS).until(() ->
delegate.failures.get() == 0);
+ int passes = service.passes.get();
+
+ // the next passes run, and they still rebalance: a disabled partition
of the only member is opened
+ TestClusterView view = delegate.view("my-ns");
+ view.setDisabled(true);
+ await().atMost(10, TimeUnit.SECONDS).until(() -> service.passes.get()
>= passes + 3 && !view.isDisabled());
+ }
+
+ @Test
+ void restartDoesNotAddChainOfPasses() throws Exception {
+ context.start();
+ delegate.getView("my-ns");
+ await().atMost(10, TimeUnit.SECONDS).until(() -> service.passes.get()
>= 2);
+
+ for (int i = 0; i < 3; i++) {
+ service.stop();
+ Thread stopped = service.lastThread;
+ service.threads.clear();
+ service.start();
Review Comment:
🔍 **Magic number `3` in ceiling formula.** A brief comment explaining why
`3` (e.g., "accounts for the in-flight pass at both window boundaries and timer
jitter") would help future maintainers understand why this constant is safe.
--
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]