-
Notifications
You must be signed in to change notification settings - Fork 62
feat: flagd provider creates named daemon threads for error executor #1625
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
base: main
Are you sure you want to change the base?
Changes from 2 commits
9ec5193
4a85e24
4d400c1
8a32d3b
40aab33
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 | ||||
|---|---|---|---|---|---|---|
| @@ -0,0 +1,30 @@ | ||||||
| package dev.openfeature.contrib.providers.flagd; | ||||||
|
|
||||||
| import java.util.concurrent.ThreadFactory; | ||||||
| import java.util.concurrent.atomic.AtomicInteger; | ||||||
|
|
||||||
| /** | ||||||
| * Thread factory for the Flagd provider to allow named daemon threads to be created. | ||||||
| */ | ||||||
| class FlagdThreadFactory implements ThreadFactory { | ||||||
|
|
||||||
| private final AtomicInteger counter = new AtomicInteger(); | ||||||
| private final String namePrefix; | ||||||
|
|
||||||
| /** | ||||||
| * {@link FlagdThreadFactory}'s constructor. | ||||||
| * | ||||||
| * @param namePrefix Prefix used for setting the new thread's name. | ||||||
| */ | ||||||
| FlagdThreadFactory(String namePrefix) { | ||||||
| this.namePrefix = namePrefix; | ||||||
|
||||||
| this.namePrefix = namePrefix; | |
| this.namePrefix = java.util.Objects.requireNonNull(namePrefix, "namePrefix must not be null"); |
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.
seems reasonable to me, wdyt?
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.
agree, I have added the suggestion & covering test
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,34 @@ | ||
| package dev.openfeature.contrib.providers.flagd; | ||
|
|
||
| import static org.assertj.core.api.Assertions.assertThat; | ||
|
|
||
| import org.junit.jupiter.api.Test; | ||
|
|
||
| class FlagdThreadFactoryTest { | ||
|
|
||
| private static final String THREAD_NAME = "testthread"; | ||
| private final Runnable runnable = () -> {}; | ||
|
|
||
| @Test | ||
| void verifyNewThreadHasNamePrefix() { | ||
|
|
||
| var flagdThreadFactory = new FlagdThreadFactory(THREAD_NAME); | ||
| var thread = flagdThreadFactory.newThread(runnable); | ||
|
|
||
| assertThat(thread.getName()).isEqualTo(THREAD_NAME + "-1"); | ||
| assertThat(thread.isDaemon()).isTrue(); | ||
| } | ||
|
|
||
| @Test | ||
| void verifyNewThreadHasNamePrefixWithIncrement() { | ||
|
|
||
| var flagdThreadFactory = new FlagdThreadFactory(THREAD_NAME); | ||
| var threadOne = flagdThreadFactory.newThread(runnable); | ||
| var threadTwo = flagdThreadFactory.newThread(runnable); | ||
|
|
||
| assertThat(threadOne.getName()).isEqualTo(THREAD_NAME + "-1"); | ||
| assertThat(threadOne.isDaemon()).isTrue(); | ||
| assertThat(threadTwo.getName()).isEqualTo(THREAD_NAME + "-2"); | ||
| assertThat(threadTwo.isDaemon()).isTrue(); | ||
| } | ||
| } |
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.
The string literal
"flagd-provider-thread"is duplicated on line 108. To improve maintainability and avoid magic strings, consider extracting it into aprivate static finalconstant at the class level. For example:private static final String ERROR_EXECUTOR_THREAD_NAME_PREFIX = "flagd-provider-thread";