-
Notifications
You must be signed in to change notification settings - Fork 98
Expand file tree
/
Copy pathDataLoaderTimeTest.java
More file actions
45 lines (30 loc) · 1.3 KB
/
DataLoaderTimeTest.java
File metadata and controls
45 lines (30 loc) · 1.3 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
package org.dataloader;
import org.dataloader.fixtures.TestingClock;
import org.junit.Test;
import java.time.Instant;
import static org.dataloader.fixtures.TestKit.keysAsValues;
import static org.hamcrest.Matchers.equalTo;
import static org.junit.Assert.assertThat;
@SuppressWarnings("UnusedReturnValue")
public class DataLoaderTimeTest {
@Test
public void should_set_and_instant_if_dispatched() {
TestingClock clock = new TestingClock();
DataLoader<Integer, Integer> dataLoader = new ClockDataLoader<>(keysAsValues(), clock);
Instant then = clock.instant();
long sinceMS = dataLoader.getTimeSinceDispatch().toMillis();
assertThat(sinceMS, equalTo(0L));
assertThat(then, equalTo(dataLoader.getLastDispatchTime()));
then = clock.instant();
clock.jump(1000);
sinceMS = dataLoader.getTimeSinceDispatch().toMillis();
assertThat(sinceMS, equalTo(1000L));
assertThat(then, equalTo(dataLoader.getLastDispatchTime()));
// dispatch and hence reset the time of last dispatch
then = clock.instant();
dataLoader.dispatch();
sinceMS = dataLoader.getTimeSinceDispatch().toMillis();
assertThat(sinceMS, equalTo(0L));
assertThat(then, equalTo(dataLoader.getLastDispatchTime()));
}
}