-
Notifications
You must be signed in to change notification settings - Fork 406
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
inject-utils: Move package private methods from PossiblyRetryable to …
…ExceptionUtils Problem The package private methods `PossiblyRetryable#isCancellation` and `PossibleRetryable#isNonRetryable` in inject-thrift are generally useful for processing interrupts on Futures. Making them publicly available allows users to not have to re-implement this logic (e.g., in the case they are attempting to mask cancellations on a Future). Solution Move the package private methods in `PossibleRetryable` in inject/inject-thrift to public methods in `ExceptionUtils` in inject/inject-utils. Result Less need for users to do this themselves (or hack around the visibility of these methods to call them). Differential Revision: https://phabricator.twitter.biz/D935287
- Loading branch information
Showing
9 changed files
with
105 additions
and
62 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
32 changes: 32 additions & 0 deletions
32
.../inject-utils/src/test/scala/com/twitter/inject/tests/exceptions/ExceptionUtilsTest.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
package com.twitter.inject.tests.exceptions | ||
|
||
import com.twitter.finagle.CancelledConnectionException | ||
import com.twitter.finagle.CancelledRequestException | ||
import com.twitter.finagle.Failure | ||
import com.twitter.finagle.FailureFlags | ||
import com.twitter.finagle.mux.ClientDiscardedRequestException | ||
import com.twitter.inject.Test | ||
import com.twitter.inject.utils.ExceptionUtils | ||
|
||
class ExceptionUtilsTest extends Test { | ||
|
||
test("test isCancellation") { | ||
assertIsCancellation(new CancelledRequestException) | ||
assertIsCancellation(new CancelledConnectionException(new Exception("cause"))) | ||
assertIsCancellation(new ClientDiscardedRequestException("cause")) | ||
assertIsCancellation(Failure("int", FailureFlags.Interrupted)) | ||
assertIsCancellation(Failure.rejected("", new CancelledRequestException)) | ||
} | ||
|
||
test("test isNonRetryable") { | ||
assertIsNonRetryable(Failure("int", FailureFlags.Ignorable)) | ||
} | ||
|
||
private def assertIsCancellation(e: Throwable): Unit = { | ||
ExceptionUtils.isCancellation(e) should be(true) | ||
} | ||
|
||
private def assertIsNonRetryable(e: Throwable): Unit = { | ||
ExceptionUtils.isNonRetryable(e) should be(true) | ||
} | ||
} |