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 62cf288263b..db7e6c834c6 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 3d35752c408..f57ad182f26 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()) }