Football_Player_Market_client

This module is a simple Java client, which was created to test our scenario.

You can specify two parameters—the ID of the football player that you want to buy, and the value of your offer. If you don't specify these parameters, the default values will be 1 (Gianlugi Buffon) and 22 million, respectively.

Now, it's time to test it. Run the following command:

$ java -jar target/Football_Player_Market_client-1.0.0.jar 18 1   

I am offering 18 million to try buy Gianluigi Buffon; my offer will be considered valid, since 18 million is more than 80% of the value of the player. For this reason, the Narayana LRA coordinator will perform the complete phase.

The following is an extract of football-player-market-microservice-lra, showing the workflow performed by the LRA coordinator against the microservice:

2018-08-24   17:32:47,851 INFO    [com.packtpub.thorntail.footballplayermicroservice.rest.service.FootballPlayerMarketREST]   (default task-1) Start method sendOffer
2018-08-24 17:32:47,851 FINE [com.packtpub.thorntail.footballplayermicroservice.rest.service.FootballPlayerMarketREST] (default task-1) Retrieving football player with id 3
2018-08-24 17:32:47,853 FINE [com.packtpub.thorntail.footballplayermicroservice.rest.service.FootballPlayerMarketREST] (default task-1) Value of LRA_ID 0_ffff7f000001_-595eb3c1_5b80245b_17
2018-08-24 17:32:47,853 FINE [com.packtpub.thorntail.footballplayermicroservice.rest.service.FootballPlayerMarketREST] (default task-1) Creating offer ...
2018-08-24 17:32:48,452 FINE [com.packtpub.thorntail.footballplayermicroservice.rest.service.FootballPlayerMarketREST] (default task-1) Offer created with response code 204
2018-08-24 17:32:48,874 FINE [com.packtpub.thorntail.footballplayermicroservice.rest.service.FootballPlayerMarketREST] (default task-1) Got football player FootballPlayer{id=3, name=Keylor, surname=Navas, age=31, team=Real Madrid, position=goalkeeper, price=18, status=null, lraId=null}
2018-08-24 17:32:48,874 FINE [com.packtpub.thorntail.footballplayermicroservice.rest.service.FootballPlayerMarketREST] (default task-1) Changing football player status ...
2018-08-24 17:32:49,018 INFO [stdout] (default task-1) Value of offer price: 18
2018-08-24 17:32:49,018 INFO [stdout] (default task-1) Value of football player price: 18
2018-08-24 17:32:49,018 FINE [com.packtpub.thorntail.footballplayermicroservice.rest.service.FootballPlayerMarketREST] (default task-1) Value of offer price 18
2018-08-24 17:32:49,018 FINE [com.packtpub.thorntail.footballplayermicroservice.rest.service.FootballPlayerMarketREST] (default task-1) Value of football player price 18
2018-08-24 17:32:49,018 INFO [com.packtpub.thorntail.footballplayermicroservice.rest.service.FootballPlayerMarketREST] (default task-1) End method sendOffer
2018-08-24 17:32:49,131 INFO [com.packtpub.thorntail.footballplayermicroservice.rest.service.FootballPlayerMarketREST] (default task-2) Start method confirmOffer: I'm in LRA complete phase
2018-08-24 17:32:49,132 FINE [com.packtpub.thorntail.footballplayermicroservice.rest.service.FootballPlayerMarketREST] (default task-2) Value of header lraId http://localhost:8580/lra-coordinator/0_ffff7f000001_-595eb3c1_5b80245b_17
2018-08-24 17:32:49,132 FINE [com.packtpub.thorntail.footballplayermicroservice.rest.service.FootballPlayerMarketREST] (default task-2) Value of lraIdParameter 0_ffff7f000001_-595eb3c1_5b80245b_17
2018-08-24 17:32:49,132 FINE [com.packtpub.thorntail.footballplayermicroservice.rest.service.FootballPlayerMarketREST] (default task-2) Setting the offer as ACCEPTED ...
2018-08-24 17:32:49,306 FINE [com.packtpub.thorntail.footballplayermicroservice.rest.service.FootballPlayerMarketREST] (default task-2) Set the offer as ACCEPTED ...
2018-08-24 17:32:49,335 FINE [com.packtpub.thorntail.footballplayermicroservice.rest.service.FootballPlayerMarketREST] (default task-2) Got football player FootballPlayer{id=3, name=Keylor, surname=Navas, age=31, team=Real Madrid, position=goalkeeper, price=18, status=Reserved, lraId=0_ffff7f000001_-595eb3c1_5b80245b_17}
2018-08-24 17:32:49,335 FINE [com.packtpub.thorntail.footballplayermicroservice.rest.service.FootballPlayerMarketREST] (default task-2) Changing football player status ...
2018-08-24 17:32:49,353 INFO [com.packtpub.thorntail.footballplayermicroservice.rest.service.FootballPlayerMarketREST] (default task-2) End method confirmOffer: LRA complete phase terminated

