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


##########
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:
   Fixed in e3be62b: the first failure is logged at WARN with the full stack 
trace; only repeats go to DEBUG.
   
   _Claude Code on behalf of Claus Ibsen_



##########
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:
   Fixed in 778242c: a comment now explains the ceiling (elapsed / period + 1, 
plus room for the counter and the clock being read at different moments).
   
   _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]

Reply via email to