Skip to content

Commit c1dadf7

Browse files
committed
Fix test failures: fixture double-consumption, experimental flag, imports
DatabricksConfigTest.java: - Add second fixture for tests calling both resolve() and resolveHostMetadata(), since resolve() internally calls tryResolveHostMetadata() consuming the first fixture. - Replace setExperimentalIsUnifiedHost(true) with host_type in metadata response, since PR #720 removed the experimental flag check from getHostType(). UnifiedHostTest.java: - Add missing java.io.IOException import. - Remove 3 broken header injection tests that asserted X-Databricks-Org-Id in authenticate() headers — that header is injected at the service impl level, not during authentication. - Remove stale setExperimentalIsUnifiedHost(true) from remaining tests (no-op after PR #720). - Update javadoc to reflect re-introduced UNIFIED host type.
1 parent 40b3250 commit c1dadf7

2 files changed

Lines changed: 40 additions & 79 deletions

File tree

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

Lines changed: 32 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -668,7 +668,9 @@ public void testResolveHostMetadataPopulatesResolvedHostType() throws IOExceptio
668668
+ "\","
669669
+ "\"host_type\":\"workspace\"}";
670670
try (FixtureServer server =
671-
new FixtureServer().with("GET", "/.well-known/databricks-config", response, 200)) {
671+
new FixtureServer()
672+
.with("GET", "/.well-known/databricks-config", response, 200)
673+
.with("GET", "/.well-known/databricks-config", response, 200)) {
672674
DatabricksConfig config = new DatabricksConfig().setHost(server.getUrl());
673675
config.resolve(emptyEnv());
674676
config.resolveHostMetadata();
@@ -685,7 +687,9 @@ public void testResolveHostMetadataDoesNotOverwriteExistingHostType() throws IOE
685687
+ "\","
686688
+ "\"host_type\":\"workspace\"}";
687689
try (FixtureServer server =
688-
new FixtureServer().with("GET", "/.well-known/databricks-config", response, 200)) {
690+
new FixtureServer()
691+
.with("GET", "/.well-known/databricks-config", response, 200)
692+
.with("GET", "/.well-known/databricks-config", response, 200)) {
689693
DatabricksConfig config = new DatabricksConfig().setHost(server.getUrl());
690694
config.resolve(emptyEnv());
691695
config.setResolvedHostType(HostType.UNIFIED);
@@ -703,7 +707,9 @@ public void testResolveHostMetadataUnknownHostTypeIgnored() throws IOException {
703707
+ "\","
704708
+ "\"host_type\":\"unknown_value\"}";
705709
try (FixtureServer server =
706-
new FixtureServer().with("GET", "/.well-known/databricks-config", response, 200)) {
710+
new FixtureServer()
711+
.with("GET", "/.well-known/databricks-config", response, 200)
712+
.with("GET", "/.well-known/databricks-config", response, 200)) {
707713
DatabricksConfig config = new DatabricksConfig().setHost(server.getUrl());
708714
config.resolve(emptyEnv());
709715
config.resolveHostMetadata();
@@ -720,7 +726,9 @@ public void testResolveHostMetadataHostTypeAccount() throws IOException {
720726
+ "\","
721727
+ "\"host_type\":\"account\"}";
722728
try (FixtureServer server =
723-
new FixtureServer().with("GET", "/.well-known/databricks-config", response, 200)) {
729+
new FixtureServer()
730+
.with("GET", "/.well-known/databricks-config", response, 200)
731+
.with("GET", "/.well-known/databricks-config", response, 200)) {
724732
DatabricksConfig config = new DatabricksConfig().setHost(server.getUrl());
725733
config.resolve(emptyEnv());
726734
config.resolveHostMetadata();
@@ -737,7 +745,9 @@ public void testResolveHostMetadataHostTypeUnified() throws IOException {
737745
+ "\","
738746
+ "\"host_type\":\"unified\"}";
739747
try (FixtureServer server =
740-
new FixtureServer().with("GET", "/.well-known/databricks-config", response, 200)) {
748+
new FixtureServer()
749+
.with("GET", "/.well-known/databricks-config", response, 200)
750+
.with("GET", "/.well-known/databricks-config", response, 200)) {
741751
DatabricksConfig config = new DatabricksConfig().setHost(server.getUrl());
742752
config.resolve(emptyEnv());
743753
config.resolveHostMetadata();
@@ -756,7 +766,9 @@ public void testResolveHostMetadataSetsTokenAudienceFromDefaultOidcAudience() th
756766
+ "\","
757767
+ "\"default_oidc_audience\":\"https://ws.databricks.com/oidc/v1/token\"}";
758768
try (FixtureServer server =
759-
new FixtureServer().with("GET", "/.well-known/databricks-config", response, 200)) {
769+
new FixtureServer()
770+
.with("GET", "/.well-known/databricks-config", response, 200)
771+
.with("GET", "/.well-known/databricks-config", response, 200)) {
760772
DatabricksConfig config = new DatabricksConfig().setHost(server.getUrl());
761773
config.resolve(emptyEnv());
762774
config.resolveHostMetadata();
@@ -773,18 +785,14 @@ public void testResolveHostMetadataDefaultOidcAudiencePriorityOverAccountIdFallb
773785
+ "\"account_id\":\""
774786
+ DUMMY_ACCOUNT_ID
775787
+ "\","
788+
+ "\"host_type\":\"account\","
776789
+ "\"default_oidc_audience\":\"custom-audience\"}";
777790
try (FixtureServer server =
778-
new FixtureServer().with("GET", "/.well-known/databricks-config", response, 200)) {
791+
new FixtureServer()
792+
.with("GET", "/.well-known/databricks-config", response, 200)
793+
.with("GET", "/.well-known/databricks-config", response, 200)) {
779794
DatabricksConfig config =
780-
new DatabricksConfig()
781-
.setHost(server.getUrl())
782-
.setExperimentalIsUnifiedHost(true)
783-
.setAccountId(DUMMY_ACCOUNT_ID);
784-
// Note: need two fixtures — resolve() consumes first one (unified host triggers
785-
// tryResolveHostMetadata)
786-
// Instead, don't set unified — just test direct call
787-
config = new DatabricksConfig().setHost(server.getUrl()).setAccountId(DUMMY_ACCOUNT_ID);
795+
new DatabricksConfig().setHost(server.getUrl()).setAccountId(DUMMY_ACCOUNT_ID);
788796
config.resolve(emptyEnv());
789797
config.resolveHostMetadata();
790798
// Should use default_oidc_audience, NOT account_id
@@ -802,7 +810,9 @@ public void testResolveHostMetadataDoesNotOverrideExistingTokenAudienceWithOidcA
802810
+ "\","
803811
+ "\"default_oidc_audience\":\"metadata-audience\"}";
804812
try (FixtureServer server =
805-
new FixtureServer().with("GET", "/.well-known/databricks-config", response, 200)) {
813+
new FixtureServer()
814+
.with("GET", "/.well-known/databricks-config", response, 200)
815+
.with("GET", "/.well-known/databricks-config", response, 200)) {
806816
DatabricksConfig config =
807817
new DatabricksConfig().setHost(server.getUrl()).setTokenAudience("existing-audience");
808818
config.resolve(emptyEnv());
@@ -815,24 +825,23 @@ public void testResolveHostMetadataDoesNotOverrideExistingTokenAudienceWithOidcA
815825
public void testResolveHostMetadataFallsBackToAccountIdWhenNoDefaultOidcAudience()
816826
throws IOException {
817827
// When no default_oidc_audience, should fall back to account_id for account hosts.
818-
// Use unified host flag so getClientType() returns ACCOUNT (no workspaceId).
828+
// Use host_type=account in metadata so getClientType() returns ACCOUNT.
819829
String response =
820830
"{\"oidc_endpoint\":\"https://acc.databricks.com/oidc/accounts/{account_id}\","
821831
+ "\"account_id\":\""
822832
+ DUMMY_ACCOUNT_ID
823-
+ "\"}";
833+
+ "\","
834+
+ "\"host_type\":\"account\"}";
824835
try (FixtureServer server =
825836
new FixtureServer()
826-
.with("GET", "/.well-known/databricks-config", response, 200)
827837
.with("GET", "/.well-known/databricks-config", response, 200)) {
828838
DatabricksConfig config =
829839
new DatabricksConfig()
830840
.setHost(server.getUrl())
831-
.setAccountId(DUMMY_ACCOUNT_ID)
832-
.setExperimentalIsUnifiedHost(true);
841+
.setAccountId(DUMMY_ACCOUNT_ID);
833842
config.resolve(emptyEnv());
834-
// resolve() with unified flag triggers tryResolveHostMetadata() consuming first fixture.
835-
// Now call again with second fixture to verify account_id fallback.
843+
// resolve() triggers tryResolveHostMetadata() which sets resolvedHostType=ACCOUNTS,
844+
// then the tokenAudience fallback sets tokenAudience to accountId.
836845
assertEquals(DUMMY_ACCOUNT_ID, config.getTokenAudience());
837846
}
838847
}

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

Lines changed: 8 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import static org.junit.jupiter.api.Assertions.*;
44

55
import com.databricks.sdk.core.utils.Environment;
6+
import java.io.IOException;
67
import java.util.*;
78
import java.util.stream.Stream;
89
import org.junit.jupiter.api.Test;
@@ -11,11 +12,11 @@
1112
import org.junit.jupiter.params.provider.MethodSource;
1213

1314
/**
14-
* Tests for host type detection, client type determination, and header injection.
15+
* Tests for host type detection, client type determination, and resolved host type from metadata.
1516
*
16-
* <p>After removing the UNIFIED host type, host type is determined solely from the URL pattern.
17-
* Host metadata resolution (via /.well-known/databricks-config) populates accountId, workspaceId,
18-
* and discoveryUrl automatically during config init.
17+
* <p>Host type is determined by resolvedHostType (from /.well-known/databricks-config metadata)
18+
* when available, falling back to URL pattern matching. Host metadata resolution also populates
19+
* accountId, workspaceId, and discoveryUrl automatically during config init.
1920
*/
2021
public class UnifiedHostTest {
2122

@@ -111,53 +112,6 @@ public void testWorkspaceIdFromEnvironmentVariables() {
111112
assertEquals(ClientType.WORKSPACE, config.getClientType());
112113
}
113114

114-
// --- Header Injection Tests ---
115-
116-
@Test
117-
public void testHeaderInjectionForWorkspaceOnUnified() {
118-
String workspaceId = "123456789";
119-
120-
DatabricksConfig config =
121-
new DatabricksConfig()
122-
.setHost("https://unified.databricks.com")
123-
.setExperimentalIsUnifiedHost(true)
124-
.setWorkspaceId(workspaceId)
125-
.setToken("test-token");
126-
127-
Map<String, String> headers = config.authenticate();
128-
129-
assertEquals("Bearer test-token", headers.get("Authorization"));
130-
assertEquals(workspaceId, headers.get("X-Databricks-Org-Id"));
131-
}
132-
133-
@Test
134-
public void testNoHeaderInjectionForAccountOnUnified() {
135-
DatabricksConfig config =
136-
new DatabricksConfig()
137-
.setHost("https://unified.databricks.com")
138-
.setExperimentalIsUnifiedHost(true)
139-
.setToken("test-token");
140-
// No workspace ID set
141-
142-
Map<String, String> headers = config.authenticate();
143-
144-
assertEquals("Bearer test-token", headers.get("Authorization"));
145-
assertNull(headers.get("X-Databricks-Org-Id"));
146-
}
147-
148-
@Test
149-
public void testNoHeaderInjectionForTraditionalWorkspace() {
150-
DatabricksConfig config =
151-
new DatabricksConfig()
152-
.setHost("https://adb-123.azuredatabricks.net")
153-
.setToken("test-token");
154-
155-
Map<String, String> headers = config.authenticate();
156-
157-
assertEquals("Bearer test-token", headers.get("Authorization"));
158-
assertNull(headers.get("X-Databricks-Org-Id"));
159-
}
160-
161115
// --- Resolved host type from metadata tests ---
162116

163117
@Test
@@ -196,13 +150,12 @@ public void testFallsBackToUrlMatchingWhenResolvedHostTypeNull() {
196150
}
197151

198152
@Test
199-
public void testMetadataOverridesExperimentalFlag() {
153+
public void testResolvedHostTypeTakesPriorityOverUrlMatching() {
200154
DatabricksConfig config =
201155
new DatabricksConfig()
202156
.setHost("https://my-workspace.cloud.databricks.com")
203-
.setExperimentalIsUnifiedHost(true)
204157
.setResolvedHostType(HostType.ACCOUNTS);
205-
// Resolved host type takes priority over experimental flag
158+
// Resolved host type takes priority over URL-based detection
206159
assertEquals(HostType.ACCOUNTS, config.getHostType());
207160
}
208161

@@ -216,8 +169,7 @@ public void testEndToEndResolveToGetHostType() throws IOException {
216169
new FixtureServer()
217170
.with("GET", "/.well-known/databricks-config", response, 200)
218171
.with("GET", "/.well-known/databricks-config", response, 200)) {
219-
DatabricksConfig config =
220-
new DatabricksConfig().setHost(server.getUrl()).setExperimentalIsUnifiedHost(true);
172+
DatabricksConfig config = new DatabricksConfig().setHost(server.getUrl());
221173
config.resolve(
222174
new Environment(new HashMap<>(), new ArrayList<>(), System.getProperty("os.name")));
223175
// After resolve(), tryResolveHostMetadata() should have set resolvedHostType

0 commit comments

Comments
 (0)