Fix intermittent failure in testCloseCandidateRegistrationInQuickSuccession 63/51963/2
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 14:46:38 +0000 (14:46 +0000)
commitbe7c8496b92dec6ee77e86fc166c7df45e9e5eab
treef5046a327a43663ec43267873c2b2854e13a0035
parentc71ecaf8a0d2d04c343dbfec0a9cfd5162c277f6
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