private void testFailureOnDecryption(SecretKeySpec perBlobKey, MockKeyManagementService mockKMS,
      boolean setExceptionForKMS, CryptoService cryptoService, KeyManagementService kms) throws InterruptedException {
    TestBlobData testData = getRandomBlob(referenceClusterMap);
    CountDownLatch encryptCallBackCount = new CountDownLatch(1);
    CountDownLatch decryptCallBackCount = new CountDownLatch(1);
    cryptoJobHandler.submitJob(new EncryptJob(testData.blobId.getAccountId(), testData.blobId.getContainerId(),
        testData.blobContent.retainedDuplicate(), testData.userMetadata, perBlobKey, cryptoService, kms, null,
        new CryptoJobMetricsTracker(routerMetrics.encryptJobMetrics),
        (EncryptJob.EncryptJobResult encryptJobResult, Exception exception) -> {
          encryptCallBackCount.countDown();
          assertNull("Exception shouldn't have been thrown to encrypt contents for " + testData.blobId, exception);
          assertNotNull("Encrypted contents should not be null", encryptJobResult.getEncryptedBlobContent());
          assertNotNull("Encrypted user-metadata should not be null", encryptJobResult.getEncryptedUserMetadata());
          assertNotNull("Encrypted key should not be null", encryptJobResult.getEncryptedKey());

          // set exception using MockKMS
          if (setExceptionForKMS) {
            mockKMS.exceptionToThrow.set(
                new GeneralSecurityException("Exception to test", new IllegalStateException()));
          }
          cryptoJobHandler.submitJob(new DecryptJob(testData.blobId, encryptJobResult.getEncryptedKey(),
              encryptJobResult.getEncryptedBlobContent(), encryptJobResult.getEncryptedUserMetadata(), cryptoService,
              kms, null, new CryptoJobMetricsTracker(routerMetrics.decryptJobMetrics),
              (DecryptJob.DecryptJobResult result, Exception e) -> {
                decryptCallBackCount.countDown();
                assertNotNull("Exception should have been thrown to decrypt contents for " + testData.blobId, e);
                assertTrue("Exception cause should have been GeneralSecurityException",
                    e instanceof GeneralSecurityException);
                assertNull("Result should have been null", result);
              }));
        }));
    awaitCountDownLatch(decryptCallBackCount, DECRYPT_JOB_TYPE);
    testData.blobContent.release();
  }
Test failure during decryption
@param perBlobKey the {@link SecretKeySpec} representing the per blob key
@param mockKMS {@link MockKeyManagementService} that mocks {@link KeyManagementService}
@param setExceptionForKMS {@code true} if exception needs to be set using {@link MockKeyManagementService}
                          {@code false} otherwise
@throws InterruptedException
ambry-router/src/test/java/com/github/ambry/router/CryptoJobHandlerTest.java