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


##########
amber/src/test/scala/org/apache/texera/amber/engine/architecture/messaginglayer/FlowControlSpec.scala:
##########
@@ -0,0 +1,144 @@
+/*
+ * 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.messaginglayer
+
+import org.apache.texera.amber.config.ApplicationConfig
+import org.apache.texera.amber.core.virtualidentity.{ActorVirtualIdentity, 
ChannelIdentity}
+import 
org.apache.texera.amber.engine.architecture.common.WorkflowActor.NetworkMessage
+import org.apache.texera.amber.engine.common.ambermessage.{
+  WorkflowFIFOMessage,
+  WorkflowFIFOMessagePayload,
+  WorkflowMessage
+}
+import org.scalatest.flatspec.AnyFlatSpec
+
+class FlowControlSpec extends AnyFlatSpec {
+
+  private val channelId =
+    ChannelIdentity(ActorVirtualIdentity("from"), ActorVirtualIdentity("to"), 
isControl = false)
+
+  // A non-DataFrame payload so that `WorkflowMessage.getInMemSize` falls 
through to
+  // the 200L default branch — using DataFrame(Array.empty) yields 0 bytes, 
which
+  // would let any message squeeze through even when the configured credit is 
0.
+  private case class FixedSizePayload() extends WorkflowFIFOMessagePayload
+
+  private def msg(id: Long): NetworkMessage =
+    NetworkMessage(id, WorkflowFIFOMessage(channelId, id, FixedSizePayload()))
+
+  // Pin the assumed payload size so the test fails loudly if WorkflowMessage's
+  // size accounting changes in a way that would invalidate the credit math 
below.
+  private val msgSize: Long = 
WorkflowMessage.getInMemSize(msg(0).internalMessage)
+  assert(msgSize == 200L)
+
+  private val maxBytes = ApplicationConfig.maxCreditAllowedInBytesPerChannel
+
+  "FlowControl" should "report full credit and not be overloaded initially" in 
{
+    val fc = new FlowControl()
+    assert(fc.getCredit == maxBytes)
+    assert(!fc.isOverloaded)

Review Comment:
   test some invalid cases. e.g., message size > max credit allowed, negative, 
overflow cases, do multiple runs (see if you can drain credit eventually).
   
    I think the most important thing in flow control is its algorithm and edge 
cases.
   
   



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