code & unit test for spark context hang detection logic

scaladoc?