### Question:
StaticMetastoreLocator implements MetastoreLocator { @Override public ThriftMetastoreClient createMetastoreClient(Optional<String> delegationToken) throws TException { List<Integer> indices = backoffs.stream() .sorted(Comparator.comparingLong(Backoff::getBackoffDuration)) .map(backoffs::indexOf) .collect(toImmutableList()); TException lastException = null; for (int index : indices) { try { return getClient(addresses.get(index), backoffs.get(index), delegationToken); } catch (TException e) { lastException = e; } } throw new TException("Failed connecting to Hive metastore: " + addresses, lastException); } @Inject  StaticMetastoreLocator(StaticMetastoreConfig config, ThriftMetastoreAuthenticationConfig authenticationConfig, ThriftMetastoreClientFactory clientFactory);  StaticMetastoreLocator(List<URI> metastoreUris, @Nullable String metastoreUsername, ThriftMetastoreClientFactory clientFactory); @Override ThriftMetastoreClient createMetastoreClient(Optional<String> delegationToken);  }### Answer:
@Test public void testDefaultHiveMetastore() throws TException { MetastoreLocator locator = createMetastoreLocator(CONFIG_WITH_FALLBACK, ImmutableMap.of(DEFAULT_URI, Optional.of(DEFAULT_CLIENT))); assertEqualHiveClient(locator.createMetastoreClient(Optional.empty()), DEFAULT_CLIENT); }
@Test public void testFallbackHiveMetastore() throws TException { MetastoreLocator locator = createMetastoreLocator(CONFIG_WITH_FALLBACK, ImmutableMap.of(DEFAULT_URI, Optional.empty(), FALLBACK_URI, Optional.of(FALLBACK_CLIENT))); assertEqualHiveClient(locator.createMetastoreClient(Optional.empty()), FALLBACK_CLIENT); }
@Test public void testFallbackHiveMetastoreWithHiveUser() throws TException { MetastoreLocator locator = createMetastoreLocator(CONFIG_WITH_FALLBACK_WITH_USER, ImmutableMap.of(DEFAULT_URI, Optional.empty(), FALLBACK_URI, Optional.empty(), FALLBACK2_URI, Optional.of(FALLBACK_CLIENT))); assertEqualHiveClient(locator.createMetastoreClient(Optional.empty()), FALLBACK_CLIENT); }
@Test public void testFallbackHiveMetastoreOnTimeOut() throws TException { MetastoreLocator cluster = createMetastoreLocator(CONFIG_WITH_FALLBACK, CLIENTS); ThriftMetastoreClient metastoreClient1 = cluster.createMetastoreClient(Optional.empty()); assertEqualHiveClient(metastoreClient1, DEFAULT_CLIENT); assertGetTableException(metastoreClient1); ThriftMetastoreClient metastoreClient2 = cluster.createMetastoreClient(Optional.empty()); assertEqualHiveClient(metastoreClient2, FALLBACK_CLIENT); assertGetTableException(metastoreClient2); }
@Test public void testFallbackHiveMetastoreOnAllTimeOut() throws TException { MetastoreLocator cluster = createMetastoreLocator(CONFIG_WITH_FALLBACK, CLIENTS); ThriftMetastoreClient metastoreClient1 = cluster.createMetastoreClient(Optional.empty()); assertEqualHiveClient(metastoreClient1, DEFAULT_CLIENT); for (int i = 0; i < 20; ++i) { assertGetTableException(metastoreClient1); } ThriftMetastoreClient metastoreClient2 = cluster.createMetastoreClient(Optional.empty()); assertEqualHiveClient(metastoreClient2, FALLBACK_CLIENT); assertGetTableException(metastoreClient2); ThriftMetastoreClient metastoreClient3 = cluster.createMetastoreClient(Optional.empty()); assertEqualHiveClient(metastoreClient3, FALLBACK_CLIENT); }