Fix test helper

This commit is contained in:
Rene Pfeuffer
2019-12-11 12:58:01 +01:00
parent 9a8f0a4ee7
commit a37df2c20b
3 changed files with 18 additions and 7 deletions

View File

@@ -4,7 +4,9 @@ import java.util.function.Consumer;
public interface SyncAsyncExecutor {
ExecutionType execute(Runnable runnable);
default ExecutionType execute(Runnable runnable) {
return execute(ignored -> runnable.run());
}
ExecutionType execute(Consumer<ExecutionType> runnable);

View File

@@ -1,10 +1,23 @@
package sonia.scm.repository.spi;
import java.time.Instant;
import java.util.function.Consumer;
import static sonia.scm.repository.spi.SyncAsyncExecutor.ExecutionType.SYNCHRONOUS;
public final class SyncAsyncExecutors {
public static SyncAsyncExecutor synchronousExecutor() {
return new SyncAsyncExecutor(Runnable::run, Instant.MAX);
return new SyncAsyncExecutor() {
@Override
public ExecutionType execute(Consumer<ExecutionType> runnable) {
runnable.accept(SYNCHRONOUS);
return SYNCHRONOUS;
}
@Override
public boolean hasExecutedAllSynchronously() {
return true;
}
};
}
}

View File

@@ -20,10 +20,6 @@ public class DefaultSyncAsyncExecutor implements SyncAsyncExecutor {
this.switchToAsyncTime = switchToAsyncTime;
}
public ExecutionType execute(Runnable runnable) {
return execute(ignored -> runnable.run());
}
public ExecutionType execute(Consumer<ExecutionType> runnable) {
if (Instant.now().isAfter(switchToAsyncTime)) {
executor.execute(() -> runnable.accept(ASYNCHRONOUS));