This is an automated email from the ASF dual-hosted git repository.

xuba pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/amoro.git


The following commit(s) were added to refs/heads/master by this push:
     new 2528923b0 [Bug] fix the of TestOptimizerGroupKeeper unit test suffers 
from intermittent failures. (#4152)
2528923b0 is described below

commit 2528923b0b7107ed4bbc00367cdad9d38a2cccda
Author: can <[email protected]>
AuthorDate: Mon Mar 30 20:36:06 2026 +0800

    [Bug] fix the of TestOptimizerGroupKeeper unit test suffers from 
intermittent failures. (#4152)
    
    [Bug] fix the of TestOptimizerGroupKeeper unit test suffers from 
intermittent failures. #4151
    
    Co-authored-by: wardli <[email protected]>
---
 .../apache/amoro/server/TestOptimizerGroupKeeper.java | 19 +++++++++++++++----
 1 file changed, 15 insertions(+), 4 deletions(-)

diff --git 
a/amoro-ams/src/test/java/org/apache/amoro/server/TestOptimizerGroupKeeper.java 
b/amoro-ams/src/test/java/org/apache/amoro/server/TestOptimizerGroupKeeper.java
index 72ff58753..889fb02cc 100644
--- 
a/amoro-ams/src/test/java/org/apache/amoro/server/TestOptimizerGroupKeeper.java
+++ 
b/amoro-ams/src/test/java/org/apache/amoro/server/TestOptimizerGroupKeeper.java
@@ -49,6 +49,7 @@ import java.util.Map;
 import java.util.concurrent.atomic.AtomicBoolean;
 import java.util.concurrent.atomic.AtomicInteger;
 import java.util.function.Function;
+import java.util.function.Supplier;
 
 @RunWith(Parameterized.class)
 public class TestOptimizerGroupKeeper extends AMSTableTestBase {
@@ -80,7 +81,7 @@ public class TestOptimizerGroupKeeper extends 
AMSTableTestBase {
   @Before
   public void prepare() throws Exception {
     optimizerRegistrar = registerInfo -> 
optimizingService().authenticate(registerInfo);
-    setupMockContainer();
+    setupMockContainer(() -> currentGroupName);
   }
 
   @After
@@ -124,9 +125,10 @@ public class TestOptimizerGroupKeeper extends 
AMSTableTestBase {
   }
 
   /** Setup mock container and inject it into Containers using reflection. */
-  private void setupMockContainer() throws Exception {
+  private void setupMockContainer(Supplier<String> targetGroupNameSupplier) 
throws Exception {
     MockOptimizerContainer mockContainer =
-        new MockOptimizerContainer(resourceAvailable, scaleOutCallCount, 
optimizerRegistrar);
+        new MockOptimizerContainer(
+            resourceAvailable, scaleOutCallCount, optimizerRegistrar, 
targetGroupNameSupplier);
 
     // Use reflection to set isInitialized to true
     DynFields.UnboundField<Boolean> initializedField =
@@ -339,14 +341,17 @@ public class TestOptimizerGroupKeeper extends 
AMSTableTestBase {
     private final AtomicBoolean resourceAvailable;
     private final AtomicInteger scaleOutCallCount;
     private final Function<OptimizerRegisterInfo, String> optimizerRegistrar;
+    private final Supplier<String> targetGroupNameSupplier;
 
     public MockOptimizerContainer(
         AtomicBoolean resourceAvailable,
         AtomicInteger scaleOutCallCount,
-        Function<OptimizerRegisterInfo, String> optimizerRegistrar) {
+        Function<OptimizerRegisterInfo, String> optimizerRegistrar,
+        Supplier<String> targetGroupNameSupplier) {
       this.resourceAvailable = resourceAvailable;
       this.scaleOutCallCount = scaleOutCallCount;
       this.optimizerRegistrar = optimizerRegistrar;
+      this.targetGroupNameSupplier = targetGroupNameSupplier;
     }
 
     @Override
@@ -354,6 +359,12 @@ public class TestOptimizerGroupKeeper extends 
AMSTableTestBase {
 
     @Override
     protected Map<String, String> doScaleOut(Resource resource) {
+      String targetGroup = targetGroupNameSupplier != null ? 
targetGroupNameSupplier.get() : null;
+      if (targetGroup != null && !targetGroup.equals(resource.getGroupName())) 
{
+        // Stale task from a previously leaked group; silently ignore to 
prevent cross-test
+        // contamination of scaleOutCallCount via the shared static Containers 
registry.
+        return Maps.newHashMap();
+      }
       scaleOutCallCount.incrementAndGet();
       if (!resourceAvailable.get()) {
         throw new RuntimeException("No resources available");

Reply via email to