Copilot commented on code in PR #3653:
URL: https://github.com/apache/celeborn/pull/3653#discussion_r3061556699


##########
worker/src/test/scala/org/apache/celeborn/service/deploy/worker/PushDataHandlerSuite.scala:
##########
@@ -0,0 +1,279 @@
+/*
+ * 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.celeborn.service.deploy.worker
+
+import java.util
+
+import org.mockito.MockitoSugar._
+import org.scalatest.funsuite.AnyFunSuite
+
+import org.apache.celeborn.common.CelebornConf
+import org.apache.celeborn.common.meta.{DiskFileInfo, DiskInfo, 
MemoryFileInfo, WorkerInfo}
+import org.apache.celeborn.common.meta.DiskStatus
+import org.apache.celeborn.common.protocol.PartitionSplitMode
+import org.apache.celeborn.common.protocol.message.StatusCode
+import org.apache.celeborn.service.deploy.worker.storage.{LocalFlusher, 
PartitionDataWriter}
+
+/**
+ * Unit tests for [[PushDataHandler.checkDiskFullAndSplit]].
+ *
+ * The method under test has the following decision tree:
+ *   1. If needHardSplitForMemoryShuffleStorage() → HARD_SPLIT
+ *   2. If workerPartitionSplitEnabled is false or diskFileInfo is null → 
NO_SPLIT
+ *   3. If disk is full and fileLength > partitionSplitMinimumSize → HARD_SPLIT
+ *   4. If isPrimary and fileLength > splitThreshold:
+ *      a. SOFT mode and fileLength < partitionSplitMaximumSize → SOFT_SPLIT
+ *      b. Otherwise (HARD mode, or fileLength >= partitionSplitMaximumSize) → 
HARD_SPLIT
+ *   5. Otherwise → NO_SPLIT
+ */
+class PushDataHandlerSuite extends AnyFunSuite {
+
+  // ── helpers ──────────────────────────────────────────────────────────────
+
+  private val splitMinimumSize: Long = 1024L * 1024L // 1 MB
+  private val splitMaximumSize: Long = 1024L * 1024L * 10L // 10 MB
+  private val splitThreshold: Long = 1024L * 1024L * 2L // 2 MB
+  private val mountPoint = "/mnt/disk0"
+
+  /**
+   * Build a [[PushDataHandler]] with the given configuration flags, wired up
+   * with a minimal [[WorkerInfo]] that contains one disk entry for 
[[mountPoint]].
+   */
+  private def buildHandler(
+      partitionSplitEnabled: Boolean,
+      diskStatus: DiskStatus = DiskStatus.HEALTHY,
+      actualUsableSpace: Long = Long.MaxValue): PushDataHandler = {
+    val conf = new CelebornConf()
+    conf.set(CelebornConf.WORKER_PARTITION_SPLIT_ENABLED.key, 
partitionSplitEnabled.toString)
+    conf.set(CelebornConf.WORKER_PARTITION_SPLIT_MIN_SIZE.key, 
splitMinimumSize.toString)
+    conf.set(CelebornConf.WORKER_PARTITION_SPLIT_MAX_SIZE.key, 
splitMaximumSize.toString)
+
+    val diskInfo = new DiskInfo(mountPoint, actualUsableSpace, 0L, 0L, 0L)
+    diskInfo.setStatus(diskStatus)
+
+    val diskInfoMap = new util.HashMap[String, DiskInfo]()
+    diskInfoMap.put(mountPoint, diskInfo)
+
+    val workerInfo = new WorkerInfo("localhost", 9095, 9096, 9097, 9098, -1, 
diskInfoMap, null)
+
+    val workerSource = mock[WorkerSource]
+
+    val handler = new PushDataHandler(workerSource)
+    // Inject fields that checkDiskFullAndSplit depends on via reflection 
helpers
+    // exposed through the init path. We use a minimal mock Worker instead.
+    val mockWorker = mock[Worker]
+    when(mockWorker.conf).thenReturn(conf)
+    when(mockWorker.workerInfo).thenReturn(workerInfo)
+    // Provide no-op stubs for all other Worker fields accessed during init
+    when(mockWorker.partitionLocationInfo).thenReturn(mock[
+      org.apache.celeborn.common.meta.WorkerPartitionLocationInfo])
+    when(mockWorker.shufflePartitionType).thenReturn(
+      new java.util.concurrent.ConcurrentHashMap())
+    when(mockWorker.shufflePushDataTimeout).thenReturn(
+      new java.util.concurrent.ConcurrentHashMap())
+    when(mockWorker.shuffleMapperAttempts).thenReturn(
+      new java.util.concurrent.ConcurrentHashMap())

Review Comment:
   These ConcurrentHashMap instances are created without type parameters. In 
Scala this infers ConcurrentHashMap[Nothing, Nothing], which won’t typecheck 
against Worker’s expected field types (e.g., ConcurrentHashMap[String, 
PartitionType], ConcurrentHashMap[String, Long], ConcurrentHashMap[String, 
AtomicIntegerArray]). Please construct them with the proper type parameters or 
use JavaUtils.newConcurrentHashMap[T,U] to match Worker.scala’s definitions.
   ```suggestion
         new java.util.concurrent.ConcurrentHashMap[
           String,
           java.util.concurrent.atomic.AtomicIntegerArray]())
   ```



##########
worker/src/test/scala/org/apache/celeborn/service/deploy/worker/PushDataHandlerSuite.scala:
##########
@@ -0,0 +1,279 @@
+/*
+ * 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.celeborn.service.deploy.worker
+
+import java.util
+
+import org.mockito.MockitoSugar._
+import org.scalatest.funsuite.AnyFunSuite
+
+import org.apache.celeborn.common.CelebornConf
+import org.apache.celeborn.common.meta.{DiskFileInfo, DiskInfo, 
MemoryFileInfo, WorkerInfo}
+import org.apache.celeborn.common.meta.DiskStatus
+import org.apache.celeborn.common.protocol.PartitionSplitMode
+import org.apache.celeborn.common.protocol.message.StatusCode
+import org.apache.celeborn.service.deploy.worker.storage.{LocalFlusher, 
PartitionDataWriter}
+
+/**
+ * Unit tests for [[PushDataHandler.checkDiskFullAndSplit]].
+ *
+ * The method under test has the following decision tree:
+ *   1. If needHardSplitForMemoryShuffleStorage() → HARD_SPLIT
+ *   2. If workerPartitionSplitEnabled is false or diskFileInfo is null → 
NO_SPLIT
+ *   3. If disk is full and fileLength > partitionSplitMinimumSize → HARD_SPLIT
+ *   4. If isPrimary and fileLength > splitThreshold:
+ *      a. SOFT mode and fileLength < partitionSplitMaximumSize → SOFT_SPLIT
+ *      b. Otherwise (HARD mode, or fileLength >= partitionSplitMaximumSize) → 
HARD_SPLIT
+ *   5. Otherwise → NO_SPLIT
+ */
+class PushDataHandlerSuite extends AnyFunSuite {
+
+  // ── helpers ──────────────────────────────────────────────────────────────
+
+  private val splitMinimumSize: Long = 1024L * 1024L // 1 MB
+  private val splitMaximumSize: Long = 1024L * 1024L * 10L // 10 MB
+  private val splitThreshold: Long = 1024L * 1024L * 2L // 2 MB
+  private val mountPoint = "/mnt/disk0"
+
+  /**
+   * Build a [[PushDataHandler]] with the given configuration flags, wired up
+   * with a minimal [[WorkerInfo]] that contains one disk entry for 
[[mountPoint]].
+   */
+  private def buildHandler(
+      partitionSplitEnabled: Boolean,
+      diskStatus: DiskStatus = DiskStatus.HEALTHY,
+      actualUsableSpace: Long = Long.MaxValue): PushDataHandler = {
+    val conf = new CelebornConf()
+    conf.set(CelebornConf.WORKER_PARTITION_SPLIT_ENABLED.key, 
partitionSplitEnabled.toString)
+    conf.set(CelebornConf.WORKER_PARTITION_SPLIT_MIN_SIZE.key, 
splitMinimumSize.toString)
+    conf.set(CelebornConf.WORKER_PARTITION_SPLIT_MAX_SIZE.key, 
splitMaximumSize.toString)
+
+    val diskInfo = new DiskInfo(mountPoint, actualUsableSpace, 0L, 0L, 0L)
+    diskInfo.setStatus(diskStatus)
+
+    val diskInfoMap = new util.HashMap[String, DiskInfo]()
+    diskInfoMap.put(mountPoint, diskInfo)
+
+    val workerInfo = new WorkerInfo("localhost", 9095, 9096, 9097, 9098, -1, 
diskInfoMap, null)
+
+    val workerSource = mock[WorkerSource]
+
+    val handler = new PushDataHandler(workerSource)
+    // Inject fields that checkDiskFullAndSplit depends on via reflection 
helpers
+    // exposed through the init path. We use a minimal mock Worker instead.
+    val mockWorker = mock[Worker]
+    when(mockWorker.conf).thenReturn(conf)
+    when(mockWorker.workerInfo).thenReturn(workerInfo)
+    // Provide no-op stubs for all other Worker fields accessed during init
+    when(mockWorker.partitionLocationInfo).thenReturn(mock[
+      org.apache.celeborn.common.meta.WorkerPartitionLocationInfo])
+    when(mockWorker.shufflePartitionType).thenReturn(
+      new java.util.concurrent.ConcurrentHashMap())
+    when(mockWorker.shufflePushDataTimeout).thenReturn(
+      new java.util.concurrent.ConcurrentHashMap())
+    when(mockWorker.shuffleMapperAttempts).thenReturn(
+      new java.util.concurrent.ConcurrentHashMap())
+    
when(mockWorker.replicateThreadPool).thenReturn(mock[java.util.concurrent.ThreadPoolExecutor])
+    when(mockWorker.unavailablePeers).thenReturn(new 
java.util.concurrent.ConcurrentHashMap())

Review Comment:
   Same issue here: unavailablePeers expects ConcurrentHashMap[WorkerInfo, 
Long] (see Worker.scala), but new ConcurrentHashMap() will infer 
ConcurrentHashMap[Nothing, Nothing] in Scala and fail to compile. Instantiate 
with the correct generic types (or JavaUtils.newConcurrentHashMap).
   ```suggestion
       when(mockWorker.unavailablePeers).thenReturn(
         new java.util.concurrent.ConcurrentHashMap[WorkerInfo, Long]())
   ```



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