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

box / box-java-sdk / #5872

17 Dec 2025 10:36AM UTC coverage: 12.895% (-0.008%) from 12.903%
#5872

Pull #1639

github

web-flow
Merge 6178ff389 into e14e97bb7
Pull Request #1639: test(boxsdkgen): Metadata Taxonomies integration tests (box/box-codegen#897)

8368 of 64891 relevant lines covered (12.9%)

0.13 hits per line

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

0.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 int maxRetriesOnException;
17

18
  public BoxRetryStrategy() {
×
19
    this.maxAttempts = 5;
×
20
    this.retryRandomizationFactor = 0.5;
×
21
    this.retryBaseInterval = 1;
×
22
    this.maxRetriesOnException = 2;
×
23
  }
×
24

25
  protected BoxRetryStrategy(Builder builder) {
×
26
    this.maxAttempts = builder.maxAttempts;
×
27
    this.retryRandomizationFactor = builder.retryRandomizationFactor;
×
28
    this.retryBaseInterval = builder.retryBaseInterval;
×
29
    this.maxRetriesOnException = builder.maxRetriesOnException;
×
30
  }
×
31

32
  @Override
33
  public boolean shouldRetry(
34
      FetchOptions fetchOptions, FetchResponse fetchResponse, int attemptNumber) {
35
    if (fetchResponse.getStatus() == 0) {
×
36
      return attemptNumber <= this.maxRetriesOnException;
×
37
    }
38
    boolean isSuccessful = fetchResponse.getStatus() >= 200 && fetchResponse.getStatus() < 400;
×
39
    String retryAfterHeader =
×
40
        (fetchResponse.getHeaders().containsKey("Retry-After")
×
41
            ? fetchResponse.getHeaders().get("Retry-After")
×
42
            : null);
43
    boolean isAcceptedWithRetryAfter =
×
44
        fetchResponse.getStatus() == 202 && !(retryAfterHeader == null);
×
45
    if (attemptNumber >= this.maxAttempts) {
×
46
      return false;
×
47
    }
48
    if (isAcceptedWithRetryAfter) {
×
49
      return true;
×
50
    }
51
    if (fetchResponse.getStatus() >= 500) {
×
52
      return true;
×
53
    }
54
    if (fetchResponse.getStatus() == 429) {
×
55
      return true;
×
56
    }
57
    if (fetchResponse.getStatus() == 401 && !(fetchOptions.getAuth() == null)) {
×
58
      fetchOptions.getAuth().refreshToken(fetchOptions.getNetworkSession());
×
59
      return true;
×
60
    }
61
    if (isSuccessful) {
×
62
      return false;
×
63
    }
64
    return false;
×
65
  }
66

67
  @Override
68
  public double retryAfter(
69
      FetchOptions fetchOptions, FetchResponse fetchResponse, int attemptNumber) {
70
    String retryAfterHeader =
×
71
        (fetchResponse.getHeaders().containsKey("Retry-After")
×
72
            ? fetchResponse.getHeaders().get("Retry-After")
×
73
            : null);
74
    if (!(retryAfterHeader == null)) {
×
75
      return Double.parseDouble(retryAfterHeader);
×
76
    }
77
    double randomization =
×
78
        random(1 - this.retryRandomizationFactor, 1 + this.retryRandomizationFactor);
×
79
    double exponential = Math.pow(2, attemptNumber);
×
80
    return exponential * this.retryBaseInterval * randomization;
×
81
  }
82

83
  public int getMaxAttempts() {
84
    return maxAttempts;
×
85
  }
86

87
  public double getRetryRandomizationFactor() {
88
    return retryRandomizationFactor;
×
89
  }
90

91
  public double getRetryBaseInterval() {
92
    return retryBaseInterval;
×
93
  }
94

95
  public int getMaxRetriesOnException() {
96
    return maxRetriesOnException;
×
97
  }
98

99
  public static class Builder {
100

101
    protected int maxAttempts;
102

103
    protected double retryRandomizationFactor;
104

105
    protected double retryBaseInterval;
106

107
    protected int maxRetriesOnException;
108

109
    public Builder() {
×
110
      this.maxAttempts = 5;
×
111
      this.retryRandomizationFactor = 0.5;
×
112
      this.retryBaseInterval = 1;
×
113
      this.maxRetriesOnException = 2;
×
114
    }
×
115

116
    public Builder maxAttempts(int maxAttempts) {
117
      this.maxAttempts = maxAttempts;
×
118
      return this;
×
119
    }
120

121
    public Builder retryRandomizationFactor(double retryRandomizationFactor) {
122
      this.retryRandomizationFactor = retryRandomizationFactor;
×
123
      return this;
×
124
    }
125

126
    public Builder retryBaseInterval(double retryBaseInterval) {
127
      this.retryBaseInterval = retryBaseInterval;
×
128
      return this;
×
129
    }
130

131
    public Builder maxRetriesOnException(int maxRetriesOnException) {
132
      this.maxRetriesOnException = maxRetriesOnException;
×
133
      return this;
×
134
    }
135

136
    public BoxRetryStrategy build() {
137
      return new BoxRetryStrategy(this);
×
138
    }
139
  }
140
}
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

© 2025 Coveralls, Inc