use of com.facebook.imagepipeline.testing.FakeClock in project fresco by facebook.
the class AnimatedDrawableCachingBackendImplTest method setup.
@Before
public void setup() {
mActivityManager = (ActivityManager) RuntimeEnvironment.application.getSystemService(Context.ACTIVITY_SERVICE);
mFakeClock = new FakeClock();
mExecutorService = new TestExecutorService(mFakeClock);
mAnimatedDrawableUtil = new AnimatedDrawableUtil();
mDrawableBackend = new TestAnimatedDrawableBackend(WIDTH, HEIGHT, FRAME_DURATIONS);
}
use of com.facebook.imagepipeline.testing.FakeClock in project fresco by facebook.
the class AnimatedSingleUsePostprocessorProducerTest method setUp.
@Before
public void setUp() {
MockitoAnnotations.initMocks(this);
mTestExecutorService = new TestExecutorService(new FakeClock());
mPostprocessorProducer = new PostprocessorProducer(mInputProducer, mPlatformBitmapFactory, mTestExecutorService);
when(mImageRequest.getPostprocessor()).thenReturn(mPostprocessor);
when(mProducerContext.getId()).thenReturn(mRequestId);
when(mProducerContext.getProducerListener()).thenReturn(mProducerListener);
when(mProducerContext.getImageRequest()).thenReturn(mImageRequest);
mResults = new ArrayList<>();
when(mPostprocessor.getName()).thenReturn(POSTPROCESSOR_NAME);
when(mProducerListener.requiresExtraMap(eq(mProducerContext), eq(POSTPROCESSOR_NAME))).thenReturn(true);
doAnswer(new Answer<Object>() {
@Override
public Object answer(InvocationOnMock invocation) throws Throwable {
mResults.add(((CloseableReference<CloseableImage>) invocation.getArguments()[0]).clone());
return null;
}
}).when(mConsumer).onNewResult(any(CloseableReference.class), anyInt());
mInOrder = inOrder(mPostprocessor, mProducerListener, mConsumer);
mSourceBitmap = mock(Bitmap.class);
mSourceCloseableStaticBitmap = mock(CloseableStaticBitmap.class);
when(mSourceCloseableStaticBitmap.getUnderlyingBitmap()).thenReturn(mSourceBitmap);
mSourceCloseableImageRef = CloseableReference.<CloseableImage>of(mSourceCloseableStaticBitmap);
mDestinationBitmap = mock(Bitmap.class);
mDestinationCloseableBitmapRef = CloseableReference.of(mDestinationBitmap, mBitmapResourceReleaser);
}
use of com.facebook.imagepipeline.testing.FakeClock in project fresco by facebook.
the class DiskStorageCacheTest method setUp.
@Before
public void setUp() {
mClock = mock(SystemClock.class);
PowerMockito.mockStatic(SystemClock.class);
PowerMockito.when(SystemClock.get()).thenReturn(mClock);
mBackgroundExecutor = new TestExecutorService(new FakeClock());
mDiskTrimmableRegistry = mock(DiskTrimmableRegistry.class);
mCacheEventListener = mock(CacheEventListener.class);
mCacheEventListenerInOrder = inOrder(mCacheEventListener);
// we know the directory will be this
mCacheDirectory = new File(RuntimeEnvironment.application.getCacheDir(), CACHE_TYPE);
mCacheDirectory.mkdirs();
if (!mCacheDirectory.exists()) {
throw new RuntimeException(String.format((Locale) null, "Cannot create cache dir: %s: directory %s", mCacheDirectory.getAbsolutePath(), mCacheDirectory.exists() ? "already exists" : "does not exist"));
}
mStorage = createDiskStorage(TESTCACHE_VERSION_START_OF_VERSIONING);
mCache = createDiskCache(mStorage, false);
mCache.clearAll();
reset(mCacheEventListener);
verify(mDiskTrimmableRegistry).registerDiskTrimmable(mCache);
}
use of com.facebook.imagepipeline.testing.FakeClock in project fresco by facebook.
the class LocalVideoThumbnailProducerTest method setUp.
@Before
public void setUp() throws Exception {
MockitoAnnotations.initMocks(this);
mExecutor = new TestExecutorService(new FakeClock());
mLocalVideoThumbnailProducer = new LocalVideoThumbnailProducer(mExecutor, RuntimeEnvironment.application.getContentResolver());
mFile = new File(RuntimeEnvironment.application.getExternalFilesDir(null), TEST_FILENAME);
mockStatic(ThumbnailUtils.class);
mProducerContext = new SettableProducerContext(mImageRequest, mRequestId, mProducerListener, mock(Object.class), ImageRequest.RequestLevel.FULL_FETCH, false, false, Priority.MEDIUM, mConfig);
when(mImageRequest.getSourceFile()).thenReturn(mFile);
mLocalVideoUri = Uri.parse("file:///dancing_hotdog.mp4");
}
use of com.facebook.imagepipeline.testing.FakeClock in project fresco by facebook.
the class PriorityNetworkFetcherTest method testNotMovingDelayedRequeue_requeueOnFail.
/**
* Scenario: an image fetch fails. We expect it to be re-queued up to maxNumberOfRequeue times.
* The reuqest should be re-queued immediately up to immediateRequeueCount and then it will wait
* in the delayedQueue to be re-queued again after delayTimeInMillis. In this test we make sure
* the request is not moved back to the priority queue unless delayTimeInMillis has passed.
*/
@Test
public void testNotMovingDelayedRequeue_requeueOnFail() {
RecordingNetworkFetcher recordingNetworkFetcher = new RecordingNetworkFetcher();
final int maxNumberOfRequeue = 3;
final int immediateRequeueCount = 1;
final int delayTimeInMillis = 300;
FakeClock clock = new FakeClock();
// Max hi-pri: 1, max low-pri: 0
PriorityNetworkFetcher<FetchState> fetcher = new PriorityNetworkFetcher<>(recordingNetworkFetcher, false, 1, 0, true, maxNumberOfRequeue, false, immediateRequeueCount, delayTimeInMillis, false, false, /* nonRecoverableExceptionPreventsRequeue */
1, /* maxConnectAttemptCount */
1, /* maxAttemptCount */
false, /* retryLowPriAll */
false, /* retryLowPriUnknownHostException */
false, /* retryLowPriConnectionException */
clock);
PriorityFetchState<FetchState> hipri1 = fetch(fetcher, "hipri1", callback, true);
assertThat(fetcher.getCurrentlyFetching()).containsExactly(hipri1);
assertThat(fetcher.getHiPriQueue()).isEmpty();
assertThat(fetcher.getLowPriQueue()).isEmpty();
// Simulate 1st failure in hipri1, the request should be requeued immediately.
getOnlyElement(recordingNetworkFetcher.callbacks.get(hipri1.delegatedState)).onFailure(new Exception());
assertThat(fetcher.getCurrentlyFetching()).containsExactly(hipri1);
assertThat(fetcher.getHiPriQueue()).isEmpty();
assertThat(fetcher.getLowPriQueue()).isEmpty();
assertThat(fetcher.getDelayedQeueue()).isEmpty();
assertThat(hipri1.requeueCount).isEqualTo(1);
assertThat(fetcher.getExtraMap(hipri1, 123)).containsEntry("delay_count", "0");
// Simulate 2nd failure in hipri1, the request should wait in the delayedQueue for
// delayTimeInMillis.
getOnlyElement(recordingNetworkFetcher.callbacks.get(hipri1.delegatedState)).onFailure(new Exception());
assertThat(fetcher.getCurrentlyFetching()).isEmpty();
assertThat(fetcher.getHiPriQueue()).isEmpty();
assertThat(fetcher.getLowPriQueue()).isEmpty();
assertThat(fetcher.getDelayedQeueue()).containsExactly(hipri1);
assertThat(fetcher.getExtraMap(hipri1, 123)).containsEntry("delay_count", "1");
clock.incrementBy(200);
// to trigger inflight requests
PriorityFetchState<FetchState> hipri2 = fetch(fetcher, "hipri2", callback, true);
// 200 ms is smaller than delayTimeInMillis, so hipri1 request should still wait in the
// delayedQueue.
assertThat(fetcher.getCurrentlyFetching()).containsExactly(hipri2);
assertThat(fetcher.getHiPriQueue()).isEmpty();
assertThat(fetcher.getLowPriQueue()).isEmpty();
assertThat(fetcher.getDelayedQeueue()).containsExactly(hipri1);
assertThat(hipri1.requeueCount).isEqualTo(2);
}
Aggregations