@Override
  public synchronized void cleanupAll() {
    try {

      if (usingStaticInstance) {
        if (databaseAdminClient != null) {
          Failsafe.with(retryOnQuotaException())
              .run(() -> databaseAdminClient.dropDatabase(instanceId, databaseId));
        }
      } else {
        LOG.info("Deleting instance {}...", instanceId);

        if (instanceAdminClient != null) {
          Failsafe.with(retryOnQuotaException())
              .run(() -> instanceAdminClient.deleteInstance(instanceId));
        }

        hasInstance = false;
      }

      hasDatabase = false;
    } catch (SpannerException e) {
      throw new SpannerResourceManagerException("Failed to delete instance.", e);
    } finally {
      if (!spanner.isClosed()) {
        spanner.close();
      }
    }
    LOG.info("Manager successfully cleaned up.");
  }
@Test
  public void testCleanupAllShouldThrowExceptionWhenSpannerDeleteInstanceFails() {
    // arrange
    doThrow(SpannerException.class).when(instanceAdminClient).deleteInstance(any());
    when(spanner.getInstanceAdminClient()).thenReturn(instanceAdminClient);
    testManager =
        new SpannerResourceManager(
            spanner, TEST_ID, PROJECT_ID, REGION, DIALECT, false, null, NODE_COUNT);

    // act & assert
    assertThrows(SpannerResourceManagerException.class, () -> testManager.cleanupAll());
  }