Copilot commented on code in PR #4790: URL: https://github.com/apache/texera/pull/4790#discussion_r3177485480
########## 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: Avoid passing `null` into `setupWriter` / `markAsReplayDestination` here. Using `null` makes the test less representative of real usage and can mask accidental NPEs if the no-op implementation ever changes. Prefer passing a real dummy `SequentialRecordWriter` (e.g., from `new EmptyRecordStorage[ReplayLogRecord]().getWriter("x")`) and an `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) + } + + 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: Same as above: prefer asserting `mgr.getStep == ProcessingStepCursor.INIT_STEP + 1` here instead of hardcoding `0L`, so the test remains correct even if the initial step constant changes. ########## 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: These assertions hardcode `0L`/`1L`, which couples the test to the current value of `ProcessingStepCursor.INIT_STEP` (-1). To make the test resilient to future changes, assert relative to `ProcessingStepCursor.INIT_STEP` (e.g., `INIT_STEP + 1`, `INIT_STEP + 2`) instead of literals; you can also use an empty block `{}` instead of `(())` for readability. -- 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]
