Java Code Examples for com.facebook.common.executors.CallerThreadExecutor#getInstance()

The following examples show how to use com.facebook.common.executors.CallerThreadExecutor#getInstance() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: DataSourceTestUtils.java    From fresco with MIT License 6 votes vote down vote up
public void setUp() {
  mSrc1 = mock(DataSource.class);
  mSrc2 = mock(DataSource.class);
  mSrc3 = mock(DataSource.class);
  mDataSourceSupplier1 = mock(Supplier.class);
  mDataSourceSupplier2 = mock(Supplier.class);
  mDataSourceSupplier3 = mock(Supplier.class);
  when(mDataSourceSupplier1.get()).thenReturn(mSrc1);
  when(mDataSourceSupplier2.get()).thenReturn(mSrc2);
  when(mDataSourceSupplier3.get()).thenReturn(mSrc3);
  mDataSubscriber = mock(DataSubscriber.class);
  mExecutor = CallerThreadExecutor.getInstance();
  mInOrder =
      inOrder(
          mSrc1,
          mSrc2,
          mSrc3,
          mDataSourceSupplier1,
          mDataSourceSupplier2,
          mDataSourceSupplier3,
          mDataSubscriber);
  mSuppliers = Arrays.asList(mDataSourceSupplier1, mDataSourceSupplier2, mDataSourceSupplier3);
}
 
Example 2
Source File: PriorityStarvingThrottlingProducerTest.java    From fresco with MIT License 6 votes vote down vote up
@Before
public void setUp() {
  MockitoAnnotations.initMocks(this);
  mThrottlingProducer =
      new PriorityStarvingThrottlingProducer<>(
          MAX_SIMULTANEOUS_REQUESTS, CallerThreadExecutor.getInstance(), mInputProducer);
  for (int i = 0; i < 7; i++) {
    mConsumers[i] = mock(Consumer.class);
    mProducerContexts[i] = mock(ProducerContext.class);
    mProducerListeners[i] = mock(ProducerListener2.class);
    mResults[i] = mock(Object.class);
    when(mProducerContexts[i].getProducerListener()).thenReturn(mProducerListeners[i]);
    when(mProducerContexts[i].getId()).thenReturn(mRequestIds[i]);
    final int iFinal = i;
    doAnswer(
            new Answer() {
              @Override
              public Object answer(InvocationOnMock invocation) throws Throwable {
                mThrottlerConsumers[iFinal] = (Consumer<Object>) invocation.getArguments()[0];
                return null;
              }
            })
        .when(mInputProducer)
        .produceResults(any(Consumer.class), eq(mProducerContexts[i]));
  }
}
 
Example 3
Source File: ThrottlingProducerTest.java    From fresco with MIT License 6 votes vote down vote up
@Before
public void setUp() {
  MockitoAnnotations.initMocks(this);
  mThrottlingProducer =
      new ThrottlingProducer<Object>(
          MAX_SIMULTANEOUS_REQUESTS, CallerThreadExecutor.getInstance(), mInputProducer);
  for (int i = 0; i < 5; i++) {
    mConsumers[i] = mock(Consumer.class);
    mProducerContexts[i] = mock(ProducerContext.class);
    mProducerListeners[i] = mock(ProducerListener2.class);
    mResults[i] = mock(Object.class);
    when(mProducerContexts[i].getProducerListener()).thenReturn(mProducerListeners[i]);
    when(mProducerContexts[i].getId()).thenReturn(mRequestIds[i]);
    final int iFinal = i;
    doAnswer(
            new Answer() {
              @Override
              public Object answer(InvocationOnMock invocation) throws Throwable {
                mThrottlerConsumers[iFinal] = (Consumer<Object>) invocation.getArguments()[0];
                return null;
              }
            })
        .when(mInputProducer)
        .produceResults(any(Consumer.class), eq(mProducerContexts[i]));
  }
}
 
Example 4
Source File: AbstractDraweeControllerTest.java    From fresco with MIT License 6 votes vote down vote up
@Before
public void setUp() {
  mDeferredReleaser = mock(DeferredReleaser.class);
  mCallerContext = mock(Object.class);
  mDataSourceSupplier = mock(Supplier.class);
  mDraweeHierarchy = mock(SettableDraweeHierarchy.class);
  mUiThreadExecutor = CallerThreadExecutor.getInstance();
  mController =
      new FakeDraweeController(
          mDeferredReleaser, mUiThreadExecutor, mDataSourceSupplier, "id", mCallerContext);
  doAnswer(
          new Answer<Object>() {
            @Override
            public Object answer(InvocationOnMock invocation) throws Throwable {
              ((DeferredReleaser.Releasable) invocation.getArguments()[0]).release();
              return null;
            }
          })
      .when(mDeferredReleaser)
      .scheduleDeferredRelease(any(DeferredReleaser.Releasable.class));
  when(mDataSourceSupplier.get()).thenReturn(SimpleDataSource.<FakeImage>create());
}
 
Example 5
Source File: DataFetchProducer.java    From fresco with MIT License 4 votes vote down vote up
public DataFetchProducer(PooledByteBufferFactory pooledByteBufferFactory) {
  super(CallerThreadExecutor.getInstance(), pooledByteBufferFactory);
}