Sharing our practices in managing batch processes at scale and the tools used for rapid building and execution of unit tests and end-to-end testing
Speakers: Jecelyn, David Hong
%in Bahrain+277-882-255-28 abortion pills for sale in Bahrain
#speakgeek - Pragmatic Batch Process Management & Developer Testing
1. David Hong • Jecelyn Yeen
PRAGMATIC
BATCH PROCESS MANAGEMENT
&
DEVELOPER TESTING
2. Agenda
Batch Process Management
• Problems.
• Job Scheduling Framework, Quartz.NET
• What’s Next.
Developer Testing
• Unit testing.
• End to end testing.
4. Problems
• No Automated Deployment
• Developer spend more time in deployment.
• Cumbersome Error Log Analysis
• Support team having difficulties in
troubleshooting.
5. Solution - “Job Scheduling Framework"
• Quartz.NET, Open Source
• Port of Java Scheduling Framework, Quartz.
• Set up as Windows Service.
Download & Set-up Put in your job Your job is ready
6. Solution for No Automated Deployment
• Quartz API method with CI tool (Jenkins)
7. Solution for Cumbersome Error Log
Analysis
• Quartz.NET with Common Logging Framework
Integration.
• Send logging messages to Centralised Logging
Framework (ELK Stack).
8. Quartz.NET Features
• Provide API method to interact with main
scheduler.
• Support job execution on any .NET class that
implements the generic interface.
9. Quartz.NET Scheduling
• Flexible triggers and rules
with Cron Expressions.
• Time Zone specific
schedulers.
• http://www.cronmaker.com/
11. Job Scheduler’s Parameters
Job Parameter Remark
JobItemClassName Job namespace and class name . It have to be unique among the Job Item.
Example: “Speakgeek.Session” that will accept topic name as parameter
Cron Schedule For Cron Schedule go to http://www.cronmaker.com/ to generate the expression
Example: “0 0 8 1/1 * ? *” – Run every day start from 8am
File Path Your dll, exe file location, beware of the security
Example: “C:Speakgeekspeakgeek.dll or speakgeek.exe”
Argument Custom argument that you can pass to the job
Example: topic name :“BatchProcess, ContinouesIntegration”
HandleMisFire Misfired rule such as
• Execute misfired immediately
• Do nothing
13. What’s Next
• Expose Quartz.NET as Web Service
• Campaign Scheduler
• Reporting Scheduler
• Clustering in Quartz.NET
14. Benefits of Quartz.NET
• Low Set-up Time and Cost
• Flexibility in Job Scheduling
• Ease of Integration
• Maintainability with Centralised Logging
Framework
• Scalability with Clustering
15. Helpful Links
• Quartz.NET Official Website
• http://www.quartz-scheduler.net/
• Cron Maker
• http://www.cronmaker.com/
• Cron Maker Tutorial
• http://www.quartz-scheduler.org/documentation/quartz-1.x/tutorials/crontrigger
• Common Logging .NET
• https://github.com/net-commons/common-logging
• Geeks with Blogs with detail walkthrough
• http://bit.ly/1dzCwgA
28. Unit testing
framework
Unit testable
code
Mocking Methodology
Working!
• Legacy code
• Inexperienced
• Static object
• Refactoring
• Time consuming
No one knows TDD
in a proper way
1st round: Result
32. End to end (E2E) testing
Verify that a system meets
external requirements and
achieves its goals, testing the
entire system, from end to end
33. Unit vs Integration vs E2E testing
Stimulate real
user scenarios.
End to end
testing
Takes a small group of
units (2 units), tests
their behaviour as a
whole
Integration
testing
Test a small piece of
the product in
isolation
Unit
testing
37. The Benefits of SpecFlow
Standard way of
defining test case
Reusable
Human
understandable
Hide away
implementation
details
Less require tech
knowledge
39. The Testing Pyramid
• Fast
• Reliable
• Isolate failure
Need initialization,
slower
• Stimulate real user
• Take longer time
• Take longer time
Number of tests
40. Journey thus Far
Start small
Having experienced guides
Motivation
Communication
What we’ve learn
Increase code coverage
Implement unit test for defects / enhancements
Where we’re heading to
Automate performance testing
How we manage our batch process and discuss some of the problems we face. I will also show you some great features of Quartz.NET when scheduling your job. Then I will show you the process of managing our batch process with Quartz.NET and how we moving forward with Quartz.NET.
Introduction
How we manage our batch process that runs repeatedly on daily or monthly basis. For example Set Failed Payment Notification Email to all members
We started small with SQL Server Job Scheduler and Windows Task Scheduler which is work well for us, but we start to face some problems when our clients base start to grow.
No Automated Deployment
Developer should focus on their product development instead of deployment. In order to improve the productivity,
we are practising Agile with Continuous Delivery where we continuously releasing our Product with great features on monthly basis.
In order to achieve that, this is where Continuous Integration (CI) come into picture. Ultimate we only need to click a "Push" button that will automate the build, test and release process so our developer continue develop better product. To know more about CI, stay tune for next session later.
Cumbersome Error Log Analysis
When comes to maintain the batch process, logs is very important for analyse/ identity the root cause when error occurred. it was very troublesome for support team to access the logs in Production Machine where a remote access always needed. This happen for Windows Task Scheduler when errors are being logged in Windows Events Log of the machine.
I will show how to address these problems in next few slides.
The main focus of Quartz are easy to setup and use with 3 steps:
Download and setup
Minimum changes required to putting in your app as part of scheduler
Start execute your job with own scheduler.
After some research on address those problems, we had chosen “Quartz.NET” as our “Job Scheduling Framework” .
The main focus of Quartz are easy to setup and use with 3 steps:
Download and setup
Minimum changes required to putting in your app as part of scheduler
Start execute your job with own scheduler.
In order to achieve Automated Deployment, we are using Quartz API method together with Jenkins (CI Tool).
This diagram show the process involved when we decide set-up a new batch job
Developer will add the new batch job in Batch Configuration
Devops will trigger Jenkins Task that will
Get latest Batch Configuration from the Source Control
Iterate through the configuration by schedule job into Quartz via API
Restart Quartz Service to load the latest Quartz Jobs
Provides a simple logging abstraction to switch between different logging implementations. There is current support for log4net, NLog and Enterprise Library logging.
Early of this year, we had launched Centralized Logging Framework to collect and store all our application logs to help Support team in analyze production issue.
So, its very important to ensure all our Batch process able to integrate with the logging framework easily.
We make use of Nlog in sending logs to Redis and LogStash and Kibana (Centralised Logging Framework)
Redis – NoSQL database which store data in Memory. Since everything is in-memory, so the READ/WRITE is extremely fast. For us, we use it as a Cache Store. We are sending logging message to REDIS via Nlog Redis Plugin
LogStash – its help to process logs in different format such as IISLog, JSON, Event Log and etc. Then you can some manipulate rule on those logs and output your content different destination. In our case, we are output the logs into ElasticSearch.
ElasticSearch – RESTful search engine where all your data stored in JSON format.
Kibana – Web Interface on top of ElasticSearch that act as analytics and visualization platform where you can easily shape your data into different form.
Quartz.NET is a full-featured, open source job scheduling system that can be used from smallest apps to large scale enterprise systems.
Setup as Windows Service , Console Application, Web Service
Provide API method to interact with main scheduler.
Scheduled/Unscheduled/Stop/Pause/Resume
Run with any .NET class that implement Ijob Interface.
Minimum migration effort required
Job Status Notification
jobToBeExecuted
jobExecutionVetoed
jobWasExecuted
Time zone base scheduler mean you can have your own time zone trigger for each batch process instead of based on machine time zone.
Simpler Trigger to have Calendar exclude Day (Public Holiday)
JobItemClassName = Job namespace and class name . It have to be unique among the Job Item.
CronSchedule = For CronSchedule go to http://www.cronmaker.com/ to generate the expression
IdentityGroup = Job Group;
Priority = Priority of the job;
FilePath = Your dll, exe file location, beware of the security
JobType= I: job inherintance the IBatchJob, C: stand alone exe.
Arguement = Only need if JobType = "C", is the parameter wish to pass to the exe.
HandleMisFire = 1: withMisfireHandlingInstructionIgnoreMisfires (All misfired executions are immediately executed, then the trigger runs back on schedule.)
2: withMisfireHandlingInstructionFireAndProceed (Immediately executes first misfired execution and discards other (i.e. all misfired executions are merged together). Then back to schedule. No matter how many trigger executions were missed, only single immediate execution is performed.)
3: withMisfireHandlingInstructionDoNothing (All misfired executions are discarded, the scheduler simply waits for next scheduled time.)
Split the job evenly
If one of node fail, other node will recover it immediately.
Prevent Single point of failure
Moving toward SOA which provide Self Service Scheduler Service
Campaign Scheduler – schedule email campaign to customers for any newsletter or promotion
Reporting Scheduler – send daily sales report to their manager
The scheduler load will definitely increase when many clients start to schedule their own job. We can easily scale our application by enable clustering feature in Quartz.NET.
Low set-up time and cost
Open Source
Very easy to set-up
Various type of setup option: Window Services, Console App, Web Service
Flexibility in scheduling
You schedule almost any combination of trigger
Time zone based
Simplicity of integration with iJob Interface
Low integration effort / Onboard
Maintainability with common logging framework
Support different logging implementation: NLOG / LOG4NET
Integrated with Centralised Logging Framework (Redis + ELK)
Scalability with Clustering
As your scheduler load increases, you can easily launch a new Quartz instance speed up the process time.
Low set-up time and cost
Open Source
Very easy to set-up
Various type of setup option: Window Services, Console App, Web Service
Flexibility in scheduling
You schedule almost any combination of trigger
Time zone based
Simplicity of integration with iJob Interface
Low integration effort
Maintainbility with common logging framework
Support different logging implementation: NLOG / LOG4NET
Integrated with Centralised Logging Framework (Redis + ELK)
Scalability with Clustering
As your scheduler load increases, you can easily launch a new Quartz instance speed up the process time.
1. Isolated: Each Unit Test Should Be Able to Run Independently
2. Test Only One Condition at a Time
3. Repeatable
4. Thorough. A code coverage of 80% and above is a good indication
5. Mock External References. should only be one assert statement for each test method
Don’t over mock:http://googletesting.blogspot.com/2013/05/testing-on-toilet-dont-overuse-mocks.html
System test: I check if my own system works as expected. For example on e-commerce site: If my customer goes through checkout, correct data are sent to the warehouse (which is owned by someone else)
End To End test: As stated above, the actual workflow. Someone puts a piece of goods to the shopping basket and fills in the user data, pays for it. I check if I actually received payment, make call to warehouse, make sure they received the data. And as little cherry on the pie: By receving the parcel, I make sure, that those data were good enough, were printed correctly, especially, when my real name is Pavel Janíček (see the funny diacritics? they sometimes get printed out incorrectly).
Integration System Testing: All the various system components are tested if they give the correct expected results in minute details.
End-to-End Testing: The entire application is tested from the beginning to end as if to be satisfied when viewed from the customer.
For example if you were to test an e-commerce site the shop front, browsing for items, cart and checkout would all work fine in systems test. You may then find issues with the workflow of moving between these areas of functionality in an end to end test.
Flower
---------
http://martinfowler.com/articles/microservice-testing/
Unit tests - exercise the smallest pieces of testable software in the application to determine whether they behave as expected.
Integration tests - verify the communication paths and interactions between components to detect interface defects.
Component tests - limit the scope of the exercised software to a portion of the system under test, manipulating the system through internal code interfaces and using test doubles to isolate the code under test from other components.
Contract tests - verify interactions at the boundary of an external service asserting that it meets the contract expected by a consuming service.
End-To-End tests - verify that a system meets external requirements and achieves its goals, testing the entire system, from end to end.
Gherkin is a domain specific language that lets us describe how our applications should behave without having to explain implementation details. Most of the above specification is free-text; there are only a few Gherkin specific keywords: Feature, Scenario, Given, When, And and Then. Everything else is free-text and is practically our documentation of how the feature is used.
Gherkin is a line-oriented language with each line in the scenario called a step. The first step in the "Logging in with valid credentials" scenario is "Given I am at the login page". The step needs a step definition so our test runner will know how to accomplish this step. A step definition in Spec Flow is simply a method with an attribute that contains the text of the step. All step definition methods need to be within a class that has a Binding attribute.
TDD vs BDDTha main benefit of BDD and tools like specflow and Cucumber is communication with the stakeholders of the project and creating a shared understanding of what is to be built.
The main benefit of TDD is to take small steps through a solutions implementation, ensuring that you build maintainable and great code.
Or if you want; BDD is about ensuring that we're building the right thing, TDD is about ensuring that we're building it right.
http://www.marcusoft.net/2011/11/bdd-and-technical-scenarios.html
http://googletesting.blogspot.com/2015/04/just-say-no-to-more-end-to-end-tests.html