I have a Spark Application, which receives data from files as RDD and sends it to another service (MyService). The processing scheme looks like this:
object Sender {
def handle(myService: MyService) = {
val rdd = getRdd()
rdd.foreachPartition(partition => {
partition.foreach(it =>
val myData = new MyData(it)
myService.send(myData))
})
}
}
where MyService looks like this:
class MyService() extends Serializable {
def send(data: MyData) = {
//do something
}
}
In my Unit test I try to do something like this:
val myServiceMock = mock[MyService]
val data = new MyData()
Sender.handle(myServiceMock)
verify(myserviceMock).send(eqTo(data))
But when Spark passes data from the driver to the executors, it's serialised and in fact, it's new MyServiceMock objects. And I get Wanted but not invoked and Actually, there were zero interactions with this mock.
Is there a special tool for testing this case?