use of com.google.common.util.concurrent.Service.Listener in project guava by google.
the class AbstractServiceTest method testManualServiceStopMultipleTimesWhileStarting.
/**
* This tests for a bug where if {@link Service#stopAsync()} was called while the service was
* {@link State#STARTING} more than once, the {@link Listener#stopping(State)} callback would get
* called multiple times.
*/
public void testManualServiceStopMultipleTimesWhileStarting() throws Exception {
ManualSwitchedService service = new ManualSwitchedService();
final AtomicInteger stopppingCount = new AtomicInteger();
service.addListener(new Listener() {
@Override
public void stopping(State from) {
stopppingCount.incrementAndGet();
}
}, directExecutor());
service.startAsync();
service.stopAsync();
assertEquals(1, stopppingCount.get());
service.stopAsync();
assertEquals(1, stopppingCount.get());
}
use of com.google.common.util.concurrent.Service.Listener in project guava by google.
the class AbstractServiceTest method testListenerDoesntDeadlockOnStopAndWaitFromTerminated.
public void testListenerDoesntDeadlockOnStopAndWaitFromTerminated() throws Exception {
final NoOpThreadedService service = new NoOpThreadedService();
service.addListener(new Listener() {
@Override
public void terminated(State from) {
service.stopAsync().awaitTerminated();
}
}, directExecutor());
service.startAsync().awaitRunning();
Thread thread = new Thread() {
@Override
public void run() {
service.stopAsync().awaitTerminated();
}
};
thread.start();
thread.join(LONG_TIMEOUT_MILLIS);
assertFalse(thread + " is deadlocked", thread.isAlive());
}
use of com.google.common.util.concurrent.Service.Listener in project guava by google.
the class AbstractServiceTest method testListenerDoesntDeadlockOnStartAndWaitFromRunning.
public void testListenerDoesntDeadlockOnStartAndWaitFromRunning() throws Exception {
final NoOpThreadedService service = new NoOpThreadedService();
service.addListener(new Listener() {
@Override
public void running() {
service.awaitRunning();
}
}, directExecutor());
service.startAsync().awaitRunning(LONG_TIMEOUT_MILLIS, TimeUnit.MILLISECONDS);
service.stopAsync();
}
Aggregations