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

box / box-java-sdk-gen / #186

04 Jun 2025 10:42AM UTC coverage: 34.762% (-0.9%) from 35.631%
#186

Pull #327

github

web-flow
Merge a4b5eccbc into 28f2ec7f8
Pull Request #327: chore: Update .codegen.json with commit hash of codegen and openapi spec

15770 of 45365 relevant lines covered (34.76%)

0.35 hits per line

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

34.0
/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✔
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) {
60
    String retryAfterHeader = fetchResponse.getHeaders().get("Retry-After");
×
61
    if (!(retryAfterHeader == null)) {
×
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() {
×
91
      this.maxAttempts = 5;
×
92
      this.retryRandomizationFactor = 0.5;
×
93
      this.retryBaseInterval = 1;
×
94
    }
×
95

96
    public BoxRetryStrategyBuilder maxAttempts(int maxAttempts) {
97
      this.maxAttempts = maxAttempts;
×
98
      return this;
×
99
    }
100

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

106
    public BoxRetryStrategyBuilder retryBaseInterval(double retryBaseInterval) {
107
      this.retryBaseInterval = retryBaseInterval;
×
108
      return this;
×
109
    }
110

111
    public BoxRetryStrategy build() {
112
      return new BoxRetryStrategy(this);
×
113
    }
114
  }
115
}
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