Yicong-Huang commented on code in PR #5440:
URL: https://github.com/apache/texera/pull/5440#discussion_r3368608615


##########
amber/src/test/scala/org/apache/texera/amber/engine/architecture/controller/ClientEventSpec.scala:
##########
@@ -0,0 +1,242 @@
+/*
+ * 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.texera.amber.engine.architecture.controller
+
+import org.apache.pekko.actor.ActorSystem
+import org.apache.pekko.serialization.{Serialization, SerializationExtension}
+import org.apache.pekko.testkit.TestKit
+import org.apache.texera.amber.core.tuple.Tuple
+import org.apache.texera.amber.core.virtualidentity.ActorVirtualIdentity
+import 
org.apache.texera.amber.engine.architecture.rpc.controlreturns.WorkflowAggregatedState
+import org.apache.texera.amber.engine.common.AmberRuntime
+import 
org.apache.texera.amber.engine.common.ambermessage.WorkflowFIFOMessagePayload
+import 
org.apache.texera.amber.engine.common.executionruntimestate.OperatorMetrics
+import org.scalatest.BeforeAndAfterAll
+import org.scalatest.flatspec.AnyFlatSpec
+
+class ClientEventSpec extends AnyFlatSpec with BeforeAndAfterAll {
+
+  // 
---------------------------------------------------------------------------
+  // Suite-local ActorSystem injected into AmberRuntime.serde via reflection
+  // 
---------------------------------------------------------------------------
+  //
+  // The serde round-trips below use the production wire path
+  // (AmberRuntime.serde), so we own a real ActorSystem and shut it down in
+  // afterAll. Pattern matches CheckpointSubsystemSpec / 
LogreplayPrimitivesSpec.
+
+  private val testSystem: ActorSystem =
+    ActorSystem("ClientEventSpec-test", AmberRuntime.pekkoConfig)
+  private val testSerde: Serialization = SerializationExtension(testSystem)
+
+  private def setAmberRuntimeField(name: String, value: AnyRef): Unit = {
+    val field = AmberRuntime.getClass.getDeclaredField(name)
+    field.setAccessible(true)
+    field.set(AmberRuntime, value)
+  }
+
+  override protected def beforeAll(): Unit = {
+    super.beforeAll()
+    setAmberRuntimeField("_actorSystem", testSystem)
+    setAmberRuntimeField("_serde", testSerde)
+  }
+
+  override protected def afterAll(): Unit = {
+    setAmberRuntimeField("_serde", null)
+    setAmberRuntimeField("_actorSystem", null)
+    TestKit.shutdownActorSystem(testSystem)
+    super.afterAll()
+  }
+
+  private def roundTrip[T <: ClientEvent](e: T): T = {
+    val bytes = AmberRuntime.serde.serialize(e).get
+    AmberRuntime.serde
+      .deserialize(bytes, e.getClass.asInstanceOf[Class[T]])
+      .get
+  }
+
+  // 
---------------------------------------------------------------------------
+  // Compile-time pin: every subtype extends ClientEvent + 
WorkflowFIFOMessagePayload
+  // 
---------------------------------------------------------------------------
+  //
+  // The `: ClientEvent` ascriptions in the per-subtype tests would fail to
+  // compile if the subtype no longer extends the trait, so the membership
+  // contract is enforced at compile time. We additionally assert
+  // `isInstanceOf[WorkflowFIFOMessagePayload]` for the trait parent (which
+  // ClientEvent itself extends) — a regression that demoted ClientEvent off
+  // WorkflowFIFOMessagePayload would surface here.
+
+  "ClientEvent subtypes" should "all extend WorkflowFIFOMessagePayload (via 
the ClientEvent trait)" in {
+    val all: List[ClientEvent] = List(
+      ExecutionStateUpdate(WorkflowAggregatedState.READY),
+      ExecutionStatsUpdate(Map.empty),
+      RuntimeStatisticsPersist(Map.empty),
+      ReportCurrentProcessingTuple("op", Array.empty),
+      WorkerAssignmentUpdate(Map.empty),
+      FatalError(new RuntimeException("x")),
+      UpdateExecutorCompleted(ActorVirtualIdentity("w")),
+      ReplayStatusUpdate(ActorVirtualIdentity("w"), status = true),
+      WorkflowRecoveryStatus(isRecovering = false)
+    )
+    all.foreach(e => assert(e.isInstanceOf[WorkflowFIFOMessagePayload]))
+  }

Review Comment:
   can this be verified during compilation? if so I suggest we don't add this: 
later new messages could forget here. If not let's keep it



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