提交 9df9953e 编写于 作者: S Sam Judd

Don't notify jobs of failures decoding from cache.

Since we also try to reload the image from source,
we may end up reporting first a failure and then
a success which would leave the request in an
undefined state.
上级 14fee20d
......@@ -179,7 +179,7 @@ public class ResourceRunnerTest {
}
@Test
public void testNotifiesJobOfFailureIfCacheLoaderThrows() {
public void testSubmitsSourceRunnerIfCacheLoaderThrows() {
final Exception exception = new IOException("test");
when(harness.cacheLoader.load(any(Key.class), any(ResourceDecoder.class), anyInt(), anyInt())).thenAnswer(
new Answer<Object>() {
......@@ -189,11 +189,12 @@ public class ResourceRunnerTest {
}
});
harness.runner.run();
verify(harness.engineJob).onException(eq(exception));
verify(harness.resizeService).submit(eq(harness.sourceRunner));
}
@Test
public void testNotifiesJobOfFailureIfTransformationThrows() {
public void testSubmitsSourceRunnerIfTransformationThrows() {
final Exception exception = new RuntimeException("test");
when(harness.tranformation.transform(any(Resource.class), anyInt(), anyInt())).thenAnswer(new Answer<Object>() {
@Override
......@@ -202,11 +203,11 @@ public class ResourceRunnerTest {
}
});
harness.runner.run();
verify(harness.engineJob).onException(eq(exception));
verify(harness.resizeService).submit(eq(harness.sourceRunner));
}
@Test
public void testNotifiesJobOfFailureIfTranscoderThrows() {
public void testSubmitsSourceRunnerIfTranscoderThrows() {
final Exception exception = new RuntimeException("test");
when(harness.transcoder.transcode(any(Resource.class))).thenAnswer(new Answer<Object>() {
@Override
......@@ -215,7 +216,7 @@ public class ResourceRunnerTest {
}
});
harness.runner.run();
verify(harness.engineJob).onException(eq(exception));
verify(harness.resizeService).submit(eq(harness.sourceRunner));
}
@Test
......@@ -232,6 +233,15 @@ public class ResourceRunnerTest {
verify(harness.engineJob).onException(eq(exception));
}
@Test
public void testDoesNotNotifyJobOfFailureIfDecodingFromCacheThrows() {
when(harness.cacheLoader.load(any(Key.class), any(ResourceDecoder.class), anyInt(), anyInt()))
.thenThrow(new RuntimeException("test"));
harness.runner.run();
verify(harness.engineJob, never()).onException(any(Exception.class));
}
@SuppressWarnings("unchecked")
private static class ResourceRunnerHarness {
EngineKey key = mock(EngineKey.class);
......
......@@ -83,8 +83,11 @@ class ResourceRunner<Z, R> implements Runnable, Prioritized {
try {
result = runWrapped();
} catch (Exception e) {
job.onException(e);
if (Log.isLoggable(TAG, Log.DEBUG)) {
Log.d(TAG, "Failed to decode resource from cache", e);
}
}
if (result != null) {
job.onResourceReady(result);
} else {
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册