ThreadSleepAwaiter.java

1
package fr.sii.ogham.core.async;
2
3
import java.time.Instant;
4
import java.util.function.Supplier;
5
6
import fr.sii.ogham.core.exception.async.WaitException;
7
8
/**
9
 * Implementation that uses {@link Thread#sleep(long)} to wait for a delay.
10
 * 
11
 * @author Aurélien Baudet
12
 */
13
public class ThreadSleepAwaiter implements Awaiter {
14
	private final Supplier<Instant> currentTimeSupplier;
15
16
	/**
17
	 * Initializes with the default time supplier ({@link Instant#now()}).
18
	 */
19
	public ThreadSleepAwaiter() {
20
		this(Instant::now);
21
	}
22
23
	/**
24
	 * Initialize with a supplier that gives the current time.
25
	 * 
26
	 * @param currentTimeSupplier
27
	 *            gives the current time
28
	 */
29
	public ThreadSleepAwaiter(Supplier<Instant> currentTimeSupplier) {
30
		super();
31
		this.currentTimeSupplier = currentTimeSupplier;
32
	}
33
34
	@Override
35
	public void waitUntil(Instant date) throws WaitException {
36
		try {
37
			long delay = Math.max(0, date.minusMillis(currentTimeSupplier.get().toEpochMilli()).toEpochMilli());
38 2 1. waitUntil : removed call to java/lang/Thread::sleep → NO_COVERAGE
2. waitUntil : removed call to java/lang/Thread::sleep → SURVIVED
			Thread.sleep(delay);
39
		} catch (InterruptedException e) {
40 1 1. waitUntil : removed call to java/lang/Thread::interrupt → NO_COVERAGE
			Thread.currentThread().interrupt();
41
			throw new WaitException("Current thread interrupted", e);
42
		}
43
	}
44
45
}

Mutations

38

1.1
Location : waitUntil
Killed by : none
removed call to java/lang/Thread::sleep → NO_COVERAGE

2.2
Location : waitUntil
Killed by : none
removed call to java/lang/Thread::sleep → SURVIVED

40

1.1
Location : waitUntil
Killed by : none
removed call to java/lang/Thread::interrupt → NO_COVERAGE

Active mutators

Tests examined


Report generated by PIT OGHAM