Introduce a TransactionTemplate for automating transaction retries.

Changed a flaky test to use the transaction template to avoid unnecessary breakages.
Merge pull request #3656 from rickardoberg/retryflaky

Introduce a TransactionTemplate for automating transaction retries