Choreographies - IME-USP

Transcription

Choreographies - IME-USP
Exploratory Study to assess
Rehearsal and TDD methodology
for web service choreographies
Training stage
Felipe Besson
SCA
2
SCA
Service Component Architecture
3
Composite Example
4
OW2 FraSCAti
●
Open source implementation of SCA
●
Dynamic reconfiguration support
●
implementation types: Java, Groovy, JavaScript,
JRuby, Jython, Scala, …
●
binding types: Java RMI, SOAP, REST, …
●
interface types: Java, WSDL, …
5
FraSCAti Demo
●
A simple orchestration of 2 web services
●
Service A: GreetingAWS
Input: “john” Output: “hi john, ”
●
Service B: GreetingBWS
Input: “john” Output: “john how are you bro?”
–
●
A + B for input “john”: “hi john, how are you bro?”
6
FraSCAti Demo
7
FraSCAti Demo
Step 01
●
Develop the component interface
–
Greeting.java
Step 02
●
Develop the implementation (business flow)
–
Orchestration.java
8
FraSCAti Demo
Step 03
●
Integrate serviceA into the flow
–
Create the service A
●
GreetingAWS.java
–
Bind the service (through stubs)
●
$ frascati wsdl2java -u <wsdl_uri> -o <src_dir>
–
Create the @References
●
Orchestrator.java
9
FraSCAti Demo
Step 04
●
Integrate serviceb into the flow
–
Create the service B
●
GreetingBWS.java
–
Bind the service (through stubs)
●
$ frascati wsdl2java -u <wsdl_uri> -o <src_dir>
–
Create the @References
●
Orchestrator.java
10
FraSCAti Demo
Step 05
●
●
Compiling the SCA application
–
$frascati compile <src_dir> <jar_file_name>
–
$frascati run <composite> -libpath <jar_file>
See http://localhost:9080/greeting?wsdl
11
(Choreographies in SCA)
Choreographies
●
Distributed coordination (roles)
–
Set of distributed orchestrations
●
Each orchestration is a role
–
In SCA
●
Orchestration = Composite =>
●
Composite = Role
12
How to test the composite
Invoke the composite service and test it as a black
box:
–
And the internal services?
●
●
As black boxes too
There are tools for doing that:
–
SoapUI, Eclipse web service plugins, stubs...
●
But if the contract is not available or change often?
●
How to maintain the automated test cases?
13
How to test the composite
How to validate the internal message flow:
–
Monitoring by using an ESB
–
Create and deploy proxies for the services that are
only published in your test cases
How to test a composition where the services are not
available in a testing environment?
–
Mock!
14
Rehearsal
15
Dynamic generation of clients
Help the developer to invoke Soap web
services
–
Test cases are written before having a contract
(WSDL file)
In the context of choreographies:
- Unit and acceptance test
16
Dynamic generation of clients
WSClient: our client !
17
Dynamic generation of clients
Types:
Primitive type
Complex type
<soap:envelope … >
<soap:envelope … >
<soap:body>
<soap:body>
<getProductStatus>
<getProductStatus>
<product>
<id>42</id>
<id>42</id>
<name>kindle</name>
<name>kindle</name>
<status>shipped</status>
<status>shipped</status>
</getProductStatus>
</product>
</soap:body>
</getProductStatus>
</soap:envelope>
</soap:body>
</soap:envelope>
18
Dynamic generation of clients
19
Dynamic generation of clients
Demonstration
Testing greetingAWS web service
20
But first ….
Divide the pairs
Setting up
$ cd ~/workspace/rehearsal-study/
$ git checkout master
$ git pull
Open eclipse and import the project rehearsal-study/
/training/sand_box
Item explorer: ~/workspace/rehearsal-study/start_explorer
21
Dynamic generation of clients
Your Turn
Testing the operation:
getWeather (cityName, countryName)
22
Message interceptor
Intercepting, storing and validating the messages
exchanged among services
–
Using proxies!
In the context of choreographies:
- Integration test
23
Message interceptor
24
Message interceptor
Demonstration
Intercepting the messages sent to
greetingBWS
25
Message interceptor
Your Turn
Intercepting the messages sent to
GlobalWeather
26
Service Mocking
Simulate a real service
●
Regular behavior
●
Faulty scenarios
In the context of choreographies:
- Integration test
27
Service Mocking
28
Service Mocking
Demonstration
Mocking GreetingAWS
29
Service Mocking
Your Turn
Mocking GlobalWeather WS without
defining mock conditions
30
Abstraction of choreography
Map choreography elements into Java objects
●
Help to write test cases
●
Interact with modeling diagrams
Service airline1 = bookTrip.getServicesByRole(“airline”).get(0);
WSClient ws = new WSClient (airline1.getWSDL());
31
Abstraction of choreography
Choreography Descriptor
roles:
- role: &1
name: supermarket
contractUri: file:///home/besson/workspace/futureMarket/roles/supermarket.wsdl
- role: &2
name: customer
contractUri: file:///home/besson/workspace/futureMarket/roles/customer.wsdl
services:
- uri: http://localhost:8084/petals/services/customer?wsdl
role: *2
participants:
- uri: http://localhost:1234/customerWS?wsdl
- uri: http://localhost:1234/smregistry?wsdl
- uri: http://localhost:8084/petals/services/supermarket1?wsdl
role: *1
participants:
- uri: http://localhost:4321/SM1?wsdl
32
Abstraction of choreography
33
TDD
Methodology
34
TDD Methodology
Why Test-Driven Development (TDD)?
●
●
Services are units
Test-Driven approach for compositions
–
–
–
–
Test early as possible
Define and document contracts
Exercise choreography features in an offline
environment (development-time)
Refactor whenever is possible
35
Methodology steps
36
TDD Methodology
Choreography development scenarios
1) A role or a set of roles must be developed
for the choreography
2) Roles are defined (via contracts) and
developers must provide only the web
services to implement the role
3) The choreography is being developed from
scratch
37
TDD Methodology
Phase 01
Creation or adaptation of atomic web services
– In the case of S1 and S3
●
–
In the case of S2
●
–
–
Contract is defined by the tests
Tests guide the development
Tests are an executable documentation
WSClient!
38
TDD Methodology
Phase 01
Creation or adaptation of atomic web services
39
TDD Methodology
Phase 02
Integration of services to compose the
choreography roles
–
Validate the messages exchanged inside the
executable processes
Mocking real dependencies
●
Using the Message Interceptor for
inspecting the messages
●
–
Detect binding problems early
40
TDD Methodology
Phase 03
Integration of roles to compose the
choreography
–
Validate the messages exchanged among the
executable processes
●
Roles are available as atomic services
Mocking third-party roles
– Using the Message Interceptor for
inspecting the messages
–
41
TDD Methodology
Phase 04
Acceptance and Scalability Testing
–
Validate all choreography features from the
user point of view
Without interceptors
●
Trying to use an environment closed to
production
●
–
Assess the choreography scalability
●
large workload and different choreography
configurations
42
TDD Methodology
Why performing this in development-time?
Build a choreography is not trivial!
–
Change choreographies all the time
Create, deploy, integrate services
Infrastructure and tools for composing services are not
consolidate
Dependent of third-party services
Scalability
●
–
–
–
Imagine deal with these issues only at runtime
43
Development
tasks
44
The choreography
Based on CHOReOS Passenger-friendly
choreography
●
Better serve passengers
–
–
–
●
Departure and arrive procedures
booking and shopping facilities
Plans arising from flight delays or cancellations
Selected scenario: Arrival at the airport
45
The choreography
After booking a car park reservation, when the passenger arrives at the
airport:
46
The choreography
47
Development Tasks
Each task corresponds to a methodology phase
1) Wrap the legacy system into a web service
2) Create the process to provide the
choreography roles
3) Integrate the choreography roles
4) Apply acceptance tests
48
Development Tasks
49
Development Tasks
Example of test case
50
Development Tasks
That is it =]
Have fun:
http://www.ime.usp.br/~besson/rehearsal-study/instructions
General information:
http://www.ime.usp.br/~besson/rehearsalstudy/instructions/info.html
51