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.
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: