Fix intermittent failure in testCloseCandidateRegistrationInQuickSuccession 15/51915/3
authorTom Pantelis <tpanteli@brocade.com>
Wed, 15 Feb 2017 16:02:57 +0000 (11:02 -0500)
committerTom Pantelis <tpanteli@brocade.com>
Thu, 16 Feb 2017 13:47:19 +0000 (13:47 +0000)
commit15741ff84dcd9bab5ab382a3ceaa48ceddffb9a3
treea43232aca6c16b5323322ab299edcea95fd34a90
parente8234fcf5c1bc64d12fe756e422e0e614019d2d4
Fix intermittent failure in testCloseCandidateRegistrationInQuickSuccession

java.lang.IllegalStateException: Optional.get() cannot be called on an absent value
  at com.google.common.base.Absent.get(Absent.java:47)
  at org.opendaylight.controller.cluster.datastore.entityownership.DistributedEntityOwnershipIntegrationTest.testCloseCandidateRegistrationInQuickSuccession(DistributedEntityOwnershipIntegrationTest.java:512)

Code:

if (!leaderEntityOwnershipService.getOwnershipState(ENTITY1).isPresent()
  || leaderEntityOwnershipService.getOwnershipState(ENTITY1).get() ==
                                               EntityOwnershipState.NO_OWNER

The code inlines calls to getOwnershipState so it's possible the first call
returns a present Optional and the second call returns absent which leads to
the failure. It's safer to capture the Optional in a lcoal var.

Change-Id: I9baa120efc9924dc820435dd63217b4598731a13
Signed-off-by: Tom Pantelis <tpanteli@brocade.com>
opendaylight/md-sal/sal-distributed-datastore/src/test/java/org/opendaylight/controller/cluster/datastore/entityownership/DistributedEntityOwnershipIntegrationTest.java