I have highlighted the log messages that show the start and end of the business method and the complete phase organized by the LRA coordinator.

If you execute a check on the database side, you will notice that the status of Gianluigi Buffon is "purchased":

$ SELECT * FROM   football_player where id = 1

The output of the preceding command is as follows:

id  name     surname age        team           position    price  
1  Gianluigi Buffon  40   Paris Saint Germain  goalkeeper    2 

status lraid
Purchased ""

If you check the football player offer, as follows, you will be able to verify that the status is ACCEPTED:

$ SELECT * FROM FOOTBALL_PLAYER_OFFER WHERE ID_FOOTBALL_PLAYER = 1

The output of the preceding command is as follows:

ID ID_FOOTBALL_PLAYER ID_FOOTBALL_MANAGER PRICE STATUS
1 1 1 18 ACCEPTED

Now, we will simulate a failure scenario.

I will offer 5 million to try and buy Manuel Neuer; my offer will not be considered valid, since 5 million is less than 80% of the value of the player. For this reason, the Narayana LRA coordinator will perform the compensate phase.

Let's run the following command:

$ java -jar target/Football_Player_Market_client-1.0.0.jar 5 2

The following is an extract of football-player-market-microservice-lra, showing the workflow performed by the LRA coordinator against the microservice:

2018-08-25 00:18:20,007 INFO [com.packtpub.thorntail.footballplayermicroservice.rest.service.FootballPlayerMarketREST] (default task-4) Start method sendOffer
2018-08-25 00:18:20,008 FINE [com.packtpub.thorntail.footballplayermicroservice.rest.service.FootballPlayerMarketREST] (default task-4) Retrieving football player with id 2
2018-08-25 00:18:20,008 FINE [com.packtpub.thorntail.footballplayermicroservice.rest.service.FootballPlayerMarketREST] (default task-4) Value of LRA_ID 0_ffff7f000001_205e9dee_5b808159_53
2018-08-25 00:18:20,008 FINE [com.packtpub.thorntail.footballplayermicroservice.rest.service.FootballPlayerMarketREST] (default task-4) Creating offer ...
2018-08-25 00:18:20,104 FINE [com.packtpub.thorntail.footballplayermicroservice.rest.service.FootballPlayerMarketREST] (default task-4) Offer created with response code 204
2018-08-25 00:18:20,105 INFO [org.apache.http.impl.execchain.RetryExec] (default task-4) I/O exception (org.apache.http.NoHttpResponseException) caught when processing request to {}->http://localhost:8080: The target server failed to respond
2018-08-25 00:18:20,106 INFO [org.apache.http.impl.execchain.RetryExec] (default task-4) Retrying request to {}->http://localhost:8080
2018-08-25 00:18:20,113 FINE [com.packtpub.thorntail.footballplayermicroservice.rest.service.FootballPlayerMarketREST] (default task-4) Got football player FootballPlayer{id=2, name=Manuel, surname=Neuer, age=32, team=Bayern Munchen, position=goalkeeper, price=35, status=null, lraId=null}
2018-08-25 00:18:20,113 FINE [com.packtpub.thorntail.footballplayermicroservice.rest.service.FootballPlayerMarketREST] (default task-4) Changing football player status ...
2018-08-25 00:18:20,129 INFO [stdout] (default task-4) Value of offer price: 5
2018-08-25 00:18:20,129 INFO [stdout] (default task-4) Value of football player price: 35
2018-08-25 00:18:20,129 FINE [com.packtpub.thorntail.footballplayermicroservice.rest.service.FootballPlayerMarketREST] (default task-4) Value of offer price 5
2018-08-25 00:18:20,129 FINE [com.packtpub.thorntail.footballplayermicroservice.rest.service.FootballPlayerMarketREST] (default task-4) Value of football player price 35
2018-08-25 00:18:20,130 ERROR [org.jboss.resteasy.resteasy_jaxrs.i18n] (default task-4) RESTEASY002010: Failed to execute: javax.ws.rs.WebApplicationException: The offer is unacceptable!
at com.packtpub.thorntail.footballplayermicroservice.rest.service.FootballPlayerMarketREST.sendOffer(FootballPlayerMarketREST.java:142)
at com.packtpub.thorntail.footballplayermicroservice.rest.service.FootballPlayerMarketREST$Proxy$_$$_WeldClientProxy.sendOffer(Unknown Source)
...
2018-08-25 00:18:20,152 INFO [com.packtpub.thorntail.footballplayermicroservice.rest.service.FootballPlayerMarketREST] (default task-5) Start method compensateWork: I'm in LRA compensate phase
2018-08-25 00:18:20,152 FINE [com.packtpub.thorntail.footballplayermicroservice.rest.service.FootballPlayerMarketREST] (default task-5) Value of lraIdParameter 0_ffff7f000001_205e9dee_5b808159_53
2018-08-25 00:18:20,153 FINE [com.packtpub.thorntail.footballplayermicroservice.rest.service.FootballPlayerMarketREST] (default task-5) Setting the offer as REFUSED ...
2018-08-25 00:18:20,196 FINE [com.packtpub.thorntail.footballplayermicroservice.rest.service.FootballPlayerMarketREST] (default task-5) Set the offer as REFUSED ...
2018-08-25 00:18:20,203 FINE [com.packtpub.thorntail.footballplayermicroservice.rest.service.FootballPlayerMarketREST] (default task-5) Got football player FootballPlayer{id=2, name=Manuel, surname=Neuer, age=32, team=Bayern Munchen, position=goalkeeper, price=35, status=Reserved, lraId=0_ffff7f000001_205e9dee_5b808159_53}
2018-08-25 00:18:20,203 FINE [com.packtpub.thorntail.footballplayermicroservice.rest.service.FootballPlayerMarketREST] (default task-5) Changing football player status ...
2018-08-25 00:18:20,227 INFO [com.packtpub.thorntail.footballplayermicroservice.rest.service.FootballPlayerMarketREST] (default task-5) End method compensateWork: LRA compensate phase terminated

I have highlighted the log messages that show the start and end of the business method and the compensate phase organized by the LRA coordinator.

If you execute a check on the database side, you will notice that the status of Manuel Neuer is Free:

$ java -jar target/Football_Player_Market_client-1.0.0.jar 5 2

The output of the preceding command is as follows:

id name surname age     team       position  price status lraid 
2  Manuel Neuer  32 Bayern Munchen goalkeeper 35   Free    "" 

If you check the football player offer, you can verify that the status will be REFUSED:

$ SELECT * FROM FOOTBALL_PLAYER_OFFER WHERE ID_FOOTBALL_PLAYER = 2 

The output of the preceding command is as follows:

2 2 1 5 REFUSEDID ID_FOOTBALL_PLAYER ID_FOOTBALL_MANAGER PRICE STATUS
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset