mirror of
https://github.com/samsonjs/media.git
synced 2026-04-27 15:07:40 +00:00
Don't use transformationResult with timeout/unexpected exceptions.
PiperOrigin-RevId: 503187291
This commit is contained in:
parent
280889bc4a
commit
306ce6e3a1
1 changed files with 21 additions and 20 deletions
|
|
@ -211,7 +211,10 @@ public class TransformerAndroidTestRunner {
|
||||||
throw transformationTestResult.analysisException;
|
throw transformationTestResult.analysisException;
|
||||||
}
|
}
|
||||||
return transformationTestResult;
|
return transformationTestResult;
|
||||||
} catch (UnsupportedOperationException | InterruptedException | IOException e) {
|
} catch (InterruptedException
|
||||||
|
| IOException
|
||||||
|
| TimeoutException
|
||||||
|
| UnsupportedOperationException e) {
|
||||||
resultJson.put(
|
resultJson.put(
|
||||||
"transformationResult",
|
"transformationResult",
|
||||||
new JSONObject().put("testException", AndroidTestUtil.exceptionAsJsonObject(e)));
|
new JSONObject().put("testException", AndroidTestUtil.exceptionAsJsonObject(e)));
|
||||||
|
|
@ -227,12 +230,16 @@ public class TransformerAndroidTestRunner {
|
||||||
* @param testId An identifier for the test.
|
* @param testId An identifier for the test.
|
||||||
* @param editedMediaItem The {@link EditedMediaItem} to transform.
|
* @param editedMediaItem The {@link EditedMediaItem} to transform.
|
||||||
* @return The {@link TransformationTestResult}.
|
* @return The {@link TransformationTestResult}.
|
||||||
|
* @throws IllegalStateException See {@link Transformer#startTransformation(EditedMediaItem,
|
||||||
|
* String)}.
|
||||||
* @throws InterruptedException If the thread is interrupted whilst waiting for transformer to
|
* @throws InterruptedException If the thread is interrupted whilst waiting for transformer to
|
||||||
* complete.
|
* complete.
|
||||||
* @throws IOException If an error occurs opening the output file for writing.
|
* @throws IOException If an error occurs opening the output file for writing.
|
||||||
|
* @throws TimeoutException If the transformation has not completed after {@linkplain
|
||||||
|
* Builder#setTimeoutSeconds(int) the given timeout}.
|
||||||
*/
|
*/
|
||||||
private TransformationTestResult runInternal(String testId, EditedMediaItem editedMediaItem)
|
private TransformationTestResult runInternal(String testId, EditedMediaItem editedMediaItem)
|
||||||
throws InterruptedException, IOException {
|
throws InterruptedException, IOException, TimeoutException {
|
||||||
MediaItem mediaItem = editedMediaItem.mediaItem;
|
MediaItem mediaItem = editedMediaItem.mediaItem;
|
||||||
if (!mediaItem.clippingConfiguration.equals(MediaItem.ClippingConfiguration.UNSET)
|
if (!mediaItem.clippingConfiguration.equals(MediaItem.ClippingConfiguration.UNSET)
|
||||||
&& requestCalculateSsim) {
|
&& requestCalculateSsim) {
|
||||||
|
|
@ -319,31 +326,25 @@ public class TransformerAndroidTestRunner {
|
||||||
});
|
});
|
||||||
|
|
||||||
// Block here until timeout reached or latch is counted down.
|
// Block here until timeout reached or latch is counted down.
|
||||||
boolean timeoutReached = !countDownLatch.await(timeoutSeconds, SECONDS);
|
if (!countDownLatch.await(timeoutSeconds, SECONDS)) {
|
||||||
long elapsedTimeMs = SystemClock.DEFAULT.elapsedRealtime() - startTimeMs;
|
throw new TimeoutException("Transformer timed out after " + timeoutSeconds + " seconds.");
|
||||||
|
}
|
||||||
@Nullable FallbackDetails fallbackDetails = fallbackDetailsReference.get();
|
|
||||||
@Nullable Exception unexpectedException = unexpectedExceptionReference.get();
|
@Nullable Exception unexpectedException = unexpectedExceptionReference.get();
|
||||||
|
if (unexpectedException != null) {
|
||||||
|
throw new IllegalStateException(
|
||||||
|
"Unexpected exception starting the transformer.", unexpectedException);
|
||||||
|
}
|
||||||
|
|
||||||
|
long elapsedTimeMs = SystemClock.DEFAULT.elapsedRealtime() - startTimeMs;
|
||||||
|
@Nullable FallbackDetails fallbackDetails = fallbackDetailsReference.get();
|
||||||
@Nullable
|
@Nullable
|
||||||
TransformationException transformationException = transformationExceptionReference.get();
|
TransformationException transformationException = transformationExceptionReference.get();
|
||||||
|
|
||||||
@Nullable Exception testException = null;
|
if (transformationException != null) {
|
||||||
if (timeoutReached) {
|
|
||||||
testException =
|
|
||||||
new TimeoutException("Transformer timed out after " + timeoutSeconds + " seconds.");
|
|
||||||
} else if (unexpectedException != null) {
|
|
||||||
testException =
|
|
||||||
new IllegalStateException(
|
|
||||||
"Unexpected exception starting the transformer.", unexpectedException);
|
|
||||||
} else if (transformationException != null) {
|
|
||||||
testException = transformationException;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (testException != null) {
|
|
||||||
return new TransformationTestResult.Builder(checkNotNull(transformationResultReference.get()))
|
return new TransformationTestResult.Builder(checkNotNull(transformationResultReference.get()))
|
||||||
.setElapsedTimeMs(elapsedTimeMs)
|
.setElapsedTimeMs(elapsedTimeMs)
|
||||||
.setFallbackDetails(fallbackDetails)
|
.setFallbackDetails(fallbackDetails)
|
||||||
.setTestException(testException)
|
.setTestException(transformationException)
|
||||||
.build();
|
.build();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue