-
Notifications
You must be signed in to change notification settings - Fork 25
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Fix] Make UserAgent
's otherInfo
thread-safe
#357
Merged
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
13 changes: 13 additions & 0 deletions
13
databricks-sdk-java/src/test/java/com/databricks/sdk/benchmark/README.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
# Benchmark Tests | ||
|
||
The tests defined in this module are benchmarks of the Databricks SDK and its internal components. These tests ensure that the SDK works correctly and with reasonable performance under high load and concurrency. These tests are not run in normal CI builds to prevent regularly exhausting the REST API rate limit. | ||
|
||
Load tests of components that don't make any network requests (e.g. `UserAgentLoadTest`) should be colocated with the unit tests for that component. | ||
|
||
## Adding a Benchmark Test | ||
|
||
All test files in this module should be named `*LoadIT.java`. They should be written as integration tests, with the `@EnvContext()` and `@ExtendWith(EnvTest.class)` annotations. | ||
|
||
## Running the Benchmarks | ||
|
||
Use [IntelliJ's built-in test runner](https://www.jetbrains.com/help/idea/performing-tests.html) to run benchmark tests. |
84 changes: 84 additions & 0 deletions
84
databricks-sdk-java/src/test/java/com/databricks/sdk/benchmark/WorkspaceClientLoadIT.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
package com.databricks.sdk.benchmark; | ||
|
||
import static org.junit.jupiter.api.Assertions.assertEquals; | ||
|
||
import com.databricks.sdk.WorkspaceClient; | ||
import com.databricks.sdk.core.DatabricksConfig; | ||
import com.databricks.sdk.integration.framework.EnvContext; | ||
import com.databricks.sdk.integration.framework.EnvOrSkip; | ||
import com.databricks.sdk.integration.framework.EnvTest; | ||
import java.util.ArrayList; | ||
import java.util.List; | ||
import java.util.concurrent.*; | ||
import org.junit.jupiter.api.Test; | ||
import org.junit.jupiter.api.extension.ExtendWith; | ||
|
||
/** | ||
* This test executes a simple operation 150 times concurrently to verify that the end-to-end | ||
* behavior of the SDK is correct under concurrent load. This test is designed to be run manually | ||
* rather than being included in CI processes, as it generates a large number of requests. | ||
*/ | ||
@EnvContext("workspace") | ||
@ExtendWith(EnvTest.class) | ||
public class WorkspaceClientLoadIT { | ||
|
||
@Test | ||
public void testConcurrentCurrentUserMe( | ||
@EnvOrSkip("DATABRICKS_HOST") String host, | ||
@EnvOrSkip("DATABRICKS_CLIENT_ID") String clientId, | ||
@EnvOrSkip("DATABRICKS_CLIENT_SECRET") String clientSecret) | ||
throws Exception { | ||
int numThreads = 150; | ||
ExecutorService executorService = Executors.newFixedThreadPool(numThreads); | ||
List<Future<Boolean>> futures = new ArrayList<>(); | ||
int successCount = 0; | ||
int failureCount = 0; | ||
|
||
Callable<Boolean> task = | ||
() -> { | ||
try { | ||
DatabricksConfig config = | ||
new DatabricksConfig() | ||
.setHost(host) | ||
.setClientId(clientId) | ||
.setClientSecret(clientSecret); | ||
|
||
WorkspaceClient w = new WorkspaceClient(config); | ||
|
||
// This should not throw an exception. | ||
w.currentUser().me(); | ||
|
||
return true; | ||
} catch (Exception e) { | ||
System.err.println( | ||
"DatabricksException occurred in thread " + Thread.currentThread().getName()); | ||
e.printStackTrace(); | ||
return false; | ||
} | ||
}; | ||
|
||
for (int i = 0; i < numThreads; i++) { | ||
futures.add(executorService.submit(task)); | ||
} | ||
|
||
executorService.shutdown(); | ||
if (!executorService.awaitTermination(60, TimeUnit.SECONDS)) { | ||
executorService.shutdownNow(); | ||
} | ||
|
||
for (Future<Boolean> future : futures) { | ||
if (future.get()) { | ||
successCount++; | ||
} else { | ||
failureCount++; | ||
} | ||
} | ||
|
||
// Log the results | ||
System.out.println("Number of successful threads: " + successCount); | ||
System.out.println("Number of failed threads: " + failureCount); | ||
|
||
// Optionally, you can assert that there were no failures | ||
assertEquals(0, failureCount); | ||
} | ||
} |
64 changes: 64 additions & 0 deletions
64
databricks-sdk-java/src/test/java/com/databricks/sdk/core/UserAgentLoadTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
package com.databricks.sdk.core; | ||
|
||
import static org.junit.jupiter.api.Assertions.assertEquals; | ||
|
||
import java.util.ArrayList; | ||
import java.util.List; | ||
import java.util.concurrent.*; | ||
import org.junit.jupiter.api.Test; | ||
|
||
/** | ||
* Load tests for the UserAgent class. | ||
* | ||
* <p>This is not part of the benchmark module because it doesn't make any network requests. | ||
*/ | ||
public class UserAgentLoadTest { | ||
|
||
@Test | ||
public void testAsStringConcurrent() throws InterruptedException, ExecutionException { | ||
int numThreads = 200; | ||
ExecutorService executorService = Executors.newFixedThreadPool(numThreads); | ||
List<Future<Boolean>> futures = new ArrayList<>(); | ||
int successCount = 0; | ||
int failureCount = 0; | ||
|
||
// Add some user agent info | ||
Callable<Boolean> task = | ||
() -> { | ||
try { | ||
UserAgent.withOtherInfo("key1", "value1"); | ||
UserAgent.asString(); | ||
return true; | ||
} catch (Exception e) { | ||
System.err.println( | ||
"DatabricksException occurred in thread " + Thread.currentThread().getName()); | ||
e.printStackTrace(); | ||
return false; | ||
} | ||
}; | ||
|
||
for (int i = 0; i < numThreads; i++) { | ||
futures.add(executorService.submit(task)); | ||
} | ||
|
||
executorService.shutdown(); | ||
if (!executorService.awaitTermination(60, TimeUnit.SECONDS)) { | ||
executorService.shutdownNow(); | ||
} | ||
|
||
for (Future<Boolean> future : futures) { | ||
if (future.get()) { | ||
successCount++; | ||
} else { | ||
failureCount++; | ||
} | ||
} | ||
|
||
// Log the results | ||
System.out.println("Number of successful threads: " + successCount); | ||
System.out.println("Number of failed threads: " + failureCount); | ||
|
||
// Optionally, you can assert that there were no failures | ||
assertEquals(0, failureCount); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Much better! :)