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


##########
amber/src/test/scala/org/apache/texera/amber/engine/common/storage/SequentialRecordStorageSpec.scala:
##########
@@ -0,0 +1,244 @@
+/*
+ * 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()
+  }
+
+  // `Files.walk` returns a closeable Stream backed by an open directory
+  // handle — wrap in try/finally so the handle is released even if
+  // traversal throws, otherwise temp-dir deletion can flake on Windows.

Review Comment:
   Good catch — swept the codebase and found one production usage with the same 
stream-leak pattern: `GitVersionControlLocalFileStorage.deleteRepo` in 
`common/workflow-core`. Filed it as a `starter-task`: #5548. Every other 
`Files.walk` / `Files.list` site already wraps the stream in try/finally, so 
this is the only one outstanding.



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