1 /*
2  * Copyright (C) 2016 The Android Open Source Project
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 package com.android.incallui.async;
18 
19 import java.util.concurrent.Executor;
20 
21 /**
22  * Executor that can be used to easily synchronize testing and production code. Production code
23  * should call {@link #milestone()} at points in the code where the state of the system is worthy of
24  * testing. In a test scenario, this method will pause execution until the test acknowledges the
25  * milestone through the use of {@link #ackMilestoneForTesting()}.
26  */
27 public interface PausableExecutor extends Executor {
28 
29   /**
30    * Method called from asynchronous production code to inform this executor that it has reached a
31    * point that puts the system into a state worth testing. TestableExecutors intended for use in a
32    * testing environment should cause the calling thread to block. In the production environment
33    * this should be a no-op.
34    */
milestone()35   void milestone();
36 
37   /**
38    * Method called from the test code to inform this executor that the state of the production
39    * system at the current milestone has been sufficiently tested. Every milestone must be
40    * acknowledged.
41    */
ackMilestoneForTesting()42   void ackMilestoneForTesting();
43 
44   /**
45    * Method called from the test code to inform this executor that the tests are finished with all
46    * milestones. Future calls to {@link #milestone()} or {@link #awaitMilestoneForTesting()} should
47    * return immediately.
48    */
ackAllMilestonesForTesting()49   void ackAllMilestonesForTesting();
50 
51   /**
52    * Method called from the test code to block until a milestone has been reached in the production
53    * code.
54    */
awaitMilestoneForTesting()55   void awaitMilestoneForTesting() throws InterruptedException;
56 }
57