Fault injection
Fault injection is the ability to deliberately cause a service to purposely fail, in order to properly test failure in a complex distributed solution. Sitecore Commerce has a single fault injection pattern, which covers the concurrency exception in the persistence of a Commerce Entity. To inject the defined concurrency fault, perform the following tasks:
-
Modify the
project.json
file for theSitecore.Commerce.Engine
project by adding a reference to theSitecore.Commerce.Plugin.FaultInjection
. -
Add a Header to the request named
FaultInjection
. -
Assign a value of
ConcurencyFault
to the Header you just added. -
Invoke any API method that persists a Commerce Entity.
At this point, you should have a concurrency error raised.
The following example is a sample result from calling the "AddCartLine" by using Postman, with the fault injection Header inserted:
Headers raw view:
Content-Type:application/json
ShopName:{{ShopName}}
ShopperId:{{ShopperId}}
Language:{{Language}}
Currency:{{Currency}}
Environment:{{Environment}}
IpAddress:{{IpAddress}}
CustomerId:{{CustomerId}}
Roles:{{Roles}}
FaultInjection:ConcurencyFault
Response body:
"ResponseCode": "Error",
"Messages": [
{
"MessageDate": "2016-09-01T12:12:45.0287079-05:00",
"Code": "Error",
"Text": "SQL.UpdateEntity.Fail:Id=Cart01|Try=1|Environment=Entity-CommerceEnvironment-
AdventureWorks|Message='Concurency error: The Entity version supplied (1) is lower or equal to the current version
(1).'|Number=50000|Procedure='sp_CommerceEntitiesUpdate'|Line=22",
"CommerceTermKey": "EntityPersistException"
}