Commit 66c0599
Add changes for Kill switch integration for SEA rollout (#1067)
## Description
Added changes to integrate with Kill Switch to prepare for SEA rollout.
Changes include lazy evaluation of clientType to cover different
scenarios for Thrift vs SEA rollout
This PR also adds comprehensive test coverage for the lazy clientType
inference feature. The implementation makes
clientType evaluation lazy using a Supplier pattern, avoiding
unnecessary feature flag service calls during connection parsing.
Test Coverage Added
Total: 32 new tests across 4 test files (101 tests run, all passing ✅)
1. DatabricksConnectionContextTest (+15 tests)
Added comprehensive tests for lazy clientType inference and decision
logic:
Lazy Initialization Tests:
- Caching behavior verification - ensures clientType is computed once
and cached
- Thread safety validation - concurrent access returns consistent
results
Client Type Selection Logic:
- Explicit useThriftClient parameter handling (0 and 1 values)
- Arrow disabled scenarios (forces THRIFT)
- CloudFetch disabled scenarios (forces THRIFT)
- Combined Arrow + CloudFetch disabled scenarios
Feature Flag Integration:
- Feature flag enabled → SEA client
- Feature flag disabled → THRIFT client
- Invalid feature flag values → safe default (THRIFT)
- Empty feature flag values → safe default (THRIFT)
- Missing feature flag → safe default (THRIFT)
Override Behavior:
- setClientType() before first access
- setClientType() after lazy evaluation
Parameterized Decision Matrix:
- Comprehensive test covering all combinations of:
- AllPurposeCluster vs Warehouse
- useThriftClient (null/0/1)
- enableArrow (0/1)
- enableCloudFetch (0/1)
- Feature flag state (true/false)
- 10 different scenarios validated
2. DatabricksSessionTest (+2 tests)
Session-level integration tests:
- Session opens correctly with lazy SEA client type
- Session opens correctly with lazy THRIFT client type for clusters
3. DatabricksDriverFeatureFlagsContextFactoryTest (NEW FILE, 8 tests)
Factory pattern and workspace isolation tests:
- Singleton pattern per workspace validation
- Different workspaces get isolated contexts
- Reference counting increments/decrements correctly
- Context persists until last reference removed
- Null safety handling
- Flag sharing across connections to same workspace
- Flag isolation across different workspaces
4. DatabricksDriverFeatureFlagsContextTest (+7 tests)
Additional feature flag integration tests:
- SQL exec flag specific handling
- Multiple feature flags in response parsing
- HTTP error handling (404, 403, 503)
- Case-sensitive flag name matching
Code Fixes
1. DatabricksConnectionContext.java
Fixed getClientTypeFromContext() to remove premature default value
check:
- Before: The method was checking getParameter(USE_THRIFT_CLIENT) which
returns default value "1", causing it to always return THRIFT before
checking feature flags
- After: Removed the redundant default check, allowing feature flag
evaluation when user hasn't explicitly set useThriftClient
- Impact: Feature flags can now properly control SEA client enablement
when prerequisites (Arrow, CloudFetch) are met
2. DatabricksDriverFeatureFlagsContextFactory.java
Made setFeatureFlagsContext() method public:
- Already marked @VisibleForTesting
- Needed for test mocking and validation
- Allows tests to inject feature flag values for deterministic testing
Test Coverage Highlights
What's Tested ✅
1. Lazy Evaluation: ClientType is not computed during connection parsing
2. Thread Safety: Concurrent access to getClientType() is safe and
consistent
3. Caching: Once computed, clientType is cached and reused
4. Decision Logic: All branches of clientType selection are covered
5. Feature Flag Integration: All feature flag states
(enabled/disabled/invalid/missing) are tested
6. Error Handling: HTTP errors, malformed responses, and edge cases
default to safe behavior
7. Workspace Isolation: Feature flags are properly isolated per
workspace
8. Reference Counting: Factory correctly manages context lifecycle
Decision Matrix Validated
| Cluster Type | useThrift | Arrow | CloudFetch | FeatureFlag | Expected
|
|--------------|-----------|-------|------------|-------------|----------|
| APC | * | * | * | * | THRIFT |
| Warehouse | 1 | * | * | * | THRIFT |
| Warehouse | 0 | * | * | * | SEA |
| Warehouse | null | 0 | * | * | THRIFT |
| Warehouse | null | * | 0 | * | THRIFT |
| Warehouse | null | 1 | 1 | true | SEA |
| Warehouse | null | 1 | 1 | false | THRIFT |
## Testing
<!-- Describe how the changes have been tested-->
mvn test
-Dtest=DatabricksConnectionContextTest,DatabricksSessionTest,DatabricksDriverFeatureFlagsContextTest,DatabricksDriverFeatureFlagsContextFactoryTest
Result: All 101 tests passing ✅
## Additional Notes to the Reviewer
<!-- Share any additional context or insights that may help the reviewer
understand the changes better. This could include challenges faced,
limitations, or compromises made during the development process.
Also, mention any areas of the code that you would like the reviewer to
focus on specifically. -->
---------
Co-authored-by: Claude <noreply@anthropic.com>1 parent 9fc7490 commit 66c0599
10 files changed
Lines changed: 716 additions & 20 deletions
File tree
- src
- main/java/com/databricks/jdbc
- api/impl
- common
- safe
- test/java/com/databricks/jdbc
- api/impl
- common/safe
- telemetry
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
3 | 3 | | |
4 | 4 | | |
5 | 5 | | |
| 6 | + | |
6 | 7 | | |
7 | 8 | | |
8 | 9 | | |
| |||
Lines changed: 48 additions & 7 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
10 | 10 | | |
11 | 11 | | |
12 | 12 | | |
| 13 | + | |
13 | 14 | | |
14 | 15 | | |
15 | 16 | | |
| |||
23 | 24 | | |
24 | 25 | | |
25 | 26 | | |
| 27 | + | |
26 | 28 | | |
27 | 29 | | |
28 | 30 | | |
| |||
34 | 36 | | |
35 | 37 | | |
36 | 38 | | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
37 | 43 | | |
38 | 44 | | |
39 | 45 | | |
40 | 46 | | |
41 | 47 | | |
42 | 48 | | |
43 | | - | |
| 49 | + | |
44 | 50 | | |
45 | 51 | | |
46 | 52 | | |
| |||
59 | 65 | | |
60 | 66 | | |
61 | 67 | | |
62 | | - | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
63 | 80 | | |
64 | 81 | | |
65 | 82 | | |
| |||
422 | 439 | | |
423 | 440 | | |
424 | 441 | | |
425 | | - | |
426 | | - | |
| 442 | + | |
| 443 | + | |
| 444 | + | |
| 445 | + | |
| 446 | + | |
| 447 | + | |
| 448 | + | |
| 449 | + | |
| 450 | + | |
| 451 | + | |
| 452 | + | |
| 453 | + | |
| 454 | + | |
| 455 | + | |
| 456 | + | |
| 457 | + | |
427 | 458 | | |
428 | 459 | | |
429 | | - | |
| 460 | + | |
| 461 | + | |
| 462 | + | |
| 463 | + | |
| 464 | + | |
| 465 | + | |
| 466 | + | |
430 | 467 | | |
431 | 468 | | |
432 | 469 | | |
433 | 470 | | |
434 | | - | |
| 471 | + | |
435 | 472 | | |
436 | 473 | | |
437 | 474 | | |
438 | | - | |
| 475 | + | |
439 | 476 | | |
440 | 477 | | |
441 | 478 | | |
| |||
1036 | 1073 | | |
1037 | 1074 | | |
1038 | 1075 | | |
| 1076 | + | |
| 1077 | + | |
| 1078 | + | |
| 1079 | + | |
1039 | 1080 | | |
1040 | 1081 | | |
1041 | 1082 | | |
| |||
Lines changed: 18 additions & 11 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
62 | 62 | | |
63 | 63 | | |
64 | 64 | | |
65 | | - | |
66 | | - | |
67 | | - | |
68 | | - | |
69 | | - | |
70 | | - | |
71 | | - | |
72 | | - | |
73 | | - | |
74 | | - | |
75 | | - | |
76 | 65 | | |
77 | 66 | | |
| 67 | + | |
| 68 | + | |
78 | 69 | | |
79 | 70 | | |
80 | 71 | | |
| |||
139 | 130 | | |
140 | 131 | | |
141 | 132 | | |
| 133 | + | |
| 134 | + | |
| 135 | + | |
| 136 | + | |
| 137 | + | |
| 138 | + | |
| 139 | + | |
| 140 | + | |
| 141 | + | |
| 142 | + | |
| 143 | + | |
| 144 | + | |
| 145 | + | |
| 146 | + | |
| 147 | + | |
| 148 | + | |
142 | 149 | | |
143 | 150 | | |
144 | 151 | | |
| |||
Lines changed: 1 addition & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
172 | 172 | | |
173 | 173 | | |
174 | 174 | | |
| 175 | + | |
175 | 176 | | |
176 | 177 | | |
177 | 178 | | |
| |||
Lines changed: 2 additions & 2 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
63 | 63 | | |
64 | 64 | | |
65 | 65 | | |
66 | | - | |
| 66 | + | |
67 | 67 | | |
68 | 68 | | |
69 | 69 | | |
| |||
73 | 73 | | |
74 | 74 | | |
75 | 75 | | |
76 | | - | |
| 76 | + | |
77 | 77 | | |
78 | 78 | | |
0 commit comments