CTS Framework Parsing (6)-Execution of tasks

Source: Internet
Author: User
Tags thread

The first two discussed the task's addition and the 9 major configurations, this is about the execution of the task.


Execution of tasks


The execution of the task is in the Commandscheduler run method, so delete all breakpoints, break the breakpoint in the Run method, and restart debug:




Look at the first line of code below the while loop


Executablecommand cmd = Dequeueconfigcommand ();

Private Executablecommand Dequeueconfigcommand () {
        try {
            //poll for a command, rather than block indefinitely, to Handle shutdown Case
            return Mcommandqueue.poll (Getcommandpolltimems (), timeunit.milliseconds);
        } catch ( Interruptedexception e) {
            clog.i ("Waiting for Command Interrupted");
        }
        return null;
    }

Remove the first object from the queue. Returns null if there are no elements in the queue. When returned, if NULL is determined in the while, the call ends again.


Executablecommand cmd = Dequeueconfigcommand ();


Until CMD is not null. So in


Ideviceselection options = Cmd.getconfiguration (). getdevicerequirements ();


Hit the breakpoint, press F8, the program will enter the above code when CMD is not null, stop.




First obtain the system equipment requirements, according to the requirements, determine whether there is a device to meet the requirements and assign the device.



Native requirements for a S/n number, Ddms assigns a idevice based on the SN number, and the CTS is then packaged as Itestdevice object idevice. Then start the real startup task based on Itestdevice,idevicemanager and Executablecommand. We are not in a hurry to discuss the process of execution, but continue to look down:


Addinvocationthread (invthread);
if (Cmd.isloopmode ()) {
    addnewexeccommandtoqueue (Cmd.getcommandtracker ());
}

The executing thread is first stored in the set and then placed again in the task queue in order to be able to loop through the task. If a successful itestdevice is not assigned according to the SN number, it will be tried again and discarded if the device is not found within the specified time. Finally do some teardown operations, and then save the log in the case run to the file. Even if it's done.


Now look back at what's going on in the thread that performs the task:


Private Invocationthread startinvocation (Idevicemanager Manager, Itestdevice device,
            executablecommand cmd) {
        final String invocationname = String.Format ("invocation-%s", Device.getserialnumber ());
        Invocationthread invocationthread = new Invocationthread (invocationname, manager, device,
                cmd);
        Invocationthread.start ();
        return invocationthread;
    }

Invocationthread is the Commandscheduler private inner class, inherited from the thread, which belongs to the thread in which the thread is started. So it's OK to look directly at Invocationthread's Run method. The Invoke method for Itestinvocation is called in the Run method:




The incoming objects are Itestdevice, IConfiguration, Irescheduler, respectively. The first two are already involved, what is the last Irescheduler. See for yourself, it doesn't make any sense. This task of the previous work has been done, the program to the Testinvocation invoke method. In the next article, because it is important, it is equivalent to a control room function.


Summary


Wrote 6 articles summarizing the process of some CTS.


The start point of the task is to accept the arguments on the command line, and if you decide to perform the CTS task, the thread that adds the command task is started in the Console.run method argrunnable<capturelist> and the thread performing the task Commandscheduler. Adding a task thread argrunnable<capturelist> calls the Commandscheduler object method AddCommand to Conditionpriorityblockingqueue<executablecommand> (with FIFO queue) This queue is added, and the task thread is executed Commandscheduler by calling its own private method, Dequeueconfigcommand.

conditionpriorityblockingqueue<executablecommand> to fetch the executable task, take the first one at a time. Then call invocationthread This thread to perform the task. Invocationthread This thread calls the Testinvocation.invoke method to perform the task.


You see, it's really simple.







Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.