Skip to content

Commit cd742e0

Browse files
authored
Merge pull request #76 from Petrakeas/petrakeas/fix/replace-exception-class
Replace TimeLimitExceededException with TimeoutException
2 parents 30c1817 + 73f5c6d commit cd742e0

File tree

3 files changed

+15
-18
lines changed

3 files changed

+15
-18
lines changed

TransifexNativeSDK/clitool/src/main/java/com/transifex/clitool/MainClass.java

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,9 @@
1818
import java.util.Map;
1919
import java.util.Set;
2020
import java.util.concurrent.Callable;
21+
import java.util.concurrent.TimeoutException;
2122
import java.util.logging.Logger;
2223

23-
import javax.naming.TimeLimitExceededException;
24-
2524
import androidx.annotation.NonNull;
2625
import androidx.annotation.Nullable;
2726
import picocli.CommandLine;
@@ -216,7 +215,7 @@ public Integer call() throws Exception {
216215
LocaleData.TxJobStatus jobStatus = null;
217216
try {
218217
jobStatus = cdsHandler.pushSourceStrings(postData);
219-
} catch (TimeLimitExceededException e) {
218+
} catch (TimeoutException e) {
220219
System.out.println("Strings are queued for processing");
221220
return 0;
222221
}
@@ -270,7 +269,7 @@ public Integer call() throws Exception {
270269
LocaleData.TxJobStatus jobStatus = null;
271270
try {
272271
jobStatus = cdsHandler.pushSourceStrings(postData);
273-
} catch (TimeLimitExceededException e) {
272+
} catch (TimeoutException e) {
274273
System.out.println("Source string clearing is queued for processing");
275274
return 0;
276275
}
@@ -446,4 +445,4 @@ String getErrorString(@NonNull LocaleData.TxJobStatus jobStatus) {
446445
private static @NonNull String getNonDownloadedLocalesString(@NonNull HashSet<String> nonDownloadedLocales) {
447446
return "The translations for the following locales were not downloaded: " + Arrays.toString(nonDownloadedLocales.toArray());
448447
}
449-
}
448+
}

TransifexNativeSDK/common/src/main/java/com/transifex/common/CDSHandler.java

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -21,11 +21,10 @@
2121
import java.net.URISyntaxException;
2222
import java.net.URL;
2323
import java.util.Set;
24+
import java.util.concurrent.TimeoutException;
2425
import java.util.logging.Level;
2526
import java.util.logging.Logger;
2627

27-
import javax.naming.TimeLimitExceededException;
28-
2928
import androidx.annotation.NonNull;
3029
import androidx.annotation.Nullable;
3130

@@ -345,11 +344,11 @@ public LocaleData.TranslationMap fetchTranslations(@Nullable String localeCode,
345344
* The job status can be either <code>"completed"</code> or <code>"failed"</code>.
346345
* If everything fails, <code>null</code> is returned.
347346
*
348-
* @throws TimeLimitExceededException When the server takes longer than 20 seconds to complete
347+
* @throws TimeoutException When the server takes longer than 20 seconds to complete
349348
* processing the job.
350349
*/
351350
public @Nullable
352-
LocaleData.TxJobStatus pushSourceStrings(@NonNull LocaleData.TxPostData postData) throws TimeLimitExceededException {
351+
LocaleData.TxJobStatus pushSourceStrings(@NonNull LocaleData.TxPostData postData) throws TimeoutException {
353352
LocaleData.TxPostResponseData response = pushSourceStringsInternal(postData);
354353
if (response == null) {
355354
return null;
@@ -462,13 +461,13 @@ LocaleData.TxJobStatus pushSourceStrings(@NonNull LocaleData.TxPostData postData
462461
* @return The job status object or <code>null</code> if everything failed. The job status can
463462
* be either <code>"completed"</code> or <code>"failed"</code>.
464463
*
465-
* @throws TimeLimitExceededException When the server takes longer than 20 seconds to complete
464+
* @throws TimeoutException When the server takes longer than 20 seconds to complete
466465
* processing the job.
467466
*
468467
* @see <a href="https://github.com/transifex/transifex-delivery/#job-status">
469468
* https://github.com/transifex/transifex-delivery/#job-status</a>
470469
*/
471-
private @Nullable LocaleData.TxJobStatus getJobStatus(@NonNull LocaleData.TxPostResponseData responseData) throws TimeLimitExceededException {
470+
private @Nullable LocaleData.TxJobStatus getJobStatus(@NonNull LocaleData.TxPostResponseData responseData) throws TimeoutException {
472471
URL url = null;
473472
try {
474473
URI cdsContentURI = new URI(mCdsHost);
@@ -531,7 +530,7 @@ LocaleData.TxJobStatus pushSourceStrings(@NonNull LocaleData.TxPostData postData
531530
}
532531
}
533532

534-
throw new TimeLimitExceededException("Server is still processing the pushed strings");
533+
throw new TimeoutException("Server is still processing the pushed strings");
535534
}
536535

537536
/**

TransifexNativeSDK/common/src/test/java/com/transifex/common/CDSHandlerTest.java

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,7 @@
1111
import java.util.Arrays;
1212
import java.util.HashSet;
1313
import java.util.LinkedHashMap;
14-
15-
import javax.naming.TimeLimitExceededException;
14+
import java.util.concurrent.TimeoutException;
1615

1716
import androidx.annotation.NonNull;
1817
import androidx.annotation.Nullable;
@@ -354,7 +353,7 @@ public void testPushSourceStrings_badURL() {
354353
LocaleData.TxJobStatus jobStatus = null;
355354
try {
356355
jobStatus = cdsHandler.pushSourceStrings(postData);
357-
} catch (TimeLimitExceededException ignored) {}
356+
} catch (TimeoutException ignored) {}
358357

359358
assertThat(jobStatus).isNull();
360359
}
@@ -369,7 +368,7 @@ public void testPushSourceStrings_normal() {
369368
LocaleData.TxJobStatus jobStatus = null;
370369
try {
371370
jobStatus = cdsHandler.pushSourceStrings(postData);
372-
} catch (TimeLimitExceededException ignored) {}
371+
} catch (TimeoutException ignored) {}
373372

374373
assertThat(jobStatus).isNotNull();
375374

@@ -405,7 +404,7 @@ public void testPushSourceStrings_CDSRespondsWith409_returnNull() {
405404
LocaleData.TxJobStatus jobStatus = null;
406405
try {
407406
jobStatus = cdsHandler.pushSourceStrings(postData);
408-
} catch (TimeLimitExceededException ignored) {}
407+
} catch (TimeoutException ignored) {}
409408

410409

411410
assertThat(jobStatus).isNull();
@@ -421,7 +420,7 @@ public void testPushSourceStrings_CDSRespondsWithFailedJob_returnErrorInResponse
421420
LocaleData.TxJobStatus jobStatus = null;
422421
try {
423422
jobStatus = cdsHandler.pushSourceStrings(postData);
424-
} catch (TimeLimitExceededException ignored) {}
423+
} catch (TimeoutException ignored) {}
425424

426425
assertThat(jobStatus).isNotNull();
427426

0 commit comments

Comments
 (0)