Java源码示例:androidx.test.espresso.idling.CountingIdlingResource
示例1
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();
}
};
}
示例2
@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));
});
}
示例3
private DecoratedHelloWorldServer(HelloWorldServer realHelloWorldServer,
CountingIdlingResource helloWorldServerIdlingResource) {
this.realHelloWorldServer = checkNotNull(realHelloWorldServer);
this.helloWorldServerIdlingResource = checkNotNull(helloWorldServerIdlingResource);
}
示例4
/**
* 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);
}
示例5
/**
* 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);
}