Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -19,17 +19,20 @@ package org.apache.spark.sql.execution.python

import scala.collection.mutable.ArrayBuffer

import org.mockito.Mockito.when
import org.scalatest.concurrent.Eventually
import org.scalatest.mockito.MockitoSugar
import org.scalatest.time.SpanSugar._

import org.apache.spark._
import org.apache.spark.memory.{TaskMemoryManager, TestMemoryManager}
import org.apache.spark.serializer.{JavaSerializer, SerializerManager}
import org.apache.spark.sql.catalyst.expressions.{GenericInternalRow, UnsafeProjection}
import org.apache.spark.sql.execution.python.PythonForeachWriter.UnsafeRowBuffer
import org.apache.spark.sql.types.{DataType, IntegerType}
import org.apache.spark.util.Utils

class PythonForeachWriterSuite extends SparkFunSuite with Eventually {
class PythonForeachWriterSuite extends SparkFunSuite with Eventually with MockitoSugar {

testWithBuffer("UnsafeRowBuffer: iterator blocks when no data is available") { b =>
b.assertIteratorBlocked()
Expand Down Expand Up @@ -75,15 +78,20 @@ class PythonForeachWriterSuite extends SparkFunSuite with Eventually {
tester = new BufferTester(memBytes, sleepPerRowReadMs)
f(tester)
} finally {
if (tester == null) tester.close()
if (tester != null) tester.close()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

e... So here's why all test failed with NPE.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes, but that NPE just covered up another NPE from SparkEnv.get.serializerManager

}
}
}


class BufferTester(memBytes: Long, sleepPerRowReadMs: Int) {
private val buffer = {
val mem = new TestMemoryManager(new SparkConf())
val mockEnv = mock[SparkEnv]
val conf = new SparkConf()
val serializerManager = new SerializerManager(new JavaSerializer(conf), conf, None)
when(mockEnv.serializerManager).thenReturn(serializerManager)
SparkEnv.set(mockEnv)
val mem = new TestMemoryManager(conf)
mem.limit(memBytes)
val taskM = new TaskMemoryManager(mem, 0)
new UnsafeRowBuffer(taskM, Utils.createTempDir(), 1)
Expand Down