-
Notifications
You must be signed in to change notification settings - Fork 141
feat: support setting core pool size for async API in system property #2632
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -63,6 +63,7 @@ | |
| import java.util.HashMap; | ||
| import java.util.List; | ||
| import java.util.Map; | ||
| import java.util.concurrent.Callable; | ||
| import java.util.concurrent.ScheduledExecutorService; | ||
| import javax.annotation.Nonnull; | ||
| import org.junit.Test; | ||
|
|
@@ -913,6 +914,62 @@ public void testCustomAsyncExecutorProvider() { | |
| assertSame(service, options.getAsyncExecutorProvider().getExecutor()); | ||
| } | ||
|
|
||
| @Test | ||
| public void testAsyncExecutorProviderCoreThreadCount() throws Exception { | ||
| assertEquals(8, SpannerOptions.getDefaultAsyncExecutorProviderCoreThreadCount()); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nit: Should we add a check to ensure that the system property was originally unset? Or maybe explicitly set the property to null?
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I see that there is a handling of this scenario within the
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I added a test for both |
||
| String propertyName = "SPANNER_ASYNC_NUM_CORE_THREADS"; | ||
| assertEquals( | ||
| Integer.valueOf(8), | ||
| runWithSystemProperty( | ||
| propertyName, null, SpannerOptions::getDefaultAsyncExecutorProviderCoreThreadCount)); | ||
| assertEquals( | ||
| Integer.valueOf(16), | ||
| runWithSystemProperty( | ||
| propertyName, "16", SpannerOptions::getDefaultAsyncExecutorProviderCoreThreadCount)); | ||
| assertEquals( | ||
| Integer.valueOf(1), | ||
| runWithSystemProperty( | ||
| propertyName, "1", SpannerOptions::getDefaultAsyncExecutorProviderCoreThreadCount)); | ||
| assertThrows( | ||
| SpannerException.class, | ||
| () -> | ||
| runWithSystemProperty( | ||
| propertyName, | ||
| "foo", | ||
| SpannerOptions::getDefaultAsyncExecutorProviderCoreThreadCount)); | ||
| assertThrows( | ||
| SpannerException.class, | ||
| () -> | ||
| runWithSystemProperty( | ||
| propertyName, | ||
| "-1", | ||
| SpannerOptions::getDefaultAsyncExecutorProviderCoreThreadCount)); | ||
| assertThrows( | ||
| SpannerException.class, | ||
| () -> | ||
| runWithSystemProperty( | ||
| propertyName, "", SpannerOptions::getDefaultAsyncExecutorProviderCoreThreadCount)); | ||
| } | ||
|
|
||
| static <V> V runWithSystemProperty( | ||
| String propertyName, String propertyValue, Callable<V> callable) throws Exception { | ||
| String currentValue = System.getProperty(propertyName); | ||
| if (propertyValue == null) { | ||
| System.clearProperty(propertyName); | ||
| } else { | ||
| System.setProperty(propertyName, propertyValue); | ||
| } | ||
| try { | ||
| return callable.call(); | ||
| } finally { | ||
| if (currentValue == null) { | ||
| System.clearProperty(propertyName); | ||
| } else { | ||
| System.setProperty(propertyName, currentValue); | ||
| } | ||
| } | ||
| } | ||
|
|
||
| @Test | ||
| public void testDefaultNumChannelsWithGrpcGcpExtensionEnabled() { | ||
| SpannerOptions options = | ||
|
|
||
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.
magic string!
should we maintain list of constants/enums property names?