Fix ConcurrentModificationEx in RpcRegistry.onBucketsUpdated 14/35714/2
authorTom Pantelis <tpanteli@brocade.com>
Thu, 3 Mar 2016 17:52:47 +0000 (12:52 -0500)
committerGerrit Code Review <gerrit@opendaylight.org>
Fri, 4 Mar 2016 06:31:57 +0000 (06:31 +0000)
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 <tpanteli@brocade.com>
opendaylight/md-sal/sal-remoterpc-connector/src/main/java/org/opendaylight/controller/remote/rpc/registry/RpcRegistry.java
opendaylight/md-sal/sal-remoterpc-connector/src/test/java/org/opendaylight/controller/remote/rpc/registry/RpcRegistryTest.java

index b467ce949ae4a86e9500fffa9f05b85c0ba407e1..1e481bc311b3f30d2bfc75346077253a871bdff0 100644 (file)
@@ -187,7 +187,11 @@ public class RpcRegistry extends BucketStore<RoutingTable> {
 
     @Override
     protected void onBucketsUpdated() {
-        for(Runnable callBack: routesUpdatedCallbacks) {
+        if(routesUpdatedCallbacks.isEmpty()) {
+            return;
+        }
+
+        for(Runnable callBack: routesUpdatedCallbacks.toArray(new Runnable[routesUpdatedCallbacks.size()])) {
             callBack.run();
         }
     }
index 2c2fd46a2914ca8a41aaae38d1ae9a3165d77685..772dae232f8dd5ca1546ee170108a95e4e4b7d4c 100644 (file)
@@ -409,15 +409,22 @@ public class RpcRegistryTest {
         registry2.tell(new SetLocalRouter(mockBroker2.getRef()), mockBroker2.getRef());
 
         List<RpcRouter.RouteIdentifier<?, ?, ?>> 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<Pair<ActorRef, Long>> 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