Fault injection
How to use the Sitecore.Commerce.Plugin.FaultInjection
plugin to test failure in a complex distributed solution.
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.Engine
project contains a reference to theSitecore.Commerce.Plugin.FaultInjection
.In the API request, add a header named
FaultInjection
.Assign the value
ConcurrencyFault
to 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" }