5th Chapter 6 "Monkeyrunner Source code Analysis" Monkey principle-Start run: Initialize event source (original)

Source: Internet
Author: User

Heaven Zhuhai Branch Rudder note : Originally this series is to prepare a book, details please see the earlier blog "to seek partners to write the deep understanding of Monkeyrunner" books. But for many reasons, there is no wish. So the draft is shared here, so mistakes are unavoidable. If necessary, please refer to the following, the forwarding of the word also keep the end of each article source and other information.

The event source represents where the command event data to inject the system came from. In this section we do not have an in-depth analysis of the implementation of the event source, because the next chapter will do it. It is enough to have a basic idea of the source of events here.

For monkey, the source of the event can be multiple places, such as when we use it for random stress tests by the monkey itself, or as part of the Monkeyrunner testing framework from USB/TCP command, here we usb/ The source of the event TCP comes from is collectively known as the network event source. Different event sources will have different classes to do the corresponding implementations:

    • monkeysourcenetwork: The event is from the network Monkeyrunner client, dealing with the interface control operations related events, such as press, etc.

    • monkeysourcenetworkvars: The event is also from the network, such as Monkeyrunner, processing is to get the system properties of this GetProperties event

    • monkeysourcenetworkviews: Events are also from the network such as Monkeyrunner, dealing with control-related events

    • monkeysourcerandom: Event is a set of random events generated from within Monkey, which is the common way we launch Monkey test target app from the command line

    • Monkeysourcerandomscript: The above random internal data source can also be created by specifying the setup script

    • monkeysourcescript: Users can also follow certain rules to write monkey scripts to drive monkey to carry out related tests, unlike the above is that it is no longer random

The previous three event sources are related to our Monkeyrunner framework, and we'll analyze them in detail in the next chapter, where we just need to know that these event sources represent the different sources of the event, and then basically deal with the following two things:

    • Gets the event from the specified source

    • Translate the command into a monkey event and put it in the command queue, all events from the event source are managed by command queue, and when the event is generated, it is placed in the queue and the event is removed from the command queue when the event is processed.

Then we continue to analyze the monkey class of the Run method, to understand how the next monkey in the START process is to initialize the different event sources according to different situations.

Code 5-6-1 Monkey-run Initializing event source

 425     /** 426 * Run the command! 427 * 428 * @param args the command-line arguments 429 * @ Return Returns A posix-style result code. 0 for no error. 430 * * 431     Private int Run(string[] args) {    ...//Omit other event source initialization code 514}Else if(Mserverport! =-1) {515             Try{516Meventsource =NewMonkeysourcenetwork (Mserverport);517}Catch(IOException e) {518System.out.println ("Error binding to network socket.");519                 return-5;520}    ...}

The function of a large piece of code omitted in front of the run method is simply to initialize different event sources according to different situations, for example, if you specify "-F ScriptFile" When you start Monkey and you specify a script file, Then initialize the source of the Monkeysourcescript event. But these are not really important here, because they do not have much to do with monkey as a Monkeyrunner service, Monkeyrunner start monkey Use the command is "Monkey-port 12345". So the real focus here is the code of the 第514-516 line, if the monkey is started by specifying the "-port" parameter, the initialization is monkeysourcenetwork this event source, specifically used to get events from the network.

Perhaps everyone here will be questioned, the network to the source of the event is not also monkeysourcenetworkviews and monkeysourcenetworkvars it? Why don't you see it here? In fact, these two classes provide mainly static methods, there is no need to initialize, when the monkeysourcenetwork need to use them in the internal call their methods.

——— to Be Continued ———

Heaven Zhuhai Branch Rudder
Public Number: Techgogogo
Weibo: Http://weibo.com/techgogogo
Csdn:http://blog.csdn.net/zhubaitian

5th Chapter 6 "Monkeyrunner Source code Analysis" Monkey principle-Start run: Initialize event source (original)

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.