use of java.util.concurrent.ScheduledExecutorService in project hazelcast by hazelcast.
the class ExecutionDelayTest method testExecutorRetriesTask_whenOneNodeShutdowns.
@Test
public void testExecutorRetriesTask_whenOneNodeShutdowns() throws InterruptedException, ExecutionException {
final int taskCount = 20;
ScheduledExecutorService ex = Executors.newSingleThreadScheduledExecutor();
try {
ex.schedule(new Runnable() {
@Override
public void run() {
instances.get(1).shutdown();
}
}, 1000, TimeUnit.MILLISECONDS);
Task task = new Task();
runClient(task, taskCount);
assertTrueEventually(new AssertTask() {
@Override
public void run() throws Exception {
final int taskExecutions = COUNTER.get();
assertTrue(taskExecutions >= taskCount);
}
});
} finally {
ex.shutdown();
}
}
use of java.util.concurrent.ScheduledExecutorService in project hazelcast by hazelcast.
the class ExecutionDelayTest method testExecutorRetriesTask_whenOneNodeTerminates.
@Test
public void testExecutorRetriesTask_whenOneNodeTerminates() throws InterruptedException, ExecutionException {
final int taskCount = 20;
ScheduledExecutorService ex = Executors.newSingleThreadScheduledExecutor();
try {
ex.schedule(new Runnable() {
@Override
public void run() {
instances.get(1).getLifecycleService().terminate();
}
}, 1000, TimeUnit.MILLISECONDS);
Task task = new Task();
runClient(task, taskCount);
assertTrueEventually(new AssertTask() {
@Override
public void run() throws Exception {
final int taskExecutions = COUNTER.get();
assertTrue(taskExecutions >= taskCount);
}
});
} finally {
ex.shutdown();
}
}
use of java.util.concurrent.ScheduledExecutorService in project musiccabinet by hakko.
the class UpdateNowPlayingService method afterPropertiesSet.
@Override
public void afterPropertiesSet() throws Exception {
taskExecutor.execute(new Runnable() {
@Override
public void run() {
try {
receive();
} catch (Throwable t) {
LOG.error("Unexpected error caught while receiving scrobbles!", t);
}
}
});
ScheduledExecutorService scheduler = Executors.newSingleThreadScheduledExecutor();
scheduler.scheduleAtFixedRate(new Runnable() {
@Override
public void run() {
try {
scrobbleTracks();
} catch (Throwable t) {
LOG.error("Unexpected error caught while scrobbling!", t);
}
}
}, 1, 1, TimeUnit.MINUTES);
}
use of java.util.concurrent.ScheduledExecutorService in project guava by google.
the class MoreExecutorsTest method testGetScheduledExitingExcutorService_shutdownHookRegistered.
public void testGetScheduledExitingExcutorService_shutdownHookRegistered() throws InterruptedException {
TestApplication application = new TestApplication();
ScheduledThreadPoolExecutor executor = mock(ScheduledThreadPoolExecutor.class);
ThreadFactory threadFactory = mock(ThreadFactory.class);
when(executor.getThreadFactory()).thenReturn(threadFactory);
ScheduledExecutorService unused = application.getExitingScheduledExecutorService(executor);
application.shutdown();
verify(executor).shutdown();
}
use of java.util.concurrent.ScheduledExecutorService in project guava by google.
the class AbstractScheduledServiceTest method testTimeout.
public void testTimeout() {
// Create a service whose executor will never run its commands
Service service = new AbstractScheduledService() {
@Override
protected Scheduler scheduler() {
return Scheduler.newFixedDelaySchedule(0, 1, TimeUnit.NANOSECONDS);
}
@Override
protected ScheduledExecutorService executor() {
return TestingExecutors.noOpScheduledExecutor();
}
@Override
protected void runOneIteration() throws Exception {
}
@Override
protected String serviceName() {
return "Foo";
}
};
try {
service.startAsync().awaitRunning(1, TimeUnit.MILLISECONDS);
fail("Expected timeout");
} catch (TimeoutException e) {
assertThat(e).hasMessage("Timed out waiting for Foo [STARTING] to reach the RUNNING state.");
}
}
Aggregations