mridulm commented on code in PR #46131:
URL: https://github.com/apache/spark/pull/46131#discussion_r1633830012


##########
core/src/test/scala/org/apache/spark/storage/DiskBlockObjectWriterSuite.scala:
##########
@@ -196,9 +204,81 @@ class DiskBlockObjectWriterSuite extends SparkFunSuite {
     for (i <- 1 to 500) {
       writer.write(i, i)
     }
+    val clazz: Class[_] = writer.getClass
+    val bsField: Field = clazz.getDeclaredField("bs")
+    bsField.setAccessible(true)
+    val bs = bsField.get(writer).asInstanceOf[OutputStreamWithCloseDetecting]
+
+    val objOutField: Field = clazz.getDeclaredField("objOut")
+    objOutField.setAccessible(true)
+    val objOut = 
objOutField.get(writer).asInstanceOf[SerializationStreamWithCloseDetecting]
+
     writer.closeAndDelete()
     assert(!file.exists())
     assert(writeMetrics.bytesWritten == 0)
     assert(writeMetrics.recordsWritten == 0)
+    assert(bs.closed)
+    assert(objOut.closed)
+  }
+}
+
+trait CloseDetecting {
+  var closed = false

Review Comment:
   nit:
   
   ```suggestion
     def isClosed: Boolean
   ```



##########
core/src/test/scala/org/apache/spark/storage/DiskBlockObjectWriterSuite.scala:
##########
@@ -196,9 +204,81 @@ class DiskBlockObjectWriterSuite extends SparkFunSuite {
     for (i <- 1 to 500) {
       writer.write(i, i)
     }
+    val clazz: Class[_] = writer.getClass
+    val bsField: Field = clazz.getDeclaredField("bs")
+    bsField.setAccessible(true)
+    val bs = bsField.get(writer).asInstanceOf[OutputStreamWithCloseDetecting]
+
+    val objOutField: Field = clazz.getDeclaredField("objOut")
+    objOutField.setAccessible(true)
+    val objOut = 
objOutField.get(writer).asInstanceOf[SerializationStreamWithCloseDetecting]
+

Review Comment:
   Instead of reflection, introduce a `private[storage]` method in 
`DiskBlockObjectWriter` for testing - to retrieve the specific fields.
   
   Something like:
   ```
   // For testing
   private[storage] def getSerializerWrappedStream: InputStream = bs
   
   // For testing
   private[storage] def getSerializationStream: SerializationStream = objOut
   
   ```



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


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to