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

aglinxinyuan pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/texera.git


The following commit(s) were added to refs/heads/main by this push:
     new bb6b52ba74 fix: reset iteration cursor in OneOnEach.initialize (#5028)
bb6b52ba74 is described below

commit bb6b52ba745dd55572c701f60d43455455e09961
Author: Matthew B. <[email protected]>
AuthorDate: Wed May 13 14:56:17 2026 -0700

    fix: reset iteration cursor in OneOnEach.initialize (#5028)
    
    ### What changes were proposed in this PR?
    `OneOnEach.initialize` now resets `index` to `0` in addition to
    replacing the `available` array. Previously, re-initializing an existing
    instance left the cursor at its prior position, causing `next()` to skip
    elements or
    throw `IndexOutOfBoundsException` when the new array was shorter than
    the old cursor value.
    
      ### Any related issues, documentation, or discussions?
      Closes: #4731
    
      ### How was this PR tested?
    - Updated `DeployStrategiesSpec` so the previously-pinned "cursor
    survives re-initialization" test now asserts the corrected behavior
    (cursor reset, new array fully consumed, exhaustion still raises
      `IndexOutOfBoundsException`).
    - `sbt "WorkflowExecutionService/testOnly ...DeployStrategiesSpec"` —
    13/13 pass.
    
      ### Was this PR authored or co-authored using generative AI tooling?
      Co-authored with Claude Opus 4.7 in compliance with ASF
---
 .../deploysemantics/deploystrategy/OneOnEach.scala             |  1 +
 .../deploysemantics/deploystrategy/DeployStrategiesSpec.scala  | 10 +++-------
 2 files changed, 4 insertions(+), 7 deletions(-)

diff --git 
a/amber/src/main/scala/org/apache/texera/amber/engine/architecture/deploysemantics/deploystrategy/OneOnEach.scala
 
b/amber/src/main/scala/org/apache/texera/amber/engine/architecture/deploysemantics/deploystrategy/OneOnEach.scala
index 62cf288263..db7e6c834c 100644
--- 
a/amber/src/main/scala/org/apache/texera/amber/engine/architecture/deploysemantics/deploystrategy/OneOnEach.scala
+++ 
b/amber/src/main/scala/org/apache/texera/amber/engine/architecture/deploysemantics/deploystrategy/OneOnEach.scala
@@ -31,6 +31,7 @@ class OneOnEach extends DeployStrategy {
 
   override def initialize(available: Array[Address]): Unit = {
     this.available = available
+    this.index = 0
   }
 
   override def next(): Address = {
diff --git 
a/amber/src/test/scala/org/apache/texera/amber/engine/architecture/deploysemantics/deploystrategy/DeployStrategiesSpec.scala
 
b/amber/src/test/scala/org/apache/texera/amber/engine/architecture/deploysemantics/deploystrategy/DeployStrategiesSpec.scala
index 3d35752c40..f57ad182f2 100644
--- 
a/amber/src/test/scala/org/apache/texera/amber/engine/architecture/deploysemantics/deploystrategy/DeployStrategiesSpec.scala
+++ 
b/amber/src/test/scala/org/apache/texera/amber/engine/architecture/deploysemantics/deploystrategy/DeployStrategiesSpec.scala
@@ -55,17 +55,13 @@ class DeployStrategiesSpec extends AnyFlatSpec with 
Matchers {
     assertThrows[IndexOutOfBoundsException](strategy.next())
   }
 
-  it should "preserve its iteration cursor across re-initialization (current 
behavior)" in {
-    // Pin: initialize() replaces the array reference but does NOT reset the
-    // index, so a re-initialized strategy continues counting from the prior
-    // position. A future fix that zeroes index inside initialize will break
-    // this spec on purpose so the contract change is reviewed.
+  it should "reset its iteration cursor on re-initialization" in {
     val strategy = OneOnEach()
     strategy.initialize(Array(nodeA, nodeB))
     strategy.next() shouldBe nodeA
+    strategy.next() shouldBe nodeB
     strategy.initialize(Array(nodeC))
-    // index is still 1 from the previous run; the new single-element array
-    // is therefore reported as exhausted.
+    strategy.next() shouldBe nodeC
     assertThrows[IndexOutOfBoundsException](strategy.next())
   }
 

Reply via email to