Copilot commented on code in PR #6853:
URL: https://github.com/apache/texera/pull/6853#discussion_r3642736604


##########
computing-unit-managing-service/src/test/scala/org/apache/texera/service/resource/ComputingUnitManagingResourceSpec.scala:
##########
@@ -0,0 +1,101 @@
+/*
+ * 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.service.resource
+
+import org.apache.texera.auth.SessionUser
+import org.apache.texera.dao.MockTexeraDB
+import org.apache.texera.dao.jooq.generated.enums.{
+  PrivilegeEnum,
+  UserRoleEnum,
+  WorkflowComputingUnitTypeEnum
+}
+import org.apache.texera.dao.jooq.generated.tables.daos.{UserDao, 
WorkflowComputingUnitDao}
+import org.apache.texera.dao.jooq.generated.tables.pojos.{User, 
WorkflowComputingUnit}
+import 
org.apache.texera.service.resource.ComputingUnitManagingResource.WorkflowComputingUnitMetrics
+import org.scalatest.BeforeAndAfterAll
+import org.scalatest.flatspec.AnyFlatSpec
+import org.scalatest.matchers.should.Matchers
+
+// Drives the per-user computing-unit endpoints against the embedded database 
using
+// local units (so no Kubernetes calls are made).
+class ComputingUnitManagingResourceSpec
+    extends AnyFlatSpec
+    with Matchers
+    with BeforeAndAfterAll
+    with MockTexeraDB {
+
+  private val uid = 800
+  private lazy val user: SessionUser = {
+    val u = new User()
+    u.setUid(uid)
+    u.setName("owner")
+    u.setEmail("[email protected]")
+    u.setRole(UserRoleEnum.REGULAR)
+    u.setPassword("password")
+    u.setGoogleAvatar("owner-avatar")
+    new SessionUser(u)
+  }
+
+  private def localUnit(cuid: Int, name: String): WorkflowComputingUnit = {
+    val unit = new WorkflowComputingUnit()
+    unit.setCuid(cuid)
+    unit.setUid(uid)
+    unit.setName(name)
+    unit.setType(WorkflowComputingUnitTypeEnum.local)
+    unit
+  }
+
+  override protected def beforeAll(): Unit = {
+    initializeDBAndReplaceDSLContext()
+    new UserDao(getDSLContext.configuration()).insert(user.getUser)
+    val unitDao = new WorkflowComputingUnitDao(getDSLContext.configuration())
+    unitDao.insert(localUnit(800, "cu-a"))
+    unitDao.insert(localUnit(801, "cu-b"))
+  }

Review Comment:
   beforeAll() should call super.beforeAll() so any lifecycle code from other 
mixed-in traits is not skipped if the trait stack changes.
   
   This issue also appears on line 73 of the same file.



##########
computing-unit-managing-service/src/test/scala/org/apache/texera/service/util/KubernetesClientSpec.scala:
##########
@@ -19,10 +19,109 @@
 
 package org.apache.texera.service.util
 
+import io.fabric8.kubernetes.api.model.metrics.v1beta1.{
+  ContainerMetricsBuilder,
+  PodMetricsBuilder,
+  PodMetricsList,
+  PodMetricsListBuilder
+}
+import io.fabric8.kubernetes.api.model.{Pod, PodBuilder, PodList, 
PodListBuilder, Quantity}
+import io.fabric8.kubernetes.client.dsl.{
+  MetricAPIGroupDSL,
+  MixedOperation,
+  NonNamespaceOperation,
+  PodMetricOperation,
+  PodResource
+}
+import io.fabric8.kubernetes.client.{KubernetesClientBuilder, KubernetesClient 
=> Fabric8Client}
+import org.apache.texera.common.config.KubernetesConfig
+import org.apache.texera.dao.jooq.generated.enums.WorkflowComputingUnitTypeEnum
+import org.apache.texera.dao.jooq.generated.tables.pojos.WorkflowComputingUnit
+import org.mockito.Mockito.{mock, when}
+import org.scalatest.BeforeAndAfterAll
 import org.scalatest.flatspec.AnyFlatSpec
 import org.scalatest.matchers.should.Matchers
 
-class KubernetesClientSpec extends AnyFlatSpec with Matchers {
+import scala.jdk.CollectionConverters._
+
+// Exercises the fabric8 wrappers without a cluster by stubbing the client 
with Mockito.
+class KubernetesClientSpec extends AnyFlatSpec with Matchers with 
BeforeAndAfterAll {
+
+  private val namespace: String = KubernetesConfig.computeUnitPoolNamespace
+
+  private def unitOfType(cuid: Int, tpe: WorkflowComputingUnitTypeEnum): 
WorkflowComputingUnit = {
+    val u = new WorkflowComputingUnit()
+    u.setCuid(cuid)
+    u.setType(tpe)
+    u
+  }
+
+  private def pod(cuid: Int, phase: String): Pod =
+    new PodBuilder()
+      .withNewMetadata()
+      .withName(KubernetesClient.generatePodName(cuid))
+      .endMetadata()
+      .withNewStatus()
+      .withPhase(phase)
+      .endStatus()
+      .build()
+
+  // cuid 1 -> Running, cuid 2 -> Pending; both returned by the namespace-wide 
listing.
+  private val podList: PodList =
+    new PodListBuilder().addToItems(pod(1, "Running"), pod(2, 
"Pending")).build()
+
+  // Only cuid 1 reports metrics.
+  private val metricsList: PodMetricsList =
+    new PodMetricsListBuilder()
+      .addToItems(
+        new PodMetricsBuilder()
+          .withNewMetadata()
+          .withName(KubernetesClient.generatePodName(1))
+          .endMetadata()
+          .addToContainers(
+            new ContainerMetricsBuilder()
+              .withName("main")
+              .withUsage(
+                Map("cpu" -> new Quantity("250m"), "memory" -> new 
Quantity("128Mi")).asJava
+              )
+              .build()
+          )
+          .build()
+      )
+      .build()
+
+  override protected def beforeAll(): Unit = {
+    val client = mock(classOf[Fabric8Client])
+

Review Comment:
   In ScalaTest lifecycle overrides, call super.beforeAll() so any other 
mixed-in traits (now or added later) get a chance to run their setup.
   
   This issue also appears on line 121 of the same file.



##########
computing-unit-managing-service/src/test/scala/org/apache/texera/service/util/ComputingUnitHelpersSpec.scala:
##########
@@ -19,23 +19,63 @@
 
 package org.apache.texera.service.util
 
-import org.apache.texera.dao.jooq.generated.enums.WorkflowComputingUnitTypeEnum
-import org.apache.texera.dao.jooq.generated.tables.pojos.WorkflowComputingUnit
+import org.apache.texera.dao.MockTexeraDB
+import org.apache.texera.dao.jooq.generated.enums.{
+  PrivilegeEnum,
+  UserRoleEnum,
+  WorkflowComputingUnitTypeEnum
+}
+import org.apache.texera.dao.jooq.generated.tables.daos.{UserDao, 
WorkflowComputingUnitDao}
+import org.apache.texera.dao.jooq.generated.tables.pojos.{User, 
WorkflowComputingUnit}
 import 
org.apache.texera.service.resource.ComputingUnitManagingResource.WorkflowComputingUnitMetrics
 import org.apache.texera.service.resource.ComputingUnitState.{Pending, Running}
+import org.scalatest.BeforeAndAfterAll
 import org.scalatest.flatspec.AnyFlatSpec
 import org.scalatest.matchers.should.Matchers
 
-class ComputingUnitHelpersSpec extends AnyFlatSpec with Matchers {
+class ComputingUnitHelpersSpec
+    extends AnyFlatSpec
+    with Matchers
+    with BeforeAndAfterAll
+    with MockTexeraDB {
+
+  override protected def beforeAll(): Unit = initializeDBAndReplaceDSLContext()
+
+  override protected def afterAll(): Unit = shutdownDB()

Review Comment:
   These lifecycle hooks override BeforeAndAfterAll but don't call 
super.beforeAll()/super.afterAll(). Calling super avoids accidentally skipping 
setup/teardown from other mixed-in traits and matches how other suites in the 
repo structure lifecycle hooks.



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