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

leeonky / test-charm-java / 156

20 Mar 2025 01:53PM UTC coverage: 74.243% (-0.2%) from 74.475%
156

push

circleci

leeonky
Refactor

14 of 15 new or added lines in 12 files covered. (93.33%)

126 existing lines in 29 files now uncovered.

7947 of 10704 relevant lines covered (74.24%)

0.74 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.concurrent.TimeUnit;
10
import java.util.function.Supplier;
11

12
import static com.github.leeonky.dal.runtime.DalException.extractException;
13

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

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

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

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

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

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

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

57
    public void run(Runnable runnable) throws Throwable {
UNCOV
58
        get(() -> {
×
59
            runnable.run();
×
UNCOV
60
            return null;
×
61
        });
UNCOV
62
    }
×
63
}
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