eugenegujing commented on code in PR #8969:
URL: https://github.com/apache/texera/pull/8969#discussion_r4572541725


##########
amber/src/test/scala/org/apache/texera/web/service/ExecutionReconfigurationServiceSpec.scala:
##########
@@ -477,6 +503,97 @@ class ExecutionReconfigurationServiceSpec
     queued.map(_._1.id) shouldBe List(alreadyQueued.id)
   }
 
+  /** Sends an edit to a deployed `deployedOp` with one reconfiguration 
already pending and
+    * returns the response together with the ids left in the pending queue.
+    */
+  private def modifyWithOnePending(
+      deployedOp: LogicalOp,
+      request: LogicalOp
+  ): (TexeraWebSocketEvent, List[PhysicalOpIdentity]) = {
+    val stateStore = new ExecutionStateStore
+    val service = new WorkflowOnlyService(stateStore, 
mkWorkflow(List(deployedOp)))
+    val alreadyQueued = mkPhysicalOp("already-queued")
+    stateStore.reconfigurationStore.updateState(_ =>
+      ExecutionReconfigurationStore(unscheduledReconfigurations = 
List((alreadyQueued, None)))
+    )
+    val response = service.modifyOperatorLogic(ModifyLogicRequest(request))
+    val queued = 
stateStore.reconfigurationStore.getState.unscheduledReconfigurations
+    (response, queued.map(_._1.id))
+  }
+
+  it should "report an operator without a reconfiguration override as a 
rejected edit" in {
+    // DummyOpDesc advertises supportReconfiguration but inherits the 
LogicalOp base, which
+    // throws UnsupportedOperationException instead of returning Failure.
+    val opId = "dummy-op"
+    val deployedOp = new DummyOpDesc
+    deployedOp.setOperatorId(opId)
+
+    val (response, queued) = modifyWithOnePending(deployedOp, mkLimitOp(opId, 
7))
+
+    response shouldBe a[ModifyLogicResponse]
+    val rejected = response.asInstanceOf[ModifyLogicResponse]
+    rejected.opId shouldBe opId
+    rejected.isValid shouldBe false
+    rejected.errorMessage should include("DummyOpDesc does not support 
reconfiguration")
+    queued shouldBe List(mkPhysicalOp("already-queued").id)
+  }
+
+  it should "report an operator whose reconfiguration override throws as a 
rejected edit" in {
+    val opId = "throwing-op"
+    val deployedOp =
+      new ThrowingReconfigurationOpDesc(() => new 
IllegalStateException(thrownMessage))
+    deployedOp.setOperatorId(opId)
+
+    val (response, queued) = modifyWithOnePending(deployedOp, mkLimitOp(opId, 
7))
+
+    response shouldBe a[ModifyLogicResponse]
+    val rejected = response.asInstanceOf[ModifyLogicResponse]
+    rejected.opId shouldBe opId
+    rejected.isValid shouldBe false
+    rejected.errorMessage shouldBe thrownMessage
+    queued shouldBe List(mkPhysicalOp("already-queued").id)
+  }
+
+  it should "describe a rejection by its exception type when the exception has 
no message" in {
+    val opId = "throwing-op"
+    val deployedOp = new ThrowingReconfigurationOpDesc(() => new 
IllegalStateException())
+    deployedOp.setOperatorId(opId)
+
+    val (response, queued) = modifyWithOnePending(deployedOp, mkLimitOp(opId, 
7))
+
+    response shouldBe a[ModifyLogicResponse]
+    val rejected = response.asInstanceOf[ModifyLogicResponse]
+    rejected.isValid shouldBe false
+    rejected.errorMessage shouldBe "java.lang.IllegalStateException"
+    queued shouldBe List(mkPhysicalOp("already-queued").id)
+  }
+
+  it should "let a fatal reconfiguration exception escape instead of reporting 
a rejection" in {
+    val opId = "throwing-op"
+    val deployedOp = new ThrowingReconfigurationOpDesc(() => new 
InterruptedException("stop"))
+    deployedOp.setOperatorId(opId)
+
+    an[InterruptedException] should be thrownBy 
modifyWithOnePending(deployedOp, mkLimitOp(opId, 7))
+  }
+
+  it should "accept a valid edit after a rejected one" in {
+    val rejectedId = "dummy-op"
+    val dummy = new DummyOpDesc
+    dummy.setOperatorId(rejectedId)
+    val acceptedId = "limit-op"
+    val stateStore = new ExecutionStateStore
+    val service =
+      new WorkflowOnlyService(stateStore, mkWorkflow(List(dummy, 
mkLimitOp(acceptedId, 5))))
+
+    val first = 
service.modifyOperatorLogic(ModifyLogicRequest(mkLimitOp(rejectedId, 7)))
+    val second = 
service.modifyOperatorLogic(ModifyLogicRequest(mkLimitOp(acceptedId, 9)))
+
+    first.asInstanceOf[ModifyLogicResponse].isValid shouldBe false
+    second.asInstanceOf[ModifyLogicResponse].isValid shouldBe true
+    val queued = 
stateStore.reconfigurationStore.getState.unscheduledReconfigurations
+    queued.map(_._1.id.logicalOpId.id) shouldBe List(acceptedId)
+  }

Review Comment:
   Fixed in b0da6cf21ae98f47dab15123979026745b5fb822.



-- 
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