@Test
  public void testBadCallbackForUpdateTtl() throws Exception {
    try {
      MockServerLayout serverLayout = new MockServerLayout(mockClusterMap);
      setRouter(getNonBlockingRouterProperties(localDcName), serverLayout, new LoggingNotificationSystem());
      setOperationParams();
      String blobId =
          router.putBlob(putBlobProperties, putUserMetadata, putChannel, new PutBlobOptionsBuilder().build())
              .get(AWAIT_TIMEOUT_MS, TimeUnit.MILLISECONDS);
      putChannel = new ByteBufferReadableStreamChannel(ByteBuffer.wrap(putContent));
      String blobIdCheck =
          router.putBlob(putBlobProperties, putUserMetadata, putChannel, new PutBlobOptionsBuilder().build())
              .get(AWAIT_TIMEOUT_MS, TimeUnit.MILLISECONDS);
      testWithErrorCodes(Collections.singletonMap(ServerErrorCode.NoError, 9), serverLayout, null, expectedError -> {
        final CountDownLatch callbackCalled = new CountDownLatch(1);
        router.updateBlobTtl(null, blobId, null, Utils.Infinite_Time, (result, exception) -> {
          callbackCalled.countDown();
          throw new RuntimeException("Throwing an exception in the user callback");
        }, null).get(AWAIT_TIMEOUT_MS, TimeUnit.MILLISECONDS);
        assertTrue("Callback not called.", callbackCalled.await(10, TimeUnit.MILLISECONDS));
        assertEquals("All operations should be finished.", 0, router.getOperationsCount());
        assertTrue("Router should not be closed", router.isOpen());
        assertTtl(router, Collections.singleton(blobId), Utils.Infinite_Time);

        //Test that TtlUpdateManager is still functional
        router.updateBlobTtl(blobIdCheck, null, Utils.Infinite_Time).get(AWAIT_TIMEOUT_MS, TimeUnit.MILLISECONDS);
        assertTtl(router, Collections.singleton(blobIdCheck), Utils.Infinite_Time);
      });
    } finally {
      if (router != null) {
        router.close();
      }
    }
  }
Test that a bad user defined callback will not crash the router or the manager.
@throws Exception
ambry-router/src/test/java/com/github/ambry/router/NonBlockingRouterTest.java