• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

leeonky / test-charm-java / 168

31 Mar 2025 02:26PM UTC coverage: 70.152% (-1.2%) from 71.321%
168

push

circleci

leeonky
Refactor test

6313 of 8999 relevant lines covered (70.15%)

0.7 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

75.0
/DAL-extension-basic/src/main/java/com/github/leeonky/dal/extensions/basic/sync/Retryer.java
1
package com.github.leeonky.dal.extensions.basic.sync;
2

3
import com.github.leeonky.util.Sneaky;
4

5
import java.time.Duration;
6
import java.time.Instant;
7
import java.util.concurrent.CompletableFuture;
8
import java.util.concurrent.ExecutionException;
9
import java.util.function.Supplier;
10

11
import static java.util.concurrent.TimeUnit.MILLISECONDS;
12

13
public class Retryer {
14
    private static int defaultTimeout = 0;
1✔
15
    private final int waitingTime;
16
    private final int interval;
17

18
    public Retryer(int waitingTime, int interval) {
1✔
19
        this.waitingTime = waitingTime;
1✔
20
        this.interval = interval;
1✔
21
    }
1✔
22

23
    public static void setDefaultTimeout(int ms) {
24
        defaultTimeout = ms;
1✔
25
    }
1✔
26

27
    public static int defaultTimeout() {
28
        return defaultTimeout;
×
29
    }
30

31
    public <T> T get(Supplier<T> s) {
32
        Throwable exception;
33
        Instant start = Instant.now();
1✔
34
        do {
35
            try {
36
                return CompletableFuture.supplyAsync(s).get(Math.max(waitingTime, defaultTimeout), MILLISECONDS);
1✔
37
            } catch (ExecutionException e) {
1✔
38
                exception = e.getCause();
1✔
39
            } catch (Throwable e) {
1✔
40
                exception = e;
1✔
41
            }
1✔
42
        } while (timeout(start) && sleep());
1✔
43
        return Sneaky.sneakyThrow(exception);
×
44
    }
45

46
    private boolean timeout(Instant now) {
47
        return Duration.between(now, Instant.now()).toMillis() < waitingTime;
1✔
48
    }
49

50
    private boolean sleep() {
51
        Sneaky.run(() -> Thread.sleep(interval));
1✔
52
        return true;
1✔
53
    }
54

55
    public void run(Runnable runnable) throws Throwable {
56
        get(() -> {
×
57
            runnable.run();
×
58
            return null;
×
59
        });
60
    }
×
61
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc