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

box / box-java-sdk-gen / #170

30 May 2025 01:03PM UTC coverage: 35.534% (-0.1%) from 35.646%
#170

Pull #321

github

web-flow
Merge a16576173 into 55711f79b
Pull Request #321: feat: Update legal holds and AI models (box/box-openapi#526)

3 of 32 new or added lines in 5 files covered. (9.38%)

46 existing lines in 15 files now uncovered.

15586 of 43862 relevant lines covered (35.53%)

0.36 hits per line

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

36.96
/src/main/java/com/box/sdkgen/networking/retries/BoxRetryStrategy.java
1
package com.box.sdkgen.networking.retries;
2

3
import static com.box.sdkgen.internal.utils.UtilsManager.random;
4

5
import com.box.sdkgen.networking.fetchoptions.FetchOptions;
6
import com.box.sdkgen.networking.fetchresponse.FetchResponse;
7

8
public class BoxRetryStrategy implements RetryStrategy {
9

10
  public int maxAttempts;
11

12
  public double retryRandomizationFactor;
13

14
  public double retryBaseInterval;
15

16
  public BoxRetryStrategy() {
1✔
17
    this.maxAttempts = 5;
1✔
18
    this.retryRandomizationFactor = 0.5;
1✔
19
    this.retryBaseInterval = 1;
1✔
20
  }
1✔
21

22
  protected BoxRetryStrategy(BoxRetryStrategyBuilder builder) {
×
23
    this.maxAttempts = builder.maxAttempts;
×
24
    this.retryRandomizationFactor = builder.retryRandomizationFactor;
×
25
    this.retryBaseInterval = builder.retryBaseInterval;
×
26
  }
×
27

28
  @Override
29
  public boolean shouldRetry(
30
      FetchOptions fetchOptions, FetchResponse fetchResponse, int attemptNumber) {
31
    boolean isSuccessful = fetchResponse.getStatus() >= 200 && fetchResponse.getStatus() < 400;
1✔
32
    String retryAfterHeader = fetchResponse.getHeaders().get("Retry-After");
1✔
33
    boolean isAcceptedWithRetryAfter =
1✔
34
        fetchResponse.getStatus() == 202 && !(retryAfterHeader == null);
1✔
35
    if (attemptNumber >= this.maxAttempts) {
1✔
36
      return false;
×
37
    }
38
    if (isAcceptedWithRetryAfter) {
1✔
39
      return true;
×
40
    }
41
    if (fetchResponse.getStatus() >= 500) {
1✔
42
      return true;
×
43
    }
44
    if (fetchResponse.getStatus() == 429) {
1✔
UNCOV
45
      return true;
×
46
    }
47
    if (fetchResponse.getStatus() == 401 && !(fetchOptions.getAuth() == null)) {
1✔
48
      fetchOptions.getAuth().refreshToken(fetchOptions.getNetworkSession());
×
49
      return true;
×
50
    }
51
    if (isSuccessful) {
1✔
52
      return false;
1✔
53
    }
54
    return false;
1✔
55
  }
56

57
  @Override
58
  public double retryAfter(
59
      FetchOptions fetchOptions, FetchResponse fetchResponse, int attemptNumber) {
UNCOV
60
    String retryAfterHeader = fetchResponse.getHeaders().get("Retry-After");
×
UNCOV
61
    if (!(retryAfterHeader == null)) {
×
UNCOV
62
      return Double.parseDouble(retryAfterHeader);
×
63
    }
64
    double randomization =
×
65
        random(1 - this.retryRandomizationFactor, 1 + this.retryRandomizationFactor);
×
66
    double exponential = Math.pow(2, attemptNumber);
×
67
    return exponential * this.retryBaseInterval * randomization;
×
68
  }
69

70
  public int getMaxAttempts() {
71
    return maxAttempts;
×
72
  }
73

74
  public double getRetryRandomizationFactor() {
75
    return retryRandomizationFactor;
×
76
  }
77

78
  public double getRetryBaseInterval() {
79
    return retryBaseInterval;
×
80
  }
81

82
  public static class BoxRetryStrategyBuilder {
×
83

84
    protected int maxAttempts;
85

86
    protected double retryRandomizationFactor;
87

88
    protected double retryBaseInterval;
89

90
    public BoxRetryStrategyBuilder maxAttempts(int maxAttempts) {
91
      this.maxAttempts = maxAttempts;
×
92
      return this;
×
93
    }
94

95
    public BoxRetryStrategyBuilder retryRandomizationFactor(double retryRandomizationFactor) {
96
      this.retryRandomizationFactor = retryRandomizationFactor;
×
97
      return this;
×
98
    }
99

100
    public BoxRetryStrategyBuilder retryBaseInterval(double retryBaseInterval) {
101
      this.retryBaseInterval = retryBaseInterval;
×
102
      return this;
×
103
    }
104

105
    public BoxRetryStrategy build() {
106
      return new BoxRetryStrategy(this);
×
107
    }
108
  }
109
}
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