From: Tom Pantelis Date: Thu, 3 Mar 2016 17:52:47 +0000 (-0500) Subject: Fix ConcurrentModificationEx in RpcRegistry.onBucketsUpdated X-Git-Tag: release/boron~328 X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?p=controller.git;a=commitdiff_plain;h=f09d37ec4cce2411eaae11dde18f9ce2d2f14118 Fix ConcurrentModificationEx in RpcRegistry.onBucketsUpdated This was introduced by a recent patch. onBucketsUpdated iterates the routesUpdateCallbacks however one of the callbacks in receiveGetRouter removes itself from the list causing the ConcurrentModificationEx. I changed onBucketsUpdated to first copy the list to an array to prevent this. Change-Id: I44c9a89b4b433f711cf4f90bf28e6955d8784f5f Signed-off-by: Tom Pantelis --- diff --git a/opendaylight/md-sal/sal-remoterpc-connector/src/main/java/org/opendaylight/controller/remote/rpc/registry/RpcRegistry.java b/opendaylight/md-sal/sal-remoterpc-connector/src/main/java/org/opendaylight/controller/remote/rpc/registry/RpcRegistry.java index b467ce949a..1e481bc311 100644 --- a/opendaylight/md-sal/sal-remoterpc-connector/src/main/java/org/opendaylight/controller/remote/rpc/registry/RpcRegistry.java +++ b/opendaylight/md-sal/sal-remoterpc-connector/src/main/java/org/opendaylight/controller/remote/rpc/registry/RpcRegistry.java @@ -187,7 +187,11 @@ public class RpcRegistry extends BucketStore { @Override protected void onBucketsUpdated() { - for(Runnable callBack: routesUpdatedCallbacks) { + if(routesUpdatedCallbacks.isEmpty()) { + return; + } + + for(Runnable callBack: routesUpdatedCallbacks.toArray(new Runnable[routesUpdatedCallbacks.size()])) { callBack.run(); } } diff --git a/opendaylight/md-sal/sal-remoterpc-connector/src/test/java/org/opendaylight/controller/remote/rpc/registry/RpcRegistryTest.java b/opendaylight/md-sal/sal-remoterpc-connector/src/test/java/org/opendaylight/controller/remote/rpc/registry/RpcRegistryTest.java index 2c2fd46a29..772dae232f 100644 --- a/opendaylight/md-sal/sal-remoterpc-connector/src/test/java/org/opendaylight/controller/remote/rpc/registry/RpcRegistryTest.java +++ b/opendaylight/md-sal/sal-remoterpc-connector/src/test/java/org/opendaylight/controller/remote/rpc/registry/RpcRegistryTest.java @@ -409,15 +409,22 @@ public class RpcRegistryTest { registry2.tell(new SetLocalRouter(mockBroker2.getRef()), mockBroker2.getRef()); List> routeIds = createRouteIds(); + routeIds.addAll(createRouteIds()); - registry1.tell(new FindRouters(routeIds.get(0)), mockBroker1.getRef()); + JavaTestKit replyKit1 = new JavaTestKit(node1); + registry1.tell(new FindRouters(routeIds.get(0)), replyKit1.getRef()); + JavaTestKit replyKit2 = new JavaTestKit(node1); + registry1.tell(new FindRouters(routeIds.get(1)), replyKit2.getRef()); registry2.tell(new AddOrUpdateRoutes(routeIds), mockBroker2.getRef()); - FindRoutersReply reply = mockBroker1.expectMsgClass(Duration.create(7, TimeUnit.SECONDS), + FindRoutersReply reply = replyKit1.expectMsgClass(Duration.create(7, TimeUnit.SECONDS), FindRoutersReply.class); - List> respList = reply.getRouterWithUpdateTime(); - Assert.assertEquals("getRouterWithUpdateTime size", 1, respList.size()); + Assert.assertEquals("getRouterWithUpdateTime size", 1, reply.getRouterWithUpdateTime().size()); + + reply = replyKit2.expectMsgClass(Duration.create(7, TimeUnit.SECONDS), + FindRoutersReply.class); + Assert.assertEquals("getRouterWithUpdateTime size", 1, reply.getRouterWithUpdateTime().size()); } @Test