aglinxinyuan commented on code in PR #4790: URL: https://github.com/apache/texera/pull/4790#discussion_r3177498908
########## amber/src/test/scala/org/apache/texera/amber/engine/architecture/logreplay/EmptyReplayLogManagerImplSpec.scala: ########## @@ -0,0 +1,89 @@ +/* + * 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.logreplay + +import org.apache.texera.amber.core.virtualidentity.{ActorVirtualIdentity, ChannelIdentity} +import org.apache.texera.amber.engine.architecture.common.ProcessingStepCursor +import org.apache.texera.amber.engine.architecture.worker.WorkflowWorker.MainThreadDelegateMessage +import org.apache.texera.amber.engine.common.ambermessage.{ + DataFrame, + WorkflowFIFOMessage, + WorkflowFIFOMessagePayload +} +import org.scalatest.flatspec.AnyFlatSpec + +import scala.collection.mutable + +class EmptyReplayLogManagerImplSpec extends AnyFlatSpec { + + private val channel = + ChannelIdentity(ActorVirtualIdentity("from"), ActorVirtualIdentity("to"), isControl = false) + + private def fifo(seq: Long, payload: WorkflowFIFOMessagePayload = DataFrame(Array.empty)) + : WorkflowFIFOMessage = + WorkflowFIFOMessage(channel, seq, payload) + + private class CapturingHandler { + val received: mutable.ListBuffer[Either[MainThreadDelegateMessage, WorkflowFIFOMessage]] = + mutable.ListBuffer() + val handler: Either[MainThreadDelegateMessage, WorkflowFIFOMessage] => Unit = + msg => received += msg + } + + "EmptyReplayLogManagerImpl" should "expose getStep starting at INIT_STEP" in { + val mgr = new EmptyReplayLogManagerImpl(_ => ()) + assert(mgr.getStep == ProcessingStepCursor.INIT_STEP) + } + + it should "no-op on setupWriter / markAsReplayDestination / terminate" in { + val mgr = new EmptyReplayLogManagerImpl(_ => ()) + // None of these should throw or change observable state. + mgr.setupWriter(null) + mgr.markAsReplayDestination(null) + mgr.terminate() Review Comment: Done in 6b0aea0e3a. Replaced `null` with real fixtures: an `EmptyRecordStorage[ReplayLogRecord]().getWriter("x")` writer and `EmbeddedControlMessageIdentity("test")`. ########## amber/src/test/scala/org/apache/texera/amber/engine/architecture/logreplay/EmptyReplayLogManagerImplSpec.scala: ########## @@ -0,0 +1,89 @@ +/* + * 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.logreplay + +import org.apache.texera.amber.core.virtualidentity.{ActorVirtualIdentity, ChannelIdentity} +import org.apache.texera.amber.engine.architecture.common.ProcessingStepCursor +import org.apache.texera.amber.engine.architecture.worker.WorkflowWorker.MainThreadDelegateMessage +import org.apache.texera.amber.engine.common.ambermessage.{ + DataFrame, + WorkflowFIFOMessage, + WorkflowFIFOMessagePayload +} +import org.scalatest.flatspec.AnyFlatSpec + +import scala.collection.mutable + +class EmptyReplayLogManagerImplSpec extends AnyFlatSpec { + + private val channel = + ChannelIdentity(ActorVirtualIdentity("from"), ActorVirtualIdentity("to"), isControl = false) + + private def fifo(seq: Long, payload: WorkflowFIFOMessagePayload = DataFrame(Array.empty)) + : WorkflowFIFOMessage = + WorkflowFIFOMessage(channel, seq, payload) + + private class CapturingHandler { + val received: mutable.ListBuffer[Either[MainThreadDelegateMessage, WorkflowFIFOMessage]] = + mutable.ListBuffer() + val handler: Either[MainThreadDelegateMessage, WorkflowFIFOMessage] => Unit = + msg => received += msg + } + + "EmptyReplayLogManagerImpl" should "expose getStep starting at INIT_STEP" in { + val mgr = new EmptyReplayLogManagerImpl(_ => ()) + assert(mgr.getStep == ProcessingStepCursor.INIT_STEP) + } + + it should "no-op on setupWriter / markAsReplayDestination / terminate" in { + val mgr = new EmptyReplayLogManagerImpl(_ => ()) + // None of these should throw or change observable state. + mgr.setupWriter(null) + mgr.markAsReplayDestination(null) + mgr.terminate() + assert(mgr.getStep == ProcessingStepCursor.INIT_STEP) + } + + "EmptyReplayLogManagerImpl.sendCommitted" should "forward the message to the configured handler" in { + val cap = new CapturingHandler + val mgr = new EmptyReplayLogManagerImpl(cap.handler) + val msg = Right[MainThreadDelegateMessage, WorkflowFIFOMessage](fifo(1L)) + mgr.sendCommitted(msg) + assert(cap.received.toList == List(msg)) + } + + "ReplayLogManager.withFaultTolerant" should "advance the step counter after the body runs" in { + val mgr = new EmptyReplayLogManagerImpl(_ => ()) + mgr.withFaultTolerant(channel, Some(fifo(1L)))(()) + assert(mgr.getStep == 0L) + mgr.withFaultTolerant(channel, Some(fifo(2L)))(()) + assert(mgr.getStep == 1L) Review Comment: Done in 6b0aea0e3a. Asserting `mgr.getStep == ProcessingStepCursor.INIT_STEP + 1` / `+ 2` and using `{}` block syntax. ########## amber/src/test/scala/org/apache/texera/amber/engine/architecture/logreplay/EmptyReplayLogManagerImplSpec.scala: ########## @@ -0,0 +1,89 @@ +/* + * 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.logreplay + +import org.apache.texera.amber.core.virtualidentity.{ActorVirtualIdentity, ChannelIdentity} +import org.apache.texera.amber.engine.architecture.common.ProcessingStepCursor +import org.apache.texera.amber.engine.architecture.worker.WorkflowWorker.MainThreadDelegateMessage +import org.apache.texera.amber.engine.common.ambermessage.{ + DataFrame, + WorkflowFIFOMessage, + WorkflowFIFOMessagePayload +} +import org.scalatest.flatspec.AnyFlatSpec + +import scala.collection.mutable + +class EmptyReplayLogManagerImplSpec extends AnyFlatSpec { + + private val channel = + ChannelIdentity(ActorVirtualIdentity("from"), ActorVirtualIdentity("to"), isControl = false) + + private def fifo(seq: Long, payload: WorkflowFIFOMessagePayload = DataFrame(Array.empty)) + : WorkflowFIFOMessage = + WorkflowFIFOMessage(channel, seq, payload) + + private class CapturingHandler { + val received: mutable.ListBuffer[Either[MainThreadDelegateMessage, WorkflowFIFOMessage]] = + mutable.ListBuffer() + val handler: Either[MainThreadDelegateMessage, WorkflowFIFOMessage] => Unit = + msg => received += msg + } + + "EmptyReplayLogManagerImpl" should "expose getStep starting at INIT_STEP" in { + val mgr = new EmptyReplayLogManagerImpl(_ => ()) + assert(mgr.getStep == ProcessingStepCursor.INIT_STEP) + } + + it should "no-op on setupWriter / markAsReplayDestination / terminate" in { + val mgr = new EmptyReplayLogManagerImpl(_ => ()) + // None of these should throw or change observable state. + mgr.setupWriter(null) + mgr.markAsReplayDestination(null) + mgr.terminate() + assert(mgr.getStep == ProcessingStepCursor.INIT_STEP) + } + + "EmptyReplayLogManagerImpl.sendCommitted" should "forward the message to the configured handler" in { + val cap = new CapturingHandler + val mgr = new EmptyReplayLogManagerImpl(cap.handler) + val msg = Right[MainThreadDelegateMessage, WorkflowFIFOMessage](fifo(1L)) + mgr.sendCommitted(msg) + assert(cap.received.toList == List(msg)) + } + + "ReplayLogManager.withFaultTolerant" should "advance the step counter after the body runs" in { + val mgr = new EmptyReplayLogManagerImpl(_ => ()) + mgr.withFaultTolerant(channel, Some(fifo(1L)))(()) + assert(mgr.getStep == 0L) + mgr.withFaultTolerant(channel, Some(fifo(2L)))(()) + assert(mgr.getStep == 1L) + } + + it should "still advance the step counter and rethrow when the body throws" in { + val mgr = new EmptyReplayLogManagerImpl(_ => ()) + intercept[RuntimeException] { + mgr.withFaultTolerant(channel, Some(fifo(1L))) { + throw new RuntimeException("boom") + } + } + assert(mgr.getStep == 0L) + } Review Comment: Done in 6b0aea0e3a. Same fix here — using `ProcessingStepCursor.INIT_STEP + 1`. -- 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]
