Fault injection
Fault injection provides the ability to deliberately cause a service to fail, in order to test failure in a complex distributed solution. Sitecore XC has a single fault injection pattern, which covers the concurrency fault in the persistence of a Commerce Entity.
The Sitecore.Commerce.Plugin.FaultInjection plugin is included in the sample Commerce Engine project provided in the Sitecore.Commerce.Engine.SDK package.
The Sitecore.Commerce.Plugin.FaultInjection plugin included in the sample Commerce Engine project is intended for use only in development or test environments. In the Sitecore.Commerce.Engine.SDK, the path to the Commerce Engine project is: Sitecore.Commerce.Engine.SDK.*.*.**\src\Sitecore.Commerce.Engine\Sitecore.Commerce.Engine.csproj.
You must remove the sample Sitecore.Commerce.Plugin.FaultInjection plugin from your custom solution before deploying to production.
To inject the defined concurrency fault:
-
Ensure that your
Sitecore.Commerce.Engineproject contains a reference to theSitecore.Commerce.Plugin.FaultInjection. -
In the API request, add a header named
FaultInjection. -
Assign the value
ConcurrencyFaultto the header you added in the previous step. -
Invoke any API methods that persists a Commerce Entity.
At this point, you should have a concurrency fault raised.
The following is a sample result from calling the AddCartLine 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
In Postman, the response body shows the following:
"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='Concurrency error: The Entity version supplied (1) is lower or equal to the current version
(1).'|Number=50000|Procedure='sp_CommerceEntitiesUpdate'|Line=22",
"CommerceTermKey": "EntityPersistException"
}