code & unit test for spark context hang detection logic

If case object, then remove () here as well.