aglinxinyuan commented on code in PR #9510: URL: https://github.com/apache/texera/pull/9510#discussion_r4596110651
########## amber/src/test/scala/org/apache/texera/amber/engine/common/AmberSerdeTestSupport.scala: ########## @@ -0,0 +1,107 @@ +/* + * 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.common + +import org.apache.pekko.actor.ActorSystem +import org.apache.pekko.serialization.{Serialization, SerializationExtension} +import org.apache.pekko.testkit.TestKit +import org.scalatest.{BeforeAndAfterAll, Suite} + +import java.nio.file.{FileSystemException, Files, Path} + +/** + * Mixin for specs that drive [[AmberRuntime.serde]] with a suite-local Pekko + * `ActorSystem`, plus best-effort recursive temp-directory cleanup. + */ +trait AmberSerdeTestSupport extends BeforeAndAfterAll { this: Suite => + + protected def amberSystemName: String = s"${getClass.getSimpleName}-test" + protected def lazyAmberActorSystem: Boolean = false + protected def restorePriorAmberRuntime: Boolean = false + + protected lazy val testSystem: ActorSystem = + ActorSystem(amberSystemName, AmberRuntime.pekkoConfig) + protected lazy val testSerde: Serialization = SerializationExtension(testSystem) + + if (!lazyAmberActorSystem) { + val _ = testSerde + } Review Comment: Done in c023ba0cb4. Both flags are gone, so the system is always built on first use and `afterAll` always restores the prior runtime; `deleteRecursively` went too, and the four storage and replay-log specs now clean up with `FileUtils.deleteQuietly`. ########## amber/src/test/scala/org/apache/texera/amber/engine/e2e/RetryingDatabaseE2ESpec.scala: ########## @@ -0,0 +1,115 @@ +/* + * 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.e2e + +import com.twitter.util.Duration +import com.typesafe.scalalogging.Logger +import org.apache.pekko.actor.{ActorSystem, Props} +import org.apache.pekko.testkit.{ImplicitSender, TestKit} +import org.apache.pekko.util.Timeout +import org.apache.texera.amber.clustering.SingleNodeListener +import org.apache.texera.amber.core.workflow.PortIdentity +import org.apache.texera.amber.engine.common.AmberRuntime +import org.apache.texera.amber.engine.e2e.TestUtils.{ + cleanupWorkflowExecutionData, + initiateTexeraDBForTestCases, + setUpWorkflowExecutionData +} +import org.apache.texera.amber.operator.TestOperators +import org.apache.texera.amber.operator.source.scan.text.TextInputSourceOpDesc +import org.apache.texera.common.compiler.model.LogicalLink +import org.scalatest.{BeforeAndAfterAll, BeforeAndAfterEach, Outcome, Retries} +import org.scalatest.flatspec.AnyFlatSpecLike + +import scala.concurrent.duration.DurationInt + +/** + * Shared retrying TestKit + database setup/teardown fixture for Amber E2E suites. + * Each subclass passes a unique `specId` so concurrent Iceberg and DB state stays isolated. + */ +abstract class RetryingDatabaseE2ESpec( + actorSystemName: String, + protected val specId: Int +) extends TestKit(ActorSystem(actorSystemName, AmberRuntime.pekkoConfig)) + with ImplicitSender + with AnyFlatSpecLike + with BeforeAndAfterAll + with BeforeAndAfterEach + with Retries { Review Comment: Left out on purpose: `LoopIntegrationSpec` is edited by #9412, #9366, #9359 and #8671, the two handler specs and the stats/console specs by #9508, and `ExecutionResultServiceSpec` by #9271 and #9272, so this PR stays clear of all of them. They can move to the shared fixtures once those land. ########## amber/src/test/scala/org/apache/texera/web/service/RecordingExecutionClient.scala: ########## @@ -0,0 +1,117 @@ +/* + * 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.web.service + +import com.twitter.util.Future +import io.reactivex.rxjava3.disposables.Disposable +import org.apache.pekko.actor.ActorSystem +import org.apache.texera.amber.core.workflow.{PhysicalPlan, WorkflowContext} +import org.apache.texera.amber.engine.architecture.coordinator.CoordinatorConfig +import org.apache.texera.amber.engine.architecture.rpc.controlreturns.EmptyReturn +import org.apache.texera.amber.engine.architecture.rpc.coordinatorservice.CoordinatorServiceFs2Grpc +import org.apache.texera.amber.engine.common.client.AmberClient + +import java.lang.reflect.{InvocationHandler, Method, Proxy} +import scala.collection.mutable +import scala.reflect.ClassTag + +/** + * Empty-plan `AmberClient` for execution-service unit specs: captures registered callbacks, + * honors subscription disposal, and optionally records coordinator RPC invocations. + */ +class RecordingExecutionClient( + system: ActorSystem, + customCoordinator: Option[CoordinatorServiceFs2Grpc[Future, Unit]] = None +) extends AmberClient( + system, + new WorkflowContext(), + PhysicalPlan(Set.empty, Set.empty), + CoordinatorConfig(None, None, None, None), + _ => () + ) { + + var shutdownCount = 0 + private val callbacks = mutable.Map.empty[Class[_], Any => Unit] + + /** `(method name, request)` of every call made through `coordinatorInterface` when no mock is provided. */ + val coordinatorCalls: mutable.ArrayBuffer[(String, Any)] = mutable.ArrayBuffer.empty + + /** Event class of every `Disposable` handed out by `registerCallback` that was later disposed. */ + val disposedCallbacks: mutable.ArrayBuffer[Class[_]] = mutable.ArrayBuffer.empty + + override val coordinatorInterface: CoordinatorServiceFs2Grpc[Future, Unit] = + customCoordinator.getOrElse( + Proxy + .newProxyInstance( + classOf[CoordinatorServiceFs2Grpc[Future, Unit]].getClassLoader, + Array(classOf[CoordinatorServiceFs2Grpc[Future, Unit]]), + new InvocationHandler { + override def invoke(proxy: Any, method: Method, args: Array[AnyRef]): AnyRef = { + if (args == null || args.isEmpty) { + if (method.getName == "hashCode") Integer.valueOf(System.identityHashCode(proxy)) + else if (method.getName == "toString") "TestCoordinatorInterface" + else null + } else { + coordinatorCalls += ((method.getName, args(0))) + Future.value(EmptyReturn()) + } + } + } + ) + .asInstanceOf[CoordinatorServiceFs2Grpc[Future, Unit]] + ) + + override def shutdown(): Unit = { + shutdownCount += 1 + super.shutdown() + } + + override def registerCallback[T](callback: T => Unit)(implicit ct: ClassTag[T]): Disposable = { + val clazz = ct.runtimeClass + callbacks(clazz) = callback.asInstanceOf[Any => Unit] + Disposable.fromAction(() => { + callbacks.remove(clazz) + disposedCallbacks += clazz + }) + } Review Comment: Done in c023ba0cb4. `callbacks` now keeps a list per event class, disposing removes only that registration, and `fire` delivers to each one in registration order (over a copy, so a callback can dispose itself mid-delivery). -- 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]
