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


##########
amber/src/test/scala/org/apache/texera/amber/engine/common/storage/VFSRecordStorageSpec.scala:
##########
@@ -0,0 +1,251 @@
+/*
+ * 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.common.storage
+
+import org.apache.pekko.actor.ActorSystem
+import org.apache.pekko.serialization.{Serialization, SerializationExtension}
+import org.apache.pekko.testkit.TestKit
+import org.apache.texera.amber.engine.common.AmberRuntime
+import org.scalatest.BeforeAndAfterAll
+import org.scalatest.flatspec.AnyFlatSpec
+
+import java.net.URI
+import java.nio.file.{Files, Path}
+
+class VFSRecordStorageSpec extends AnyFlatSpec with BeforeAndAfterAll {
+
+  // 
---------------------------------------------------------------------------
+  // Suite-local Pekko serde injected into AmberRuntime via reflection
+  // 
---------------------------------------------------------------------------
+  //
+  // `SequentialRecordWriter.writeRecord` hard-codes `AmberRuntime.serde`,
+  // so any test that round-trips a record needs AmberRuntime initialized.
+  // Pattern matches CheckpointSubsystemSpec / ClientEventSpec — own a
+  // suite-local ActorSystem, inject it into AmberRuntime's private vars,
+  // tear down in afterAll.
+
+  private val testSystem: ActorSystem =
+    ActorSystem("VFSRecordStorageSpec-test", AmberRuntime.pekkoConfig)
+  private val testSerde: Serialization = SerializationExtension(testSystem)
+
+  private def setAmberRuntimeField(name: String, value: AnyRef): Unit = {
+    val field = AmberRuntime.getClass.getDeclaredField(name)
+    field.setAccessible(true)
+    field.set(AmberRuntime, value)
+  }
+
+  override protected def beforeAll(): Unit = {
+    super.beforeAll()
+    setAmberRuntimeField("_actorSystem", testSystem)
+    setAmberRuntimeField("_serde", testSerde)
+  }
+
+  override protected def afterAll(): Unit = {
+    setAmberRuntimeField("_serde", null)
+    setAmberRuntimeField("_actorSystem", null)
+    TestKit.shutdownActorSystem(testSystem)
+    super.afterAll()
+  }
+
+  // 
---------------------------------------------------------------------------
+  // Temp-directory helpers — every test owns its own scratch folder so the
+  // cases are independent and parallel-safe.
+  // 
---------------------------------------------------------------------------
+
+  // Returns (sub, uri) where `sub` is the storage folder under a unique
+  // temp root and is NOT yet created on disk (so constructor tests can
+  // pin the auto-create-folder branch). The parent of `sub` IS the unique
+  // temp root, which is what cleanup() removes — keeping the disk clean
+  // even when a test fails before the storage folder gets created.
+  private def mkTempUri(prefix: String): (Path, URI) = {
+    val root = Files.createTempDirectory(s"vfs-record-storage-spec-$prefix-")
+    val sub = root.resolve("logs")
+    (sub, sub.toUri)
+  }
+
+  // Always clean from the parent temp root so any sibling files / partial
+  // state created by a failing test are also removed.
+  private def cleanup(sub: Path): Unit = {
+    val root = sub.getParent
+    if (root == null || !Files.exists(root)) return
+    Files
+      .walk(root)
+      .sorted(java.util.Comparator.reverseOrder())
+      .forEach(child => Files.deleteIfExists(child))
+  }

Review Comment:
   `Files.walk(...)` returns a `java.util.stream.Stream` that should be closed; 
the current cleanup helper never closes it, which can leak file descriptors and 
make temp-directory deletion flaky on some platforms.



##########
amber/src/test/scala/org/apache/texera/amber/engine/common/storage/SequentialRecordStorageSpec.scala:
##########
@@ -0,0 +1,237 @@
+/*
+ * 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.common.storage
+
+import org.apache.pekko.actor.ActorSystem
+import org.apache.pekko.serialization.{Serialization, SerializationExtension}
+import org.apache.pekko.testkit.TestKit
+import org.apache.texera.amber.engine.common.AmberRuntime
+import org.apache.texera.amber.engine.common.storage.SequentialRecordStorage.{
+  SequentialRecordReader,
+  SequentialRecordWriter
+}
+import org.scalatest.BeforeAndAfterAll
+import org.scalatest.flatspec.AnyFlatSpec
+
+import java.io.{ByteArrayInputStream, ByteArrayOutputStream, DataInputStream, 
DataOutputStream}
+import java.nio.file.{Files, Path}
+
+class SequentialRecordStorageSpec extends AnyFlatSpec with BeforeAndAfterAll {
+
+  // 
---------------------------------------------------------------------------
+  // Suite-local Pekko serde injected into AmberRuntime via reflection
+  // 
---------------------------------------------------------------------------
+  //
+  // `SequentialRecordWriter.writeRecord` / `SequentialRecordReader`'s
+  // iterator both hard-code `AmberRuntime.serde`. Pattern matches
+  // CheckpointSubsystemSpec / ClientEventSpec: own a suite-local
+  // ActorSystem, inject it into AmberRuntime's private vars via
+  // reflection, tear down in afterAll.
+
+  private val testSystem: ActorSystem =
+    ActorSystem("SequentialRecordStorageSpec-test", AmberRuntime.pekkoConfig)
+  private val testSerde: Serialization = SerializationExtension(testSystem)
+
+  private def setAmberRuntimeField(name: String, value: AnyRef): Unit = {
+    val field = AmberRuntime.getClass.getDeclaredField(name)
+    field.setAccessible(true)
+    field.set(AmberRuntime, value)
+  }
+
+  override protected def beforeAll(): Unit = {
+    super.beforeAll()
+    setAmberRuntimeField("_actorSystem", testSystem)
+    setAmberRuntimeField("_serde", testSerde)
+  }
+
+  override protected def afterAll(): Unit = {
+    setAmberRuntimeField("_serde", null)
+    setAmberRuntimeField("_actorSystem", null)
+    TestKit.shutdownActorSystem(testSystem)
+    super.afterAll()
+  }
+
+  private def deleteRecursively(p: Path): Unit = {
+    if (!Files.exists(p)) return
+    Files
+      .walk(p)
+      .sorted(java.util.Comparator.reverseOrder())
+      .forEach(child => Files.deleteIfExists(child))
+  }

Review Comment:
   `Files.walk(...)` returns a stream that must be closed; `deleteRecursively` 
currently leaks the stream, which can keep handles open and cause intermittent 
failures when deleting temp dirs.



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