androidx.test.espresso.idling.CountingIdlingResource Java Examples

The following examples show how to use androidx.test.espresso.idling.CountingIdlingResource. 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: IdlingTest.java    From android-test with Apache License 2.0 6 votes vote down vote up
public void register() throws Exception {
  resource = new CountingIdlingResource("counter");
  IdlingRegistry.getInstance().register(resource);
  IdlingUIActivity.listener =
      new IdlingUIActivity.Listener() {
        @Override
        public void onLoadStarted() {
          resource.increment();
        }

        @Override
        public void onLoadFinished() {
          resource.decrement();
        }
      };
}
 
Example #2
Source File: AdvancedSynchronizationTest.java    From android-test with Apache License 2.0 6 votes vote down vote up
@Before
public void setUp() throws Exception {
  ActivityScenario<SyncActivity> activityScenario = ActivityScenario.launch(SyncActivity.class);
  activityScenario.onActivity(
      activity -> {
        HelloWorldServer realServer = activity.getHelloWorldServer();
        // Here, we use CountingIdlingResource - a common convenience class - to track the idle
        // state of
        // the server. You could also do this yourself, by implementing the IdlingResource
        // interface.
        countingResource = new CountingIdlingResource("HelloWorldServerCalls");

        activity.setHelloWorldServer(new DecoratedHelloWorldServer(realServer, countingResource));
        assertTrue(registerIdlingResources(countingResource));
      });
}
 
Example #3
Source File: AdvancedSynchronizationTest.java    From android-test with Apache License 2.0 4 votes vote down vote up
private DecoratedHelloWorldServer(HelloWorldServer realHelloWorldServer,
    CountingIdlingResource helloWorldServerIdlingResource) {
  this.realHelloWorldServer = checkNotNull(realHelloWorldServer);
  this.helloWorldServerIdlingResource = checkNotNull(helloWorldServerIdlingResource);
}
 
Example #4
Source File: IdlingScheduledThreadPoolExecutor.java    From android-test with Apache License 2.0 3 votes vote down vote up
/**
 * Creates a new {@code IdlingScheduledThreadPoolExecutor} with the given initial parameters.
 *
 * @param resourceName the name of the executor (used for logging and idempotency of
 *     registration).
 * @param corePoolSize the number of threads to keep in the pool, even if they are idle, unless
 *     allowCoreThreadTimeOut is set.
 * @param threadFactory the factory to use when the executor creates a new thread.
 */
public IdlingScheduledThreadPoolExecutor(
    String resourceName, int corePoolSize, ThreadFactory threadFactory) {
  super(corePoolSize, threadFactory);
  countingIdlingResource = new CountingIdlingResource(resourceName);
  Log.i(LOG_TAG, "Register idling resource for scheduled thread pool " + resourceName);
  IdlingRegistry.getInstance().register(this);
}
 
Example #5
Source File: IdlingThreadPoolExecutor.java    From android-test with Apache License 2.0 3 votes vote down vote up
/**
 * Creates a new {@code IdlingThreadPoolExecutor} with the given initial parameters and default
 * rejected execution handler.
 *
 * @param resourceName the name of the executor (used for logging and idempotency of
 *     registration).
 * @param corePoolSize the number of threads to keep in the pool, even if they are idle, unless
 *     allowCoreThreadTimeOut is set.
 * @param maximumPoolSize the maximum number of threads to allow in the pool.
 * @param keepAliveTime when the number of threads is greater than the core, this is the maximum
 *     time that excess idle threads will wait for new tasks before terminating.
 * @param unit the time unit for the keepAliveTime argument.
 * @param workQueue the queue to use for holding tasks before they are executed. This queue will
 *     hold only the Runnable tasks submitted by the execute method.
 * @param threadFactory the factory to use when the executor creates a new thread.
 */
public IdlingThreadPoolExecutor(
    String resourceName,
    int corePoolSize,
    int maximumPoolSize,
    long keepAliveTime,
    TimeUnit unit,
    BlockingQueue<Runnable> workQueue,
    ThreadFactory threadFactory) {
  super(corePoolSize, maximumPoolSize, keepAliveTime, unit, workQueue, threadFactory);
  countingIdlingResource = new CountingIdlingResource(resourceName);
  Log.i(LOG_TAG, "Register idling resource for thread pool " + resourceName);
  IdlingRegistry.getInstance().register(this);
}