File tree Expand file tree Collapse file tree 4 files changed +19
-8
lines changed
bosk-mongo/src/main/java/works/bosk/drivers/mongo/internal
bosk-testing/src/main/java/works/bosk/testing/drivers Expand file tree Collapse file tree 4 files changed +19
-8
lines changed Original file line number Diff line number Diff line change @@ -87,9 +87,13 @@ public class Bosk<R extends StateTreeNode> implements BoskInfo<R> {
8787 private final ThreadLocal <R > rootSnapshot = new ThreadLocal <>();
8888 private final HookRegistrar hookRegistrar ;
8989 private final Queue <HookRegistration <?>> hooks = new ConcurrentLinkedQueue <>();
90- private final ExecutorService hookExecutor = Executors .newVirtualThreadPerTaskExecutor ();
9190 private final PathCompiler pathCompiler ;
9291
92+ private final Thread .Builder hookThreadBuilder = Thread
93+ .ofVirtual ()
94+ .name ("bosk-hook-" , 1 );
95+ private final ExecutorService hookExecutor = Executors .newThreadPerTaskExecutor (hookThreadBuilder ::unstarted );
96+
9397 // Mutable state
9498 private volatile R currentRoot ;
9599
Original file line number Diff line number Diff line change 1010import java .util .function .Consumer ;
1111import org .junit .jupiter .api .BeforeEach ;
1212import org .junit .jupiter .api .Test ;
13+ import org .junit .jupiter .api .TestInfo ;
1314import org .junit .jupiter .params .ParameterizedTest ;
1415import org .junit .jupiter .params .provider .EnumSource ;
1516import org .junit .jupiter .params .provider .ValueSource ;
1617import works .bosk .annotations .Hook ;
1718import works .bosk .annotations .ReferencePath ;
1819import works .bosk .exceptions .InvalidTypeException ;
1920
21+ import static java .lang .Thread .currentThread ;
2022import static java .util .Arrays .asList ;
2123import static java .util .Collections .emptyList ;
2224import static java .util .Collections .singletonList ;
@@ -64,6 +66,11 @@ void setupBosk() throws InvalidTypeException {
6466 recorder = new HookRecorder ();
6567 }
6668
69+ @ BeforeEach
70+ void setThreadName (TestInfo testInfo ) {
71+ currentThread ().setName ("test: " + testInfo .getDisplayName ());
72+ }
73+
6774 @ ParameterizedTest
6875 @ EnumSource (Variant .class )
6976 void beforeRegistration_noHooks (Variant variant ) {
Original file line number Diff line number Diff line change @@ -55,7 +55,8 @@ class ChangeReceiver implements Closeable {
5555 private final ChangeListener listener ;
5656 private final MongoDriverSettings settings ;
5757 private final MongoCollection <BsonDocument > collection ;
58- private final ScheduledExecutorService ex = Executors .newScheduledThreadPool (1 );
58+ private final Thread .Builder threadBuilder = Thread .ofPlatform ().name ("bosk-mongo-change-receiver" );
59+ private final ScheduledExecutorService ex = Executors .newScheduledThreadPool (1 , threadBuilder ::unstarted );
5960 private final Exception creationPoint ;
6061 private volatile @ Nullable Thread thread = null ;
6162 private volatile boolean isClosed = false ;
@@ -124,8 +125,6 @@ public void close() {
124125 * around the loop.
125126 */
126127 private void connectionLoop () {
127- String oldThreadName = currentThread ().getName ();
128- currentThread ().setName (getClass ().getSimpleName () + " [" + boskName + "]" );
129128 try (MDCScope _ = setupMDC (boskName , boskID )) {
130129 LOGGER .debug ("Starting connectionLoop task" );
131130 try {
@@ -217,7 +216,6 @@ private void connectionLoop() {
217216 }
218217 } finally {
219218 LOGGER .debug ("Ending connectionLoop task; isClosed={}" , isClosed );
220- currentThread ().setName (oldThreadName );
221219 thread = null ;
222220 }
223221 } catch (RuntimeException e ) {
Original file line number Diff line number Diff line change @@ -36,15 +36,17 @@ public abstract class AbstractDriverTest {
3636
3737 @ BeforeEach
3838 void logStart (TestInfo testInfo ) {
39- logTest ("/=== Start" , testInfo );
4039 oldThreadName = Thread .currentThread ().getName ();
41- Thread .currentThread ().setName (testInfo .getDisplayName ());
40+ String newThreadName = "test: " + testInfo .getDisplayName ();
41+ Thread .currentThread ().setName (newThreadName );
42+ logTest ("/=== Start" , testInfo );
43+ LOGGER .debug ("Old thread name was {}" , oldThreadName );
4244 }
4345
4446 @ AfterEach
4547 void logDone (TestInfo testInfo ) {
46- Thread .currentThread ().setName (oldThreadName );
4748 logTest ("\\ === Done" , testInfo );
49+ Thread .currentThread ().setName (oldThreadName );
4850 }
4951
5052 private static void logTest (String verb , TestInfo testInfo ) {
You can’t perform that action at this time.
0 commit comments