17
17
import io .kubernetes .client .informer .cache .Indexer ;
18
18
import io .kubernetes .client .openapi .models .V1Pod ;
19
19
import io .kubernetes .client .openapi .models .V1PodList ;
20
+ import io .kubernetes .client .util .Threads ;
21
+ import java .util .concurrent .Executors ;
22
+ import java .util .concurrent .ThreadFactory ;
20
23
import java .util .function .BiConsumer ;
21
24
import org .junit .Rule ;
22
25
import org .junit .Test ;
23
26
import org .mockito .Mock ;
24
27
import org .mockito .junit .MockitoJUnit ;
25
28
import org .mockito .junit .MockitoRule ;
26
29
30
+ import static org .mockito .ArgumentMatchers .any ;
31
+ import static org .mockito .Mockito .verify ;
32
+ import static org .mockito .Mockito .verifyNoMoreInteractions ;
33
+ import static org .mockito .Mockito .when ;
34
+
27
35
public class DefaultSharedIndexInformerTest {
28
36
29
37
private static final Class <V1Pod > anyApiType = V1Pod .class ;
@@ -35,6 +43,25 @@ public class DefaultSharedIndexInformerTest {
35
43
@ Mock private DeltaFIFO deltaFIFOMock ;
36
44
@ Mock private Indexer <V1Pod > indexerMock ;
37
45
@ Mock private BiConsumer <Class <V1Pod >, Throwable > exceptionHandler ;
46
+ @ Mock private ThreadFactory threadFactory ;
47
+ @ Mock private Thread thread ;
48
+
49
+ @ Test
50
+ public void testConstructorUsesDefaultThreadFactory () {
51
+ when (threadFactory .newThread (any ())).thenReturn (thread );
52
+
53
+ try {
54
+ Threads .setDefaultThreadFactory (threadFactory );
55
+ new DefaultSharedIndexInformer <>(
56
+ anyApiType , listerWatcher , anyResyncPeriod , deltaFIFOMock , indexerMock , exceptionHandler );
57
+ } finally { // revert to default
58
+ Threads .setDefaultThreadFactory (Executors .defaultThreadFactory ());
59
+ }
60
+
61
+ verify (threadFactory ).newThread (any ());
62
+ verify (thread ).setName ("informer-controller-V1Pod" );
63
+ verifyNoMoreInteractions (threadFactory , thread );
64
+ }
38
65
39
66
@ Test
40
67
public void testConstructorWithExceptionHandlerExists () {
0 commit comments