3
3
import io .arex .agent .bootstrap .constants .ConfigConstants ;
4
4
import io .arex .agent .bootstrap .util .ConcurrentHashSet ;
5
5
import io .arex .inst .runtime .context .RecordLimiter ;
6
+ import io .arex .inst .runtime .listener .EventProcessor ;
6
7
import io .arex .inst .runtime .model .ArexConstants ;
7
8
import io .arex .inst .runtime .model .DynamicClassEntity ;
8
9
import java .util .Arrays ;
9
10
import java .util .HashSet ;
10
11
import java .util .List ;
12
+
13
+ import org .junit .jupiter .api .AfterAll ;
11
14
import org .junit .jupiter .api .Assertions ;
15
+ import org .junit .jupiter .api .BeforeAll ;
12
16
import org .junit .jupiter .api .Test ;
13
17
import org .junit .jupiter .params .ParameterizedTest ;
14
18
import org .junit .jupiter .params .provider .Arguments ;
15
19
import org .junit .jupiter .params .provider .MethodSource ;
20
+ import org .mockito .MockedStatic ;
21
+ import org .mockito .Mockito ;
16
22
17
23
import java .util .function .Predicate ;
18
24
import java .util .stream .Stream ;
21
27
import static org .junit .jupiter .params .provider .Arguments .arguments ;
22
28
23
29
class ConfigTest {
30
+ @ BeforeAll
31
+ static void setUp () {
32
+ Mockito .mockStatic (EventProcessor .class );
33
+ }
34
+
35
+ @ AfterAll
36
+ static void tearDown () {
37
+ Mockito .clearAllCaches ();
38
+ }
24
39
25
40
@ ParameterizedTest
26
41
@ MethodSource ("invalidCase" )
@@ -32,27 +47,38 @@ void invalidRecord(Runnable mocker, Predicate<Boolean> predicate) {
32
47
static Stream <Arguments > invalidCase () {
33
48
ConfigBuilder config = ConfigBuilder .create ("mock" );
34
49
Runnable mocker1 = () -> {
50
+ Mockito .when (EventProcessor .dependencyInitComplete ()).thenReturn (true );
35
51
config .addProperty (ConfigConstants .STORAGE_SERVICE_MODE , "local" ).build ();;
36
52
};
37
53
Runnable mocker2 = () -> {
54
+ Mockito .when (EventProcessor .dependencyInitComplete ()).thenReturn (true );
38
55
config .addProperty (ConfigConstants .STORAGE_SERVICE_MODE , "" ).build ();;
39
56
config .recordRate (0 ).build ();
40
57
};
41
58
Runnable mocker3 = () -> {
59
+ Mockito .when (EventProcessor .dependencyInitComplete ()).thenReturn (true );
42
60
config .recordRate (1 ).build ();
43
61
};
44
62
Runnable mocker4 = () -> {
63
+ Mockito .when (EventProcessor .dependencyInitComplete ()).thenReturn (true );
45
64
config .addProperty (ConfigConstants .DURING_WORK , "true" ).build ();;
46
65
};
47
66
Runnable mocker5 = () -> {
67
+ Mockito .when (EventProcessor .dependencyInitComplete ()).thenReturn (true );
48
68
config .addProperty (ConfigConstants .AGENT_ENABLED , "true" ).build ();
49
69
RecordLimiter .init (mock -> true );
50
70
};
51
71
Runnable disableRecord = () -> {
72
+ Mockito .when (EventProcessor .dependencyInitComplete ()).thenReturn (true );
52
73
config .addProperty (ConfigConstants .DISABLE_RECORD , "true" ).build ();;
53
74
RecordLimiter .init (mock -> true );
54
75
};
55
76
77
+ Runnable dependencyNotInitComplete = () -> {
78
+ Mockito .when (EventProcessor .dependencyInitComplete ()).thenReturn (false );
79
+ config .build ();;
80
+ };
81
+
56
82
Predicate <Boolean > assertFalse = result -> !result ;
57
83
Predicate <Boolean > assertTrue = result -> result ;
58
84
return Stream .of (
@@ -61,7 +87,8 @@ static Stream<Arguments> invalidCase() {
61
87
arguments (mocker3 , assertTrue ),
62
88
arguments (mocker4 , assertTrue ),
63
89
arguments (mocker5 , assertFalse ),
64
- arguments (disableRecord , assertTrue )
90
+ arguments (disableRecord , assertTrue ),
91
+ arguments (dependencyNotInitComplete , assertTrue )
65
92
);
66
93
}
67
94
0 commit comments