Permalink
Browse files

Properly handle a ClusterListener that throws an exception when proce…

…ssing an event
  • Loading branch information...
1 parent 40ee730 commit 79594a83c9569278ad0e72a6ba9d70b5a219628c Chris Conrad committed Jun 3, 2010
@@ -187,8 +187,15 @@ trait ClusterClient extends Logging {
val a = actor {
loop {
receive {
- case event: ClusterEvent => listener.handleClusterEvent(event)
+ case event: ClusterEvent =>
+ try {
+ listener.handleClusterEvent(event)
+ } catch {
+ case ex: Exception => log.error(ex, "Uncaught exception thrown from ClusterListener")
+ }
+
case 'quit => exit
+
case m => log.error("Received invalid message: " + m)
}
}
@@ -285,5 +285,21 @@ class ClusterClientSpec extends SpecificationWithJUnit with Mockito with WaitFor
cluster.isShutdown must beTrue
}
+
+ "handle a listener throwing an exception" in {
+ val listener = new ClusterListener {
+ var callCount = 0
+ def handleClusterEvent(event: ClusterEvent) = {
+ callCount += 1
+ throw new Exception
+ }
+ }
+
+ cluster.addListener(listener) must notBeNull
+ addListenerCount must be_==(1)
+ currentListeners.head ! ClusterEvents.NodesChanged(Set())
+ currentListeners.head ! ClusterEvents.NodesChanged(Set())
+ listener.callCount must eventually(be_==(2))
+ }
}
}
@@ -99,7 +99,9 @@ trait NetworkServer extends Logging {
case ex: ClusterException => log.error(ex, "Unable to mark node available")
}
}
+
case ClusterEvents.Shutdown => doShutdown(true)
+
case _ => // do nothing
}
})

0 comments on commit 79594a8

Please sign in to comment.