com.thorstenmarx.webtools.test.MockedExecutor Maven / Gradle / Ivy
package com.thorstenmarx.webtools.test;
/*-
* #%L
* webtools-actions
* %%
* Copyright (C) 2016 - 2018 Thorsten Marx
* %%
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public
* License along with this program. If not, see
* .
* #L%
*/
import com.thorstenmarx.webtools.api.execution.Executor;
import java.util.concurrent.Callable;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.Executors;
import java.util.concurrent.Future;
import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.ScheduledFuture;
import java.util.concurrent.TimeUnit;
/**
*
* @author marx
*/
public class MockedExecutor implements Executor {
ScheduledExecutorService scheduler;
public MockedExecutor () {
scheduler = Executors.newSingleThreadScheduledExecutor();
}
public void shutdown () {
scheduler.shutdownNow();
}
@Override
public CompletableFuture execute(Runnable task) {
return CompletableFuture.runAsync(task, scheduler);
}
@Override
public ScheduledFuture> schedule(Runnable task, long delay, TimeUnit timeUnit) {
return scheduler.schedule(task, delay, timeUnit);
}
@Override
public ScheduledFuture> scheduleFixedDelay(Runnable task, long initialDelay, long delay, TimeUnit timeUnit) {
return scheduler.scheduleWithFixedDelay(task, initialDelay, delay, timeUnit);
}
@Override
public ScheduledFuture> scheduleFixedRate(Runnable task, long initialDelay, long period, TimeUnit timeUnit) {
return scheduler.scheduleAtFixedRate(task, initialDelay, period, timeUnit);
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy