@@ -399,6 +399,11 @@ private static Environment emptyEnv() {
399399 return new Environment (new HashMap <>(), new ArrayList <>(), System .getProperty ("os.name" ));
400400 }
401401
402+ // Note: getHostMetadata() is package-private and not called directly by users. It is invoked
403+ // internally by resolve() during config init. These tests call it explicitly to verify the raw
404+ // response parsing, so we register the well-known fixture twice: once consumed by resolve(),
405+ // and once for the explicit getHostMetadata() call under test.
406+
402407 @ Test
403408 public void testGetHostMetadataWorkspaceStaticOidcEndpoint () throws IOException {
404409 String response =
@@ -410,7 +415,9 @@ public void testGetHostMetadataWorkspaceStaticOidcEndpoint() throws IOException
410415 + DUMMY_WORKSPACE_ID
411416 + "\" }" ;
412417 try (FixtureServer server =
413- new FixtureServer ().with ("GET" , "/.well-known/databricks-config" , response , 200 )) {
418+ new FixtureServer ()
419+ .with ("GET" , "/.well-known/databricks-config" , response , 200 )
420+ .with ("GET" , "/.well-known/databricks-config" , response , 200 )) {
414421 DatabricksConfig config = new DatabricksConfig ().setHost (server .getUrl ());
415422 config .resolve (emptyEnv ());
416423 HostMetadata meta = config .getHostMetadata ();
@@ -425,7 +432,9 @@ public void testGetHostMetadataAccountRawOidcTemplate() throws IOException {
425432 String response =
426433 "{\" oidc_endpoint\" :\" https://acc.databricks.com/oidc/accounts/{account_id}\" }" ;
427434 try (FixtureServer server =
428- new FixtureServer ().with ("GET" , "/.well-known/databricks-config" , response , 200 )) {
435+ new FixtureServer ()
436+ .with ("GET" , "/.well-known/databricks-config" , response , 200 )
437+ .with ("GET" , "/.well-known/databricks-config" , response , 200 )) {
429438 DatabricksConfig config = new DatabricksConfig ().setHost (server .getUrl ());
430439 config .resolve (emptyEnv ());
431440 HostMetadata meta = config .getHostMetadata ();
@@ -438,7 +447,9 @@ public void testGetHostMetadataAccountRawOidcTemplate() throws IOException {
438447 @ Test
439448 public void testGetHostMetadataRaisesOnHttpError () throws IOException {
440449 try (FixtureServer server =
441- new FixtureServer ().with ("GET" , "/.well-known/databricks-config" , "{}" , 404 )) {
450+ new FixtureServer ()
451+ .with ("GET" , "/.well-known/databricks-config" , "{}" , 404 )
452+ .with ("GET" , "/.well-known/databricks-config" , "{}" , 404 )) {
442453 DatabricksConfig config = new DatabricksConfig ().setHost (server .getUrl ());
443454 config .resolve (emptyEnv ());
444455 DatabricksException ex =
@@ -463,7 +474,6 @@ public void testResolveHostMetadataWorkspacePopulatesAllFields() throws IOExcept
463474 new FixtureServer ().with ("GET" , "/.well-known/databricks-config" , response , 200 )) {
464475 DatabricksConfig config = new DatabricksConfig ().setHost (server .getUrl ());
465476 config .resolve (emptyEnv ());
466- config .resolveHostMetadata ();
467477 assertEquals (DUMMY_ACCOUNT_ID , config .getAccountId ());
468478 assertEquals (DUMMY_WORKSPACE_ID , config .getWorkspaceId ());
469479 assertEquals (
@@ -481,7 +491,6 @@ public void testResolveHostMetadataAccountSubstitutesAccountId() throws IOExcept
481491 DatabricksConfig config =
482492 new DatabricksConfig ().setHost (server .getUrl ()).setAccountId (DUMMY_ACCOUNT_ID );
483493 config .resolve (emptyEnv ());
484- config .resolveHostMetadata ();
485494 assertEquals (
486495 "https://acc.databricks.com/oidc/accounts/"
487496 + DUMMY_ACCOUNT_ID
@@ -506,7 +515,6 @@ public void testResolveHostMetadataDoesNotOverwriteExistingFields() throws IOExc
506515 .setAccountId (existingAccountId )
507516 .setWorkspaceId (existingWorkspaceId );
508517 config .resolve (emptyEnv ());
509- config .resolveHostMetadata ();
510518 assertEquals (existingAccountId , config .getAccountId ());
511519 assertEquals (existingWorkspaceId , config .getWorkspaceId ());
512520 }
@@ -521,7 +529,6 @@ public void testResolveHostMetadataMissingAccountIdWithPlaceholderSkipsDiscovery
521529 new FixtureServer ().with ("GET" , "/.well-known/databricks-config" , response , 200 )) {
522530 DatabricksConfig config = new DatabricksConfig ().setHost (server .getUrl ());
523531 config .resolve (emptyEnv ());
524- config .resolveHostMetadata ();
525532 // DiscoveryURL should not be set because account_id is empty and placeholder can't be
526533 // substituted
527534 assertNull (config .getDiscoveryUrl ());
@@ -535,7 +542,6 @@ public void testResolveHostMetadataNoOidcEndpointSkipsDiscoveryUrl() throws IOEx
535542 new FixtureServer ().with ("GET" , "/.well-known/databricks-config" , response , 200 )) {
536543 DatabricksConfig config = new DatabricksConfig ().setHost (server .getUrl ());
537544 config .resolve (emptyEnv ());
538- config .resolveHostMetadata ();
539545 assertEquals (DUMMY_ACCOUNT_ID , config .getAccountId ());
540546 assertNull (config .getDiscoveryUrl ());
541547 }
@@ -544,7 +550,9 @@ public void testResolveHostMetadataNoOidcEndpointSkipsDiscoveryUrl() throws IOEx
544550 @ Test
545551 public void testResolveHostMetadataRaisesOnHttpError () throws IOException {
546552 try (FixtureServer server =
547- new FixtureServer ().with ("GET" , "/.well-known/databricks-config" , "{}" , 500 )) {
553+ new FixtureServer ()
554+ .with ("GET" , "/.well-known/databricks-config" , "{}" , 500 )
555+ .with ("GET" , "/.well-known/databricks-config" , "{}" , 500 )) {
548556 DatabricksConfig config = new DatabricksConfig ().setHost (server .getUrl ());
549557 config .resolve (emptyEnv ());
550558 DatabricksException ex =
@@ -582,15 +590,14 @@ public void testResolveHostMetadataDoesNotOverwriteTokenAudience() throws IOExce
582590 .setAccountId (DUMMY_ACCOUNT_ID )
583591 .setTokenAudience ("custom-audience" );
584592 config .resolve (emptyEnv ());
585- config .resolveHostMetadata ();
586593 assertEquals ("custom-audience" , config .getTokenAudience ());
587594 }
588595 }
589596
590597 // --- tryResolveHostMetadata (config init) tests ---
591598
592599 @ Test
593- public void testEnsureResolvedResolvesHostMetadataWhenUnifiedHost () throws IOException {
600+ public void testEnsureResolvedResolvesHostMetadataWhenHostSet () throws IOException {
594601 String response =
595602 "{\" oidc_endpoint\" :\" https://ws.databricks.com/oidc\" ,"
596603 + "\" account_id\" :\" "
@@ -601,8 +608,7 @@ public void testEnsureResolvedResolvesHostMetadataWhenUnifiedHost() throws IOExc
601608 + "\" }" ;
602609 try (FixtureServer server =
603610 new FixtureServer ().with ("GET" , "/.well-known/databricks-config" , response , 200 )) {
604- DatabricksConfig config =
605- new DatabricksConfig ().setHost (server .getUrl ()).setExperimentalIsUnifiedHost (true );
611+ DatabricksConfig config = new DatabricksConfig ().setHost (server .getUrl ());
606612 config .resolve (emptyEnv ());
607613 assertEquals (DUMMY_ACCOUNT_ID , config .getAccountId ());
608614 assertEquals (DUMMY_WORKSPACE_ID , config .getWorkspaceId ());
@@ -613,8 +619,9 @@ public void testEnsureResolvedResolvesHostMetadataWhenUnifiedHost() throws IOExc
613619 }
614620
615621 @ Test
616- public void testEnsureResolvedSkipsHostMetadataWhenNotUnified () throws IOException {
617- // No metadata endpoint fixture — if it were called, the fixture server would fail
622+ public void testEnsureResolvedHostMetadataNotFoundNonFatal () throws IOException {
623+ // When host metadata endpoint returns 404, resolve should still succeed
624+ // (auto-stubbed by FixtureServer)
618625 try (FixtureServer server = new FixtureServer ()) {
619626 DatabricksConfig config = new DatabricksConfig ().setHost (server .getUrl ());
620627 config .resolve (emptyEnv ());
@@ -629,8 +636,7 @@ public void testEnsureResolvedHostMetadataFailureNonFatal() throws IOException {
629636 new FixtureServer ()
630637 .with (
631638 "GET" , "/.well-known/databricks-config" , "{\" error\" : \" internal error\" }" , 500 )) {
632- DatabricksConfig config =
633- new DatabricksConfig ().setHost (server .getUrl ()).setExperimentalIsUnifiedHost (true );
639+ DatabricksConfig config = new DatabricksConfig ().setHost (server .getUrl ());
634640 // Should not throw — metadata failure is non-fatal
635641 config .resolve (emptyEnv ());
636642 assertNull (config .getAccountId ());
@@ -643,8 +649,7 @@ public void testEnsureResolvedHostMetadataNoOidcEndpointNonFatal() throws IOExce
643649 String response = "{\" account_id\" :\" " + DUMMY_ACCOUNT_ID + "\" }" ;
644650 try (FixtureServer server =
645651 new FixtureServer ().with ("GET" , "/.well-known/databricks-config" , response , 200 )) {
646- DatabricksConfig config =
647- new DatabricksConfig ().setHost (server .getUrl ()).setExperimentalIsUnifiedHost (true );
652+ DatabricksConfig config = new DatabricksConfig ().setHost (server .getUrl ());
648653 config .resolve (emptyEnv ());
649654 assertEquals (DUMMY_ACCOUNT_ID , config .getAccountId ());
650655 assertNull (config .getDiscoveryUrl ());
@@ -658,8 +663,7 @@ public void testEnsureResolvedHostMetadataMissingAccountIdWithPlaceholderNonFata
658663 "{\" oidc_endpoint\" :\" https://acc.databricks.com/oidc/accounts/{account_id}\" }" ;
659664 try (FixtureServer server =
660665 new FixtureServer ().with ("GET" , "/.well-known/databricks-config" , response , 200 )) {
661- DatabricksConfig config =
662- new DatabricksConfig ().setHost (server .getUrl ()).setExperimentalIsUnifiedHost (true );
666+ DatabricksConfig config = new DatabricksConfig ().setHost (server .getUrl ());
663667 config .resolve (emptyEnv ());
664668 // DiscoveryURL should not be set because account_id is empty and placeholder can't be
665669 // substituted
0 commit comments