Presentation is loading. Please wait.

Presentation is loading. Please wait.

The Usual Suspects Jorge Hidalgo Senior Technology Architect

Similar presentations


Presentation on theme: "The Usual Suspects Jorge Hidalgo Senior Technology Architect"— Presentation transcript:

1 The Usual Suspects Jorge Hidalgo Senior Technology Architect
Creating a Cloud Development Environment with Sonar, Selenium and JMeter on OpenShift Origin Jorge Hidalgo Senior Technology Architect Accenture Delivery Centre in Spain – Java Lead

2 The Usual Suspects Creating a Cloud Development Environment with Sonar, Selenium and JMeter on OpenShift Origin Abstract: OpenShift has already established itself as a great platform to run Java applications (plus many other technologies) in the Cloud. But OpenShift also offers the foundation for a development environment, including source control with Git, build automation with Maven and continuous integration with Jenkins. In this session, we will learn how to extend the basic development environment and create a more powerful environment on OpenShift featuring “usual suspects” such as Sonar for continuous quality assurance, Selenium for functional testing, JMeter for performance/load testing as well as Arquillian for in-container testing. The session includes a live demo built on OpenShift Origin. Speaker: Jorge Hidalgo – Senior Technology Architect Accenture Delivery Centre in Spain – Java Lead Author of dr. macphail’s trance blog:

3 What is a Development Environment?
The Usual Suspects What is a Development Environment?

4 How Cloud Platforms can be of help?
The Usual Suspects How Cloud Platforms can be of help?

5 The Usual Suspects Agenda
Understanding the Basics – Git and Apache Maven Continuous Integration with Jenkins Continuous Quality Assurance with Sonar Functional, Cross-browser Tests with Selenium WebDriver Performance/Load Tests with Apache JMeter In-Container Tests with Arquillian Q & A

6 00: Understanding the Basics – Git and Apache Maven

7 Understanding the Basics
Each application in OpenShift comes with a Git repository. Stores sources, configuration, binaries and scripts. Each push action to the repository triggers a new build and deploy process. Details on what means “build and deploy” depends on the type of application, and can be customised with action hooks. action hooks for a DIY app git push origin master

8 Understanding the Basics
For Java applications (jbossas-7 type) builds are managed with Apache Maven. Isolated configuration. Isolated local repository. Lifecycle standardisation. validate compile test package integration-test action hooks for a jbossas-7 app verify install deploy

9 We are using Spring Pet Clinic reference application as test subject.
Preparing Pet Clinic We are using Spring Pet Clinic reference application as test subject. Resource redirection fixed to work with Tomcat 7 and JBoss 7 Added some Selenium and Apache JMeter test scripts

10 Create a new JBoss application:
Preparing Pet Clinic Create a new JBoss application: >rhc app create -a petclinic -t jbossas-7 UUID: a74be67eaafb4ced969a279ce3082e03 Git URL: demo.example.com/~/git/petclinic.git/ Public URL: Command line

11 Preparing Pet Clinic Add MySQL cartridge:
>rhc app cartridge add -a petclinic -c mysql-5.1 Root User: admin Root Password: Uvvp2ZZ_nBzn Database Name: petclinic Connection URL: mysql:// :3306/ Command line

12 Merge Pet Clinic sources and configuration.
Preparing Pet Clinic Merge Pet Clinic sources and configuration. Load schema and initial data: Connect your favourite database client to the MySQL cartridge: OpenShift: redirect ports with command rhc port-forward. Origin: use the client directly in the Origin box. Run the scripts at: src/main/resources/db/mysql Alternatively: Run scripts on app start and disable them next time here: src/main/resources/applicationContext-dataSource.xml Commit and push.

13 Preparing Pet Clinic

14 01: Continuous Integration with Jenkins

15 Continuous Integration
OpenShift offers easy configuration of Jenkins, the popular Continuous Integration engine. Jenkins dashboard runs as another application within our domain. Jenkins consumes one gear. For each application managed with Jenkins a especial type of Java application is created: the builder. Builders consume gears. Why add Jenkins? Centralized build reports: status, error causes, which version is deployed, change log, etc. Better control to build process, e.g. add code profiling, add integration tests.

16 Jenkins Installation and Configuration
Create a new Jenkins application: >rhc app create -a jenkins -t jenkins-1.4 UUID: f614bee8414b0fb701f50fc Git URL: demo.example.com/~/git/jenkins.git/ Public URL: Command line

17 Jenkins Installation and Configuration
Add build job (and builder app) for Pet Clinic: >rhc app cartridge add -a petclinic –c jenkins-client-1.4 Job URL: https://jenkins-demo.example.com/job/petclinic- build/ Command line

18 Jenkins Installation and Configuration

19 02: Continuous Quality Assurance with Sonar

20 Continuous Quality Assurance
Sonar is a popular code profiler and dashboard that excels when used along a Continuous Integration engine: Seamless integration with Maven. Leverages best-of-breed tools as Checkstyle, PMD or FindBugs. Configurable quality profiles. Re-execution of tests and test code coverage (UT, IT). Design Structure Matrix analysis. Flexible and highly customisable dashboard. Actions plans / peer reviews. Historic views / run charts. Can be used with Java, .Net, C/C++, Groovy, PHP,...

21 Sonar Installation and Configuration
Create a new DIY application: >rhc app create -a sonar -t diy-0.1 UUID: 4cd9eacb71b34401b81ea712352ffccb Git URL: demo.example.com/~/git/sonar.git/ Public URL: Command line

22 Sonar Installation and Configuration
Add MySQL cartridge: >rhc app cartridge add -a sonar -c mysql-5.1 Root User: admin Root Password: VyikSHzlLvjx Database Name: sonar Connection URL: mysql:// :3306/ Command line

23 Sonar Installation and Configuration
Unzip Sonar distribution to app root folder. Update conf/sonar.properties with settings for MySQL cartridge and bind to OpenShift internal IP and port: sonar.web.host: sonar.web.port: sonar.web.context: / sonar.jdbc.username: admin sonar.jdbc.password: VyikSHzlLvjx sonar.jdbc.driver: com.mysql.jdbc.Driver sonar.jdbc.url: jdbc:mysql:// :3306/sonar ?useUnicode=true&characterEncoding=utf &rewriteBatchedStatements=true File: /sonar/sonar-3.1.1/conf/sonar.properties

24 Sonar Installation and Configuration
Update action hooks with the appropriate commands to start and stop Sonar: #!/bin/bash cd $OPENSHIFT_REPO_DIR/sonar-3.1.1/bin/linux-x86-64 chmod 755 wrapper sh ./sonar.sh start sh ./sonar.sh stop File: /sonar/.openshift/action_hooks/start File: /sonar/.openshift/action_hooks/stop

25 Sonar Installation and Configuration
Add this to Pet Clinic build job to trigger the Sonar analysis before packaging and deploying the application: mvn --global-settings $OPENSHIFT_MAVEN_MIRROR clean test export SONAR_JDBC="-Dsonar.jdbc.url=jdbc:mysql:// :3306/sonar ?useUnicode=true&characterEncoding=utf8" export SONAR_DRIVER=-Dsonar.jdbc.driver=com.mysql.jdbc.Driver export SONAR_DBUSER=-Dsonar.jdbc.username=admin export SONAR_DBPASS=-Dsonar.jdbc.password=VyikSHzlLvjx export SONAR_URL=-Dsonar.host.url=http://sonar-demo.example.com export SONAR_OPTS="$SONAR_JDBC $SONAR_DRIVER $SONAR_DBUSER $SONAR_DBPASS $SONAR_URL" mvn --global-settings $OPENSHIFT_MAVEN_MIRROR sonar:sonar $SONAR_OPTS Jenkins job: petclinic-build

26 Sonar Installation and Configuration

27 03: Functional, Cross-browser Tests with Selenium WebDriver

28 Functional Tests Selenium is a popular framework / tool that allows, for web based applications, to record, re-execute and distribute tests across multiple browsers and computers. Because Java-only tests may not be enough. Can run with HtmlUnit to simulate a real browser (useful to gather code coverage metrics). Can run with local browsers or distributed across computers in a grid. The grid can be hosted in OpenShift, but browsers cannot – need dedicated machines with a desktop session that will act as test nodes. You can use your Origin box as both hub and test node.

29 Selenium Grid Hub Installation and Configuration
Create a new DIY application: >rhc app create -a seleniumhub -t diy-0.1 UUID: ddd8d0a2182b4b6799ec7c7ce8ae62b8 Git URL: seleniumhub-demo.example.com/~/git/seleniumhub.git/ Public URL: Command line

30 Selenium Grid Hub Installation and Configuration
Copy selenium-server-standalone jar (or other version) to folder selenium Update action hooks with appropriate commands to start and stop the hub: #!/bin/bash nohup java -jar $OPENSHIFT_REPO_DIR/selenium / selenium-server-standalone jar -role hub -host $OPENSHIFT_INTERNAL_IP -port $OPENSHIFT_INTERNAL_PORT >>$OPENSHIFT_LOG_DIR/seleniumhub.log 2>&1 & kill `ps -ef | grep selenium | grep -v grep | awk '{ print $2 }'` > /dev/null 2>&1 exit 0 File: /seleniumhub/.openshift/action_hooks/start File: /seleniumhub/.openshift/action_hooks/stop

31 Selenium Grid Hub Installation and Configuration
Update Maven target in Pet Clinic build job to launch Selenium tests with HtmlUnit to gather code coverage: mvn --global-settings $OPENSHIFT_MAVEN_MIRROR clean test ... Sonar settings ... mvn --global-settings $OPENSHIFT_MAVEN_MIRROR sonar:sonar $SONAR_OPTS mvn --global-settings $OPENSHIFT_MAVEN_MIRROR clean verify –Pcargo-tomcat,selenium-tests Jenkins job: petclinic-build BEFORE Jenkins job: petclinic-build AFTER

32 Selenium Grid Hub Installation and Configuration
Add this at the end of Pet Clinic build job to launch Selenium tests with real browsers once the app is deployed: export SELENIUM_BROWSERS="-Dtest.run.htmlunit=false -Dtest.run.firefox=true -Dtest.run.chrome=true" export SELENIUM_HUB="-Dtest.selenium.hub.url= export SELENIUM_TARGET="-Dtest.target.server.url= export SELENIUM_OPTS="$SELENIUM_BROWSERS $SELENIUM_HUB $SELENIUM_TARGET" mvn --global-settings $OPENSHIFT_MAVEN_MIRROR failsafe:integration-test –Pselenium-tests $SELENIUM_OPTS Jenkins job: petclinic-build

33 Pet Clinic Advanced Settings
What is the cargo-tomcat Maven profile doing? Provisions a Tomcat 7 container before ITs are executed. Tomcat runs with JaCoCo agent to gather coverage metrics. Stops the Tomcat 7 container after ITs are executed. Instead of Tomcat, we could use Glassfish, JBoss, Jetty...

34 Pet Clinic Advanced Settings
What is the selenium-tests Maven profile doing? Configures Maven’s Failsafe plug-in to execute Selenium integration tests during Maven’s integration-test phase. Tell Sonar where to find JaCoCo report.

35 Pet Clinic Advanced Settings
How are we dealing with different configuration for local and cloud execution? By default, assumes local execution (so developers can test within their IDEs). Local settings also work in CI server. Leverage openshift profile to copy configuration files over default ones when packaging the app for OpenShift.

36 Selenium in Action

37 Integration Tests Coverage as Seen by Sonar

38 04: Performance/Load Tests with Apache JMeter

39 Performance/Load Tests
Performance/Load Tests purpose is to verify application performance under stress: Capable of handling multiple requests at the same time. Well designed and implemented for concurrency. Adding Load Tests to continuous integration allows for early detection of concurrency and performance issues. Engineers/Architects may define thresholds to prevent deployments of non performant builds.

40 Performance/Load Tests
Apache JMeter is a veteran framework / tool that allows to record, define and re-execute a wide variety of integration tests: HTTP requests. Web Services (SOAP, JAX-RPC) requests. And many more. JMeter is capable of running tests concurrently using multiple threads: Locally, limited due to the amount of available resources. Remotely, using JMeter Server on multiple test nodes (load injectors).

41 Adding JMeter Tests to Jenkins and Sonar
Update Maven target in Pet Clinic build job to launch JMeter tests and save them in a known place for Sonar: mvn --global-settings $OPENSHIFT_MAVEN_MIRROR clean verify -Pcargo-tomcat,selenium-tests mvn --global-settings $OPENSHIFT_MAVEN_MIRROR clean verify -Pcargo-tomcat,selenium-tests,jmeter-tests Jenkins job: petclinic-build BEFORE Jenkins job: petclinic-build AFTER

42 Pet Clinic Advanced Settings
What is the jmeter-tests Maven profile doing? Configures Maven’s JMeter plug-in to execute JMeter tests during Maven’s integration-test phase. Tell Sonar where to find JMeter report.

43 JMeter Execution Report as Seen by Sonar

44 05: In-Container Tests with Arquillian

45 In-Container Tests There is a gap between ‘strict’ unit tests (method or class level, in isolation) and functional integration tests (focused on user interactions). Another type of tests, called unit-integration tests or in- container tests, bridge that gap and help testing application components: Within a container, using the services the container provides. Key to properly test features like: AOP transactions, AOP error handling, CDI bean injection, etc.

46 Key features of Arquillian include:
In-Container Tests Arquillian is a popular in-container test framework, recently born but with great traction in the community. Key features of Arquillian include: It’s open and modular – very easy to add extensions and new features. Allows for cross-container tests with the help of Maven profiles – very convenient if you want to test your components in multiple containers (Weld, JBoss, Glassfish...). Makes all the plumbing for you – prepares deployable units and puts them into the container of choice, either embedded (within the same JVM) or not (local / remote containers).

47 Preparing Arquillian Test Application
Create a new JBoss application: >rhc app create -a arqtest -t jbossas-7 UUID: 0690fabf2e3549abb746a911d Git URL: demo.example.com/~/git/arqtest.git/ Public URL: Merge sources and configuration from test application. Using some examples from Arquillian web site. Command line

48 Preparing Arquillian Test Application
Add build job (and builder app) for Arqtest: >rhc app cartridge add -a arqtest -c jenkins- client-1.4 Job URL: https://jenkins-demo.example.com/job/arqtest- build/ Command line

49 Preparing Arquillian Test Application
Add this to Arqtest build job to launch Arquillian tests: mvn --global-settings $OPENSHIFT_MAVEN_MIRROR --version mvn --global-settings $OPENSHIFT_MAVEN_MIRROR clean package –Popenshift -DskipTests mvn --global-settings $OPENSHIFT_MAVEN_MIRROR clean test -Parquillian-glassfish-embedded Commit and push. Jenkins job: arqtest-build BEFORE Jenkins job: arqtest-build AFTER

50 Running Arqtest Build Job
Arqtest build job will execute tests with a Glassfish embedded container:

51 The Usual Suspects – Wrap up
Platforms like OpenShift enable development teams to build and use powerful, best-of-breed development tools. Easy access to the best software engineering practices. With Origin, you get all the tools you need in the same box. Deploy it locally or in your in-house infrastructure. Excellent for individuals and small development teams... ...But if you work in a larger team and want more power, why not deploy the same in OpenShift?

52 Q & A


Download ppt "The Usual Suspects Jorge Hidalgo Senior Technology Architect"

Similar presentations


Ads by Google