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

box / box-java-sdk-gen / #241

23 Jun 2025 12:23PM UTC coverage: 35.71% (-0.01%) from 35.722%
#241

Pull #343

github

web-flow
Merge ee8babc34 into 8c4ecda2f
Pull Request #343: test: Hubs API integration tests (box/box-codegen#727)

446 of 1240 new or added lines in 43 files covered. (35.97%)

9 existing lines in 5 files now uncovered.

16606 of 46502 relevant lines covered (35.71%)

0.36 hits per line

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

42.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(Builder 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;
1✔
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");
1✔
61
    if (!(retryAfterHeader == null)) {
1✔
62
      return Double.parseDouble(retryAfterHeader);
1✔
63
    }
UNCOV
64
    double randomization =
×
UNCOV
65
        random(1 - this.retryRandomizationFactor, 1 + this.retryRandomizationFactor);
×
UNCOV
66
    double exponential = Math.pow(2, attemptNumber);
×
UNCOV
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 Builder {
83

84
    protected int maxAttempts;
85

86
    protected double retryRandomizationFactor;
87

88
    protected double retryBaseInterval;
89

90
    public Builder() {
×
91
      this.maxAttempts = 5;
×
92
      this.retryRandomizationFactor = 0.5;
×
93
      this.retryBaseInterval = 1;
×
94
    }
×
95

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

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

106
    public Builder 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