33
33
import org .mockito .junit .jupiter .MockitoExtension ;
34
34
35
35
import static org .mockito .ArgumentMatchers .any ;
36
- import static org .mockito .Mockito .RETURNS_DEEP_STUBS ;
37
36
import static org .mockito .Mockito .mock ;
38
37
import static org .mockito .Mockito .times ;
39
38
import static org .mockito .Mockito .verify ;
@@ -47,10 +46,14 @@ class ComputeNodeOnlineHandlerTest {
47
46
@ Mock (answer = Answers .RETURNS_DEEP_STUBS )
48
47
private ContextManager contextManager ;
49
48
49
+ @ Mock (answer = Answers .RETURNS_DEEP_STUBS )
50
+ private ClusterPersistServiceFacade clusterPersistServiceFacade ;
51
+
50
52
@ BeforeEach
51
53
void setUp () {
52
54
handler = ShardingSphereServiceLoader .getServiceInstances (GlobalDataChangedEventHandler .class ).stream ()
53
55
.filter (each -> NodePathGenerator .toPath (each .getSubscribedNodePath ()).equals ("/nodes/compute_nodes/online" )).findFirst ().orElse (null );
56
+ when (contextManager .getPersistServiceFacade ().getModeFacade ()).thenReturn (clusterPersistServiceFacade );
54
57
}
55
58
56
59
@ Test
@@ -62,9 +65,7 @@ void assertHandleWithInvalidInstanceOnlinePath() {
62
65
@ Test
63
66
void assertHandleWithInstanceOnlineEvent () {
64
67
ComputeNodeInstance computeNodeInstance = mock (ComputeNodeInstance .class );
65
- ClusterPersistServiceFacade clusterPersistServiceFacade = mock (ClusterPersistServiceFacade .class , RETURNS_DEEP_STUBS );
66
68
when (clusterPersistServiceFacade .getComputeNodeService ().loadInstance (any ())).thenReturn (computeNodeInstance );
67
- when (contextManager .getPersistServiceFacade ().getModeFacade ()).thenReturn (clusterPersistServiceFacade );
68
69
handler .handle (contextManager , new DataChangedEvent ("/nodes/compute_nodes/online/proxy/foo_instance_id" , "{attribute: 127.0.0.1@3307,version: 1}" , Type .ADDED ));
69
70
verify (contextManager .getComputeNodeInstanceContext ().getClusterInstanceRegistry ()).add (computeNodeInstance );
70
71
}
0 commit comments