Skip to content

Commit ced7adc

Browse files
committed
[ISSUE-1462] Use low retry-backoff value when running tests
- Because we use a mock server
1 parent f3b3405 commit ced7adc

File tree

4 files changed

+46
-21
lines changed

4 files changed

+46
-21
lines changed

tmail-backend/tmail-third-party/openpaas/src/main/java/com/linagora/tmail/dav/DavClient.java

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,6 @@
5858

5959
public class DavClient {
6060
public static final int MAX_CALENDAR_OBJECT_UPDATE_RETRIES = 5;
61-
public static final Duration MIN_CALENDAR_OBJECT_UPDATE_RETRY_BACKOFF = Duration.ofMillis(100);
6261

6362
private static final Logger LOGGER = LoggerFactory.getLogger(DavClient.class);
6463
private static final Duration DEFAULT_RESPONSE_TIMEOUT = Duration.ofSeconds(10);
@@ -67,10 +66,14 @@ public class DavClient {
6766
private static final String ACCEPT_VCARD_JSON = "application/vcard+json";
6867
private static final String ACCEPT_XML = "application/xml";
6968
private static final String CONTENT_TYPE_VCARD = "application/vcard";
70-
private static final boolean SHOULD_RETRY_CALENDAR_OBJECT_UPDATE = true;
7169

7270
private final HttpClient client;
7371
private final DavConfiguration config;
72+
public final Duration calendarObjectUpdateRetryBackoff =
73+
Optional.ofNullable(System.getProperty("MIN_CALENDAR_OBJECT_UPDATE_RETRY_BACKOFF_IN_MILLS"))
74+
.map(Long::parseLong)
75+
.map(Duration::ofMillis)
76+
.orElse(Duration.ofMillis(100));
7477

7578
public DavClient(DavConfiguration config) {
7679
this.config = config;
@@ -157,8 +160,8 @@ public Mono<Void> updateCalendarObject(String username, URI calendarObjectUri, F
157160
.map(calendarObjectUpdater)
158161
.flatMap(updatedCalendarObject -> doUpdateCalendarObject(username, updatedCalendarObject))
159162
.retryWhen(
160-
Retry.backoff(MAX_CALENDAR_OBJECT_UPDATE_RETRIES, MIN_CALENDAR_OBJECT_UPDATE_RETRY_BACKOFF)
161-
.filter(e -> e instanceof DavClientException && ((DavClientException) e).shouldRetry())
163+
Retry.backoff(MAX_CALENDAR_OBJECT_UPDATE_RETRIES, calendarObjectUpdateRetryBackoff)
164+
.filter(RetriableDavClientException.class::isInstance)
162165
.onRetryExhaustedThrow((retryBackoffSpec, retrySignal) ->
163166
new DavClientException("Max retries exceeded for calendar update", retrySignal.failure())));
164167
}
@@ -184,10 +187,10 @@ private static Mono<Void> handleCalendarObjectUpdateResponse(DavCalendarObject u
184187
() -> LOGGER.info("Calendar object '{}' updated successfully.",
185188
updatedCalendarObject.uri()));
186189
} else if (response.status() == HttpResponseStatus.PRECONDITION_FAILED) {
187-
return Mono.error(new DavClientException(
190+
return Mono.error(new RetriableDavClientException(
188191
String.format(
189192
"Precondition failed (ETag mismatch) when updating calendar object '%s'. Retry may be needed.",
190-
updatedCalendarObject.uri()), SHOULD_RETRY_CALENDAR_OBJECT_UPDATE));
193+
updatedCalendarObject.uri())));
191194
} else {
192195
return Mono.error(new DavClientException(
193196
String.format(

tmail-backend/tmail-third-party/openpaas/src/main/java/com/linagora/tmail/dav/DavClientException.java

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -19,27 +19,12 @@
1919
package com.linagora.tmail.dav;
2020

2121
public class DavClientException extends RuntimeException {
22-
private final boolean shouldRetry;
2322

2423
public DavClientException(String message) {
25-
this(message, false);
26-
}
27-
28-
public DavClientException(String message, boolean shouldRetry) {
2924
super(message);
30-
this.shouldRetry = shouldRetry;
3125
}
3226

3327
public DavClientException(String message, Throwable cause) {
34-
this(message, cause, false);
35-
}
36-
37-
public DavClientException(String message, Throwable cause, boolean shouldRetry) {
3828
super(message, cause);
39-
this.shouldRetry = shouldRetry;
40-
}
41-
42-
public boolean shouldRetry() {
43-
return shouldRetry;
4429
}
4530
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
/********************************************************************
2+
* As a subpart of Twake Mail, this file is edited by Linagora. *
3+
* *
4+
* https://twake-mail.com/ *
5+
* https://linagora.com *
6+
* *
7+
* This file is subject to The Affero Gnu Public License *
8+
* version 3. *
9+
* *
10+
* https://www.gnu.org/licenses/agpl-3.0.en.html *
11+
* *
12+
* This program is distributed in the hope that it will be *
13+
* useful, but WITHOUT ANY WARRANTY; without even the implied *
14+
* warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR *
15+
* PURPOSE. See the GNU Affero General Public License for *
16+
* more details. *
17+
********************************************************************/
18+
19+
package com.linagora.tmail.dav;
20+
21+
public class RetriableDavClientException extends DavClientException {
22+
23+
public RetriableDavClientException(String message) {
24+
super(message);
25+
}
26+
27+
public RetriableDavClientException(String message, Throwable cause) {
28+
super(message, cause);
29+
}
30+
}

tmail-backend/tmail-third-party/openpaas/src/test/java/com/linagora/tmail/dav/DavClientTest.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@
5252
import org.apache.http.HttpStatus;
5353
import org.apache.james.core.MailAddress;
5454
import org.apache.james.util.ClassLoaderUtils;
55+
import org.junit.jupiter.api.AfterEach;
5556
import org.junit.jupiter.api.BeforeEach;
5657
import org.junit.jupiter.api.Test;
5758
import org.junit.jupiter.api.extension.RegisterExtension;
@@ -79,9 +80,15 @@ public class DavClientTest {
7980

8081
@BeforeEach
8182
void setup() {
83+
System.setProperty("MIN_CALENDAR_OBJECT_UPDATE_RETRY_BACKOFF_IN_MILLS", "10");
8284
client = new DavClient(davServerExtension.getDavConfiguration());
8385
}
8486

87+
@AfterEach
88+
void tearDown() {
89+
System.clearProperty("MIN_CALENDAR_OBJECT_UPDATE_RETRY_BACKOFF_IN_MILLS");
90+
}
91+
8592
@Test
8693
void existsCollectedContactShouldReturnTrueWhenHTTPResponseIs200() {
8794
String collectedContactUid = UUID.randomUUID().toString();

0 commit comments

Comments
 (0)