Build and Test in the Cloud

3,588 views
3,531 views

Published on

Build And Test In The Cloud
JavaGruppen 2011 Denmark
http://www.carlossanchez.eu

Building and testing software can be a time- and resource-consuming
task. Cloud computing/on-demand services such as Amazon EC2 provide a
cost-effective way to scale applications and, for building and testing
software, can reduce the time needed to find and correct problems,
meaning a cost reduction as well.

Properly configuring your build tools (Maven, Ant,...), continuous
integration servers (Continuum, Hudson, Cruise Control,...), and
testing tools (TestNG, Selenium,...) can enable you to run all the
building/testing process in a cloud environment, simulating high-load
environments, distributing long-running tests to reduce their
execution time, using different environments for client or server
applications, and so on—and in the case of on-demand services such as
Amazon EC2, pay only for the time you use it.

In this presentation we will introduce a development process and
architecture using popular open source tools for the build and test
process such as Apache Maven or Ant for building, Apache Continuum as
continuous integration server with distributed capabilities, TestNG
and Selenium for parallel, distributed and load testing, and how to
configure them to achieve the best results and performance in several
typical use cases (long running testing processes, different
environments, different client platforms,...) by using he Amazon
Elastic Computing Cloud EC2, and therefore reducing time and costs
compared to other solutions.

Published in: Technology, Business
1 Comment
1 Like
Statistics
Notes
No Downloads
Views
Total views
3,588
On SlideShare
0
From Embeds
0
Number of Embeds
13
Actions
Shares
0
Downloads
0
Comments
1
Likes
1
Embeds 0
No embeds

No notes for slide
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • 35\n
  • 35\n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • Build and Test in the Cloud

    1. 1. Build and Testin the CloudCarlos SanchezMaestroDev
    2. 2. Hej!Solutions Architect atMaestroDevMember of ApacheSoftware FoundationMaven PMC, Continuum,ArchivaEclipse IAM co-leadetc...
    3. 3. Index The tools why the Cloud? Distributed building Maven integration tests Maven & SeleniumTesting in different environments And now in the cloud
    4. 4. The tools
    5. 5. Build: Apache Maven Build tool and more Dependency managementExecution of unit/integration tests Start/stop application serverAutomatic application deployment
    6. 6. Test Cases: TestNG Unit/integration tests parameterized tests parallel testing
    7. 7. Integration Tests: Selenium UI and Integration testing Tests run in the browser support for multiple browsers Tests can be recordedno need for developers writing tests Selenium IDE Firefox plugin
    8. 8. Continuous Integration: Apache Continuum Tight integration with Apache Maven dependency handling Trigger builds when integration tests change when the webapp changes when the webapp dependencies change Distributed building
    9. 9. Cloud Computing: Amazon Web Services Amazon S3 storage Amazon SQS queue service Amazon Mechanical Turk manpower Amazon EC2 computation
    10. 10. why the cloud?
    11. 11. $$$ Machines cost money Bandwidth costs money Electricity costs moneyServer administration costs money
    12. 12. Resource Optimization build servers can be repurposedtest servers working 10-20% of the time ability to do expensive builds/tests for a short amount of time
    13. 13. Predictions cost moneyInfrastructure Cost $ time Source: Amazon
    14. 14. Predictions cost moneyInfrastructure Cost $ Predicted Demand time Source: Amazon
    15. 15. Predictions cost moneyInfrastructure Cost $ Predicted Demand Traditional Hardware time Source: Amazon
    16. 16. Predictions cost moneyInfrastructure Cost $ Large Capital Expenditure Predicted Demand Traditional Hardware time Source: Amazon
    17. 17. Predictions cost moneyInfrastructure Cost $ Predicted Demand Traditional Hardware time Source: Amazon
    18. 18. Predictions cost moneyInfrastructure Cost $ Predicted Demand Traditional Hardware Actual Demand time Source: Amazon
    19. 19. Predictions cost moneyInfrastructure Cost $ Predicted Demand Opportunity Traditional Cost Hardware Actual Demand time Source: Amazon
    20. 20. Predictions cost moneyInfrastructure Cost $ You just lost customers Predicted Demand Opportunity Traditional Cost Hardware Actual Demand time Source: Amazon
    21. 21. Predictions cost moneyInfrastructure Cost $ Predicted Demand Traditional Hardware Actual Demand Automated Virtualization time Source: Amazon
    22. 22. AvailabilityCan you get 3000 machines in 3 days?
    23. 23. Amazon EC2Elastic Compute CloudMachines on demand
    24. 24. Amazon EC2pay per hoursame price for10 machines / 1 hour1 machine / 10 hoursunlimited number ofmachinesstart in couple minutes
    25. 25. AMIs
    26. 26. AMIsAmazon Machine Images
    27. 27. AMIsAmazon Machine Images Bundle your own
    28. 28. Distributed building
    29. 29. Credits: XKCD
    30. 30. ContinuumMaster Continuum server Centralized management Builds, users, output,... Can build tooDistributed build agents distribute load different environmentsdifferent networks/clouds
    31. 31. Distributed builds CouplingMaven dependencies determine parallelism Environments OS, JDK, installed libraries... VM size
    32. 32. Configuration Use properties Allow customizing environments -Djetty.port=8081-Dweb.host=184.73.250.39
    33. 33. ConfigurationUse settings.xml <settings>For user / agents <profiles>configuration <profile> <id>acme</id> <activation> <activeByDefault>true</activeByDefault> </activation> <properties> <jetty.port>8081</jetty.port> <web.host>184.73.250.39</web.host> </properties> </profile> </profiles> </settings>
    34. 34. Build agents in the cloud Startup Automatically start with instance APIAuto-connect to master when instance starts ie. using user-data on EC2
    35. 35. Starting more agents Not worth at build time Instance startup time Pay for full hours Use a poolKeep a minimum number of instances in pool Start/Stop more as needed
    36. 36. Maven EC2 pluginhttp://mojo.codehaus.org/maven-ec2-plugin start Amazon AMIs stop at the end of the build pass on user data
    37. 37. Multicloud APIs Java - JClouds http://code.google.com/p/jclouds/ Python (+ Java) - libcloudhttp://incubator.apache.org/libcloud/
    38. 38. Provisioning DevOps! Puppet / ChefManage instances automagically
    39. 39. class buildagent { $path="/usr/bin:/usr/sbin:/bin:/sbin" # Java 6 package { jdk: ensure => "1.6.0_23-fcs", require => Class[yum], } # Builder user{ "builder": name => builder, ensure => present, home => "/home/builder", managehome => true, shell => "/bin/bash", } # Builder Agent packages $builder_agent_packages = ["maven", "continuum-buildagent", "subversion","xorg-x11-server-Xvfb", "xorg-x11-server-utils"] package { $builder_agent_packages: ensure => latest, require => [Package[jdk]] }
    40. 40. package { firefox: ensure => latest,#["3.6.9", "3.0.19"], require => Class[yum]}$settings_xml = "/home/builder/.m2/settings.xml"file { "/home/builder/.m2": owner => "builder", group => "builder", mode => "0600", ensure => directory, require => User["builder"],}file { $settings_xml : owner => "builder", group => "builder", mode => "0600", content => template("builder/settings.xml.erb"), require => File["/home/builder/.m2"],}service { continuum-buildagent : enable => true, ensure => running, hasstatus => true, hasrestart => true, require => [Package[continuum-buildagent], File[$settings_xml]]}
    41. 41. Fear of change Affects behaviorability of doing things that could not be done before but requires new knowledge too Embrace change!
    42. 42. Maven integration tests
    43. 43. The webapp to testApache Maven 2Effective Implementation Centrepoint sample webapp
    44. 44. A new Maven projectCentrepointselenium-tests <groupId>com.effectivemaven.centrepoint</groupId> <artifactId>selenium-tests</artifactId> <version>1.0-SNAPSHOT</version> <name>Centrepoint Selenium Test Suite</name>
    45. 45. that depends onCentrepoint webapp <dependency> <groupId>com.effectivemaven.centrepoint</groupId> <artifactId>webapp</artifactId> <version>${project.version}</version> <type>war</type> </dependency>
    46. 46. using Jetty plugin to run itautomatically <plugin> <groupId>org.mortbay.jetty</groupId> <artifactId>maven-jetty-plugin</artifactId>
    47. 47. Record Selenium testsSeleniumIDE
    48. 48. as Java
    49. 49. test casesusing Selenium API public void setUp() throws Exception { setUp("http://localhost:18880/", "*chrome"); } public void testNew() throws Exception { selenium.open("/mainMenu.html"); selenium.click("link=Administration"); selenium.waitForPageToLoad("30000"); selenium.type("j_password", "admin"); selenium.click("rememberMe"); selenium.click("//input[@name=login]"); selenium.waitForPageToLoad("30000"); selenium.click("link=Edit Profile"); selenium.waitForPageToLoad("30000"); selenium.click("link=Main Menu"); selenium.waitForPageToLoad("30000"); selenium.click("link=Edit Profile"); selenium.waitForPageToLoad("30000"); selenium.click("document.forms[0].elements[24]"); selenium.waitForPageToLoad("30000"); }
    50. 50. Maven & Selenium
    51. 51. Selenium Architecture Selenium server
    52. 52. Maven & SeleniumStart Selenium server locally Run integration tests Stop selenium server
    53. 53. Selenium Maven pluginhttp://mojo.codehaus.org/selenium-maven-plugin selenium:start-server selenium:stop-server
    54. 54. Selenium Maven plugin<plugin> <groupId>org.codehaus.mojo</groupId> <artifactId>selenium-maven-plugin</artifactId> <version>1.0-rc-1</version> <executions> <execution> <id>start-selenium</id> <phase>pre-integration-test</phase> <goals> <goal>start-server</goal> </goals> </execution> </executions> <configuration> <background>${selenium.background}</background> </configuration></plugin>
    55. 55. Testing in different environments
    56. 56. Multi environment Multiple BrowsersMultiple Operating Systems
    57. 57. Multi environment Multiple BrowsersMultiple Operating Systems
    58. 58. Multi environment Multiple BrowsersMultiple Operating Systems
    59. 59. Parallel Run tests in parallel in each browserseveral browsers per test Load testing
    60. 60. Selenium Grid
    61. 61. TestNG propertiesAllows to run the same tests in different environments and in parallel
    62. 62. TestNG properties<suite name="Example" parallel="tests" thread-count="3"> <test name="iexplore"> <parameter name="browser" value="*iexplore"/> <packages> <package name="com.effectivemaven.centrepoint.selenium" /> </packages> </test> <test name="firefox2"> <parameter name="browser" value="*firefox2"/> <packages> <package name="com.effectivemaven.centrepoint.selenium" /> </packages> </test> <test name="opera"> <parameter name="browser" value="*opera"/> <packages> <package name="com.effectivemaven.centrepoint.selenium" /> </packages> </test></suite>
    63. 63. TestNG properties<suite name="Example" parallel="tests" thread-count="3"> <test name="iexplore"> <parameter name="browser" value="*iexplore"/> <packages> <package name="com.effectivemaven.centrepoint.selenium" /> </packages> </test> <test name="firefox2"> <parameter name="browser" value="*firefox2"/> <packages> <package name="com.effectivemaven.centrepoint.selenium" /> </packages> </test> <test name="opera"> <parameter name="browser" value="*opera"/> <packages> <package name="com.effectivemaven.centrepoint.selenium" /> </packages> </test></suite>
    64. 64. and now in the Cloud
    65. 65. Countless possibilitiesInternet ExplorerFirefox 2OperaSafariFirefox 3Firefox 2etc...no OS X :(
    66. 66. Amazon AMIs Create AMIs for different environments to testRead user data to customize the images at runtime where is the Selenium Hub
    67. 67. Linux Selenium headlessUse *nix X Virtual Frame Buffer In Maven selenium:xvfb
    68. 68. Windows Run Selenium Agent in user account not local service Selenium needs to have access to Desktop Disable password expiration Disable/Open windows firewallnetsh firewall add portopening TCP 8181 “Continuum BuildAgent” netsh firewall add portopening TCP 9000 “Selenium RC 9000”
    69. 69. Browser config Uninstall Internet Explorer Enhanced Security Configuration Windows 2003 http://www.visualwin.com/IE-enhanced-security/ in Add/Remove programs Windows 2008http://windowsitpro.com/article/articleid/96159/how-do-i-turn-off-internet-explorer- enhanced-security-configuration-in-windows-server-2008.html Safari/Firefox Disable popup blocker
    70. 70. Questions?
    71. 71. Tak!http://maestrodev.comhttp://carlossanchez.eucsanchez@maestrodev.comcarlos@apache.orgcsanchez
    72. 72. Credits Son of Man Legohttp://www.flickr.com/photos/hoyvinmayvin/4702772452/ XKCD - Compiling http://xkcd.com/303/

    ×