Skip to content

Commit 884e9dd

Browse files
committed
Always resolve host metadata when host is set, matching Go SDK
Remove the experimentalIsUnifiedHost gate in tryResolveHostMetadata() so metadata is resolved unconditionally during config init. Add auto-stub for /.well-known/databricks-config in FixtureServer to prevent metadata resolution from interfering with unrelated tests. Update tests to remove redundant explicit resolveHostMetadata() calls and unnecessary setExperimentalIsUnifiedHost(true). Co-authored-by: Isaac
1 parent 849be46 commit 884e9dd

File tree

6 files changed

+50
-33
lines changed

6 files changed

+50
-33
lines changed

databricks-sdk-java/src/main/java/com/databricks/sdk/core/DatabricksConfig.java

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -232,17 +232,13 @@ private synchronized DatabricksConfig innerResolve() {
232232
}
233233

234234
/**
235-
* Attempts to resolve host metadata from the well-known endpoint. Only called for unified hosts.
236-
* Logs a warning and continues if metadata resolution fails, since not all hosts support the
237-
* discovery endpoint.
235+
* Attempts to resolve host metadata from the well-known endpoint. Logs a warning and continues if
236+
* metadata resolution fails, since not all hosts support the discovery endpoint.
238237
*/
239238
private void tryResolveHostMetadata() {
240239
if (host == null) {
241240
return;
242241
}
243-
if (experimentalIsUnifiedHost == null || !experimentalIsUnifiedHost) {
244-
return;
245-
}
246242
try {
247243
resolveHostMetadata();
248244
} catch (Exception e) {

databricks-sdk-java/src/test/java/com/databricks/sdk/AccountClientTest.java

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,6 @@ public void testGetWorkspaceClientForUnifiedHost() {
3636
DatabricksConfig accountConfig =
3737
new DatabricksConfig()
3838
.setHost(unifiedHost)
39-
.setExperimentalIsUnifiedHost(true)
4039
.setAccountId("test-account")
4140
.setToken("test-token");
4241

@@ -64,7 +63,6 @@ public void testGetWorkspaceClientForSpogHostDoesNotMutateAccountConfig() {
6463
DatabricksConfig accountConfig =
6564
new DatabricksConfig()
6665
.setHost(spogHost)
67-
.setExperimentalIsUnifiedHost(true)
6866
.setAccountId("test-account")
6967
.setToken("test-token");
7068

databricks-sdk-java/src/test/java/com/databricks/sdk/core/DatabricksConfigTest.java

Lines changed: 25 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -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

databricks-sdk-java/src/test/java/com/databricks/sdk/core/FixtureServer.java

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -173,8 +173,11 @@ public int getRedirectStatusCode() {
173173
}
174174
}
175175

176+
private static final String WELL_KNOWN_PATH = "/.well-known/databricks-config";
177+
176178
private final HttpServer server;
177179
private final List<FixtureMapping> fixtures = new ArrayList<>();
180+
private boolean hasWellKnownFixture = false;
178181

179182
public FixtureServer() throws IOException {
180183
HttpHandler handler = new FixtureHandler();
@@ -194,6 +197,21 @@ public void handle(HttpExchange exchange) throws IOException {
194197
}
195198

196199
private void handlerInner(HttpExchange exchange) throws IOException {
200+
// Auto-stub the host metadata endpoint with 404 to prevent config resolution
201+
// from interfering with test assertions. This handles two cases:
202+
// 1. No well-known fixture registered: always auto-stub.
203+
// 2. Well-known fixtures registered but queue is empty (already consumed): auto-stub
204+
// so that repeated calls (e.g. resolve() + explicit getHostMetadata()) don't fail.
205+
if ("GET".equals(exchange.getRequestMethod())
206+
&& "/.well-known/databricks-config".equals(exchange.getRequestURI().getPath())
207+
&& (!hasWellKnownFixture || fixtures.isEmpty())) {
208+
respond(
209+
exchange,
210+
404,
211+
"{\"error_code\":\"NOT_FOUND\",\"message\":\"auto-stubbed by test framework\"}");
212+
return;
213+
}
214+
197215
if (fixtures.isEmpty()) {
198216
respondInternalServerError(exchange, "No fixtures defined");
199217
return;
@@ -245,6 +263,9 @@ private void respondRedirect(HttpExchange exchange, String location, int statusC
245263
}
246264

247265
public FixtureServer with(String method, String path, String response, int statusCode) {
266+
if (WELL_KNOWN_PATH.equals(path)) {
267+
hasWellKnownFixture = true;
268+
}
248269
FixtureMapping fixture =
249270
new FixtureMapping.Builder()
250271
.validateMethod(method)

databricks-sdk-java/src/test/java/com/databricks/sdk/core/UnifiedHostTest.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -88,11 +88,10 @@ public void testIsAccountClientForWorkspaceHost() {
8888

8989
@Test
9090
public void testIsAccountClientForNonAccountsHost() {
91-
// Non-accounts hosts are not account clients, even with experimentalIsUnifiedHost set
91+
// Non-accounts hosts are not account clients
9292
assertFalse(
9393
new DatabricksConfig()
9494
.setHost("https://mycompany.databricks.com")
95-
.setExperimentalIsUnifiedHost(true)
9695
.isAccountClient());
9796
}
9897

databricks-sdk-java/src/test/java/com/databricks/sdk/integration/HostMetadataIT.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,7 @@ public class HostMetadataIT {
2222

2323
@Test
2424
void testResolvePopulatesFieldsFromMetadata(@EnvOrSkip("DATABRICKS_HOST") String host) {
25-
DatabricksConfig config =
26-
new DatabricksConfig().setHost(host).setExperimentalIsUnifiedHost(true);
25+
DatabricksConfig config = new DatabricksConfig().setHost(host);
2726
config.resolve();
2827

2928
LOG.info(

0 commit comments

Comments
 (0)