use of com.facebook.imagepipeline.image.EncodedImage in project fresco by facebook.
the class JobSchedulerTest method testUpdate_Last.
@Test
public void testUpdate_Last() {
EncodedImage encodedImage = fakeEncodedImage();
assertTrue(mJobScheduler.updateJob(encodedImage, true));
assertNotSame(encodedImage, mJobScheduler.mEncodedImage);
assertReferencesEqual(encodedImage, mJobScheduler.mEncodedImage);
assertEquals(true, mJobScheduler.mIsLast);
assertEquals(0, mTestScheduledExecutorService.getPendingCount());
assertEquals(0, mTestExecutorService.getPendingCount());
assertEquals(0, mTestJobRunnable.jobs.size());
}
use of com.facebook.imagepipeline.image.EncodedImage in project fresco by facebook.
the class JobSchedulerTest method testSchedule_Last_Running_And_Pending.
@Test
public void testSchedule_Last_Running_And_Pending() {
EncodedImage encodedImage1 = fakeEncodedImage();
mJobScheduler.updateJob(encodedImage1, true);
assertTrue(mJobScheduler.scheduleJob());
final EncodedImage encodedImage2 = fakeEncodedImage();
final EncodedImage encodedImage3 = fakeEncodedImage();
Executors.newFixedThreadPool(1).execute(new Runnable() {
@Override
public void run() {
// wait until the job starts running
waitForCondition(mTestJobRunnable.running, true);
assertEquals(0, mTestScheduledExecutorService.getPendingCount());
assertEquals(0, mTestExecutorService.getPendingCount());
assertEquals(0, mTestJobRunnable.jobs.size());
mJobScheduler.updateJob(encodedImage2, true);
assertEquals(JobScheduler.JobState.RUNNING, mJobScheduler.mJobState);
assertTrue(mJobScheduler.scheduleJob());
assertEquals(JobScheduler.JobState.RUNNING_AND_PENDING, mJobScheduler.mJobState);
mJobScheduler.updateJob(encodedImage3, true);
assertEquals(JobScheduler.JobState.RUNNING_AND_PENDING, mJobScheduler.mJobState);
assertTrue(mJobScheduler.scheduleJob());
assertEquals(JobScheduler.JobState.RUNNING_AND_PENDING, mJobScheduler.mJobState);
mTestJobRunnable.wait.set(false);
}
});
// block running until the above code executed on another thread finishes
mTestJobRunnable.wait.set(true);
mFakeClockForTime.incrementBy(0);
mFakeClockForScheduled.incrementBy(0);
// this line blocks
mFakeClockForWorker.incrementBy(0);
assertEquals(JobScheduler.JobState.QUEUED, mJobScheduler.mJobState);
assertEquals(1, mTestScheduledExecutorService.getPendingCount());
assertEquals(0, mTestExecutorService.getPendingCount());
assertEquals(1, mTestJobRunnable.jobs.size());
assertJobsEqual(mTestJobRunnable.jobs.get(0), encodedImage1, true);
mFakeClockForTime.incrementBy(INTERVAL);
mFakeClockForScheduled.incrementBy(INTERVAL);
mFakeClockForWorker.incrementBy(INTERVAL);
assertEquals(JobScheduler.JobState.IDLE, mJobScheduler.mJobState);
assertEquals(0, mTestScheduledExecutorService.getPendingCount());
assertEquals(0, mTestExecutorService.getPendingCount());
assertEquals(2, mTestJobRunnable.jobs.size());
assertJobsEqual(mTestJobRunnable.jobs.get(1), encodedImage3, true);
}
use of com.facebook.imagepipeline.image.EncodedImage in project fresco by facebook.
the class LocalAssetFetchProducerTest method setUp.
@Before
public void setUp() throws Exception {
MockitoAnnotations.initMocks(this);
when(mAssetManager.openFd(eq(TEST_FILENAME))).thenReturn(mAssetFileDescriptor);
when(mAssetFileDescriptor.getLength()).thenReturn((long) TEST_DATA_LENGTH);
when(mPooledByteBufferFactory.newByteBuffer(any(InputStream.class), eq(TEST_DATA_LENGTH))).thenReturn(mPooledByteBuffer);
mExecutor = new TestExecutorService(new FakeClock());
mLocalAssetFetchProducer = new LocalAssetFetchProducer(mExecutor, mPooledByteBufferFactory, mAssetManager);
mProducerContext = new SettableProducerContext(mImageRequest, mRequestId, mProducerListener, mock(Object.class), ImageRequest.RequestLevel.FULL_FETCH, false, true, Priority.MEDIUM);
when(mImageRequest.getSourceUri()).thenReturn(Uri.parse("asset:///" + TEST_FILENAME));
doAnswer(new Answer() {
@Override
public Object answer(InvocationOnMock invocation) throws Throwable {
mCapturedEncodedImage = EncodedImage.cloneOrNull((EncodedImage) invocation.getArguments()[0]);
return null;
}
}).when(mConsumer).onNewResult(notNull(EncodedImage.class), anyBoolean());
}
use of com.facebook.imagepipeline.image.EncodedImage in project fresco by facebook.
the class BranchOnSeparateImagesProducerTest method testFirstProducerReturnsTwoResultsThumbnailsNotAllowed.
@Test
public void testFirstProducerReturnsTwoResultsThumbnailsNotAllowed() {
when(mImageRequest.getLocalThumbnailPreviewsEnabled()).thenReturn(false);
EncodedImage intermediateEncodedImage = new EncodedImage(mIntermediateResult.getByteBufferRef());
intermediateEncodedImage.setImageFormat(DefaultImageFormats.JPEG);
intermediateEncodedImage.setRotationAngle(-1);
intermediateEncodedImage.setWidth(WIDTH / 2);
intermediateEncodedImage.setHeight(HEIGHT / 2);
mFirstProducerConsumer.onNewResult(intermediateEncodedImage, false);
verify(mConsumer, never()).onNewResult(intermediateEncodedImage, false);
EncodedImage finalEncodedImage = new EncodedImage(mFirstProducerFinalResult.getByteBufferRef());
finalEncodedImage.setImageFormat(DefaultImageFormats.JPEG);
finalEncodedImage.setRotationAngle(-1);
finalEncodedImage.setWidth(WIDTH);
finalEncodedImage.setHeight(HEIGHT);
mFirstProducerConsumer.onNewResult(finalEncodedImage, true);
verify(mConsumer).onNewResult(finalEncodedImage, true);
verify(mInputProducer2, never()).produceResults(any(Consumer.class), eq(mProducerContext));
}
use of com.facebook.imagepipeline.image.EncodedImage in project fresco by facebook.
the class BranchOnSeparateImagesProducerTest method testFirstProducerReturnsIntermediateResultThenGoodEnoughResult.
@Test
public void testFirstProducerReturnsIntermediateResultThenGoodEnoughResult() {
EncodedImage intermediateEncodedImage = new EncodedImage(mIntermediateResult.getByteBufferRef());
intermediateEncodedImage.setImageFormat(DefaultImageFormats.JPEG);
intermediateEncodedImage.setRotationAngle(-1);
intermediateEncodedImage.setWidth(WIDTH);
intermediateEncodedImage.setHeight(HEIGHT);
mFirstProducerConsumer.onNewResult(intermediateEncodedImage, false);
verify(mConsumer).onNewResult(intermediateEncodedImage, false);
EncodedImage finalEncodedImage = new EncodedImage(mFirstProducerFinalResult.getByteBufferRef());
finalEncodedImage.setImageFormat(DefaultImageFormats.JPEG);
finalEncodedImage.setRotationAngle(-1);
finalEncodedImage.setWidth(WIDTH);
finalEncodedImage.setHeight(HEIGHT);
mFirstProducerConsumer.onNewResult(finalEncodedImage, true);
verify(mConsumer).onNewResult(finalEncodedImage, true);
verify(mInputProducer2, never()).produceResults(any(Consumer.class), eq(mProducerContext));
}
Aggregations