From: Robert Varga Date: Tue, 22 Aug 2017 08:51:58 +0000 (+0200) Subject: BUG-8858: remove sleeps from test driver X-Git-Tag: release/fluorine~83 X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?p=controller.git;a=commitdiff_plain;h=8d022374318a90c5fb0b066a776b5e6403e279e5;ds=sidebyside BUG-8858: remove sleeps from test driver This is a follow-up patch to speed up test driver, properly chasing leader, without any sleeps incurred. Change-Id: I55ed680ad3f45813b3ee3d8b948046c4ae34e273 Signed-off-by: Robert Varga (cherry picked from commit 0cb983d35266801f8c8a0f9dc106bdc3f812e599) --- diff --git a/opendaylight/md-sal/samples/clustering-test-app/provider/src/main/java/org/opendaylight/controller/clustering/it/provider/impl/FlappingSingletonService.java b/opendaylight/md-sal/samples/clustering-test-app/provider/src/main/java/org/opendaylight/controller/clustering/it/provider/impl/FlappingSingletonService.java index 3ca46b128f..90ce618f3d 100644 --- a/opendaylight/md-sal/samples/clustering-test-app/provider/src/main/java/org/opendaylight/controller/clustering/it/provider/impl/FlappingSingletonService.java +++ b/opendaylight/md-sal/samples/clustering-test-app/provider/src/main/java/org/opendaylight/controller/clustering/it/provider/impl/FlappingSingletonService.java @@ -10,8 +10,6 @@ package org.opendaylight.controller.clustering.it.provider.impl; import com.google.common.util.concurrent.Futures; import com.google.common.util.concurrent.ListenableFuture; -import java.util.concurrent.ScheduledExecutorService; -import java.util.concurrent.TimeUnit; import java.util.concurrent.atomic.AtomicBoolean; import java.util.concurrent.atomic.AtomicLong; import org.opendaylight.mdsal.singleton.common.api.ClusterSingletonService; @@ -28,8 +26,6 @@ public class FlappingSingletonService implements ClusterSingletonService { private static final ServiceGroupIdentifier SERVICE_GROUP_IDENTIFIER = ServiceGroupIdentifier.create("flapping-singleton-service"); - private static final ScheduledExecutorService EXECUTOR = FinalizableScheduledExecutorService.newSingleThread(); - private final ClusterSingletonServiceProvider singletonServiceProvider; private final AtomicBoolean active = new AtomicBoolean(true); @@ -47,21 +43,16 @@ public class FlappingSingletonService implements ClusterSingletonService { @SuppressWarnings("checkstyle:IllegalCatch") public void instantiateServiceInstance() { LOG.debug("Instantiating flapping-singleton-service."); - - // TODO direct registration/close seem to trigger a bug in singleton state transitions, - // remove the whole executor shenanigans after it's fixed. - EXECUTOR.submit(() -> { - try { - registration.close(); - registration = null; - } catch (Exception e) { - LOG.warn("There was a problem closing flapping singleton service.", e); - setInactive(); - - final long count = flapCount.get(); - flapCount.compareAndSet(count, -count); - } - }); + try { + registration.close(); + registration = null; + } catch (Exception e) { + LOG.warn("There was a problem closing flapping singleton service.", e); + setInactive(); + + final long count = flapCount.get(); + flapCount.compareAndSet(count, -count); + } } @Override @@ -71,22 +62,16 @@ public class FlappingSingletonService implements ClusterSingletonService { flapCount.incrementAndGet(); if (active.get()) { - // TODO direct registration/close seem to trigger a bug in singleton state transitions, - // remove whole executor shenanigans after it's fixed. - // Needs to be delayed slightly otherwise it's triggered as well. - EXECUTOR.schedule(() -> { - LOG.debug("Running re-registration"); - try { - registration = singletonServiceProvider.registerClusterSingletonService(this); - } catch (RuntimeException e) { - LOG.warn("There was a problem re-registering flapping singleton service.", e); - setInactive(); - - final long count = flapCount.get(); - flapCount.compareAndSet(count, -count - 1); - } - - }, 200, TimeUnit.MILLISECONDS); + LOG.debug("Running re-registration"); + try { + registration = singletonServiceProvider.registerClusterSingletonService(this); + } catch (RuntimeException e) { + LOG.warn("There was a problem re-registering flapping singleton service.", e); + setInactive(); + + final long count = flapCount.get(); + flapCount.compareAndSet(count, -count - 1); + } } return Futures.immediateFuture(null);