From: Lorand Jakab Date: Mon, 31 Mar 2014 13:00:35 +0000 (+0300) Subject: Add thread safety to inner HashMap in ClusterDAO X-Git-Tag: jenkins-lispflowmapping-bulk-release-prepare-only-34~1 X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?a=commitdiff_plain;h=a805ca43abe080babf37989abf15622e41f1ed78;p=lispflowmapping.git Add thread safety to inner HashMap in ClusterDAO Needed by SMR patches Change-Id: I7defd582dfa2d7af444ab322d1816072b5cd3fc8 Signed-off-by: Lorand Jakab --- diff --git a/mappingservice/clusterdao/src/main/java/org/opendaylight/lispflowmapping/clusterdao/ClusterDAOService.java b/mappingservice/clusterdao/src/main/java/org/opendaylight/lispflowmapping/clusterdao/ClusterDAOService.java index 0c89ac15a..8826f9423 100644 --- a/mappingservice/clusterdao/src/main/java/org/opendaylight/lispflowmapping/clusterdao/ClusterDAOService.java +++ b/mappingservice/clusterdao/src/main/java/org/opendaylight/lispflowmapping/clusterdao/ClusterDAOService.java @@ -9,8 +9,8 @@ package org.opendaylight.lispflowmapping.clusterdao; import java.util.EnumSet; -import java.util.HashMap; import java.util.Map; +import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.ConcurrentMap; import java.util.concurrent.Executors; import java.util.concurrent.ScheduledExecutorService; @@ -31,7 +31,7 @@ public class ClusterDAOService implements ILispDAO { protected static final Logger logger = LoggerFactory.getLogger(ClusterDAOService.class); private IClusterContainerServices clusterContainerService = null; - private ConcurrentMap> data; + private ConcurrentMap> data; private final String CACHE_NAME = "mappingServiceCache"; private TimeUnit timeUnit = TimeUnit.SECONDS; private int recordTimeOut = 240; @@ -82,7 +82,7 @@ public class ClusterDAOService implements ILispDAO { return; } logger.trace("Retrieving cache for ClusterDAOService"); - data = (ConcurrentMap>) this.clusterContainerService.getCache(CACHE_NAME); + data = (ConcurrentMap>) this.clusterContainerService.getCache(CACHE_NAME); if (data == null) { logger.warn("Cache couldn't be retrieved for ClusterDAOService"); } @@ -90,7 +90,7 @@ public class ClusterDAOService implements ILispDAO { } public void getAll(IRowVisitor visitor) { - for (Map.Entry> keyEntry : data.entrySet()) { + for (ConcurrentMap.Entry> keyEntry : data.entrySet()) { for (Map.Entry valueEntry : keyEntry.getValue().entrySet()) { visitor.visitRow(keyEntry.getKey(), valueEntry.getKey(), valueEntry.getValue()); } @@ -99,7 +99,7 @@ public class ClusterDAOService implements ILispDAO { public void put(Object key, MappingEntry... values) { if (!data.containsKey(key)) { - data.put(key, new HashMap()); + data.put(key, new ConcurrentHashMap()); } for (MappingEntry entry : values) { data.get(key).put(entry.getKey(), entry.getValue()); diff --git a/mappingservice/integrationtest/src/test/java/org/opendaylight/lispflowmapping/integrationtest/MappingServiceIntegrationTest.java b/mappingservice/integrationtest/src/test/java/org/opendaylight/lispflowmapping/integrationtest/MappingServiceIntegrationTest.java index cdefc8b6a..1d0c332a1 100644 --- a/mappingservice/integrationtest/src/test/java/org/opendaylight/lispflowmapping/integrationtest/MappingServiceIntegrationTest.java +++ b/mappingservice/integrationtest/src/test/java/org/opendaylight/lispflowmapping/integrationtest/MappingServiceIntegrationTest.java @@ -436,10 +436,12 @@ public class MappingServiceIntegrationTest { LispAFIAddress rloc2Value = asIPAfiAddress("4.3.2.2"); MapReply mapReply = sendMapRegisterTwiceWithDiffrentValues(eid, rloc1Value, rloc2Value); assertEquals(2, mapReply.getEidToLocatorRecord().get(0).getLocatorRecord().size()); - assertEquals(LispAFIConvertor.toContainer(rloc1Value), mapReply.getEidToLocatorRecord().get(0).getLocatorRecord().get(0) - .getLispAddressContainer()); - assertEquals(LispAFIConvertor.toContainer(rloc2Value), mapReply.getEidToLocatorRecord().get(0).getLocatorRecord().get(1) - .getLispAddressContainer()); + LispAddressContainer rloc1ReturnValueContainer = mapReply.getEidToLocatorRecord().get(0).getLocatorRecord().get(0).getLispAddressContainer(); + LispAddressContainer rloc2ReturnValueContainer = mapReply.getEidToLocatorRecord().get(0).getLocatorRecord().get(1).getLispAddressContainer(); + assertTrue((LispAFIConvertor.toContainer(rloc1Value).equals(rloc1ReturnValueContainer) && + LispAFIConvertor.toContainer(rloc2Value).equals(rloc2ReturnValueContainer)) || + (LispAFIConvertor.toContainer(rloc1Value).equals(rloc2ReturnValueContainer) && + LispAFIConvertor.toContainer(rloc2Value).equals(rloc1ReturnValueContainer))); } private MapReply sendMapRegisterTwiceWithDiffrentValues(LispAFIAddress eid, LispAFIAddress rloc1, LispAFIAddress rloc2)