@ -17,6 +17,7 @@
package org.apache.dolphinscheduler.service.alert ;
package org.apache.dolphinscheduler.service.alert ;
import org.apache.dolphinscheduler.common.enums.WarningType ;
import org.apache.dolphinscheduler.remote.NettyRemotingClient ;
import org.apache.dolphinscheduler.remote.NettyRemotingClient ;
import org.apache.dolphinscheduler.remote.command.Command ;
import org.apache.dolphinscheduler.remote.command.Command ;
import org.apache.dolphinscheduler.remote.command.alert.AlertSendRequestCommand ;
import org.apache.dolphinscheduler.remote.command.alert.AlertSendRequestCommand ;
@ -67,10 +68,10 @@ public class AlertClientServiceTest {
String content = "test-content" ;
String content = "test-content" ;
//1.alter server does not exist
//1.alter server does not exist
AlertSendResponseCommand alertSendResponseCommand = alertClient . sendAlert ( host , port , groupId , title , content ) ;
AlertSendResponseCommand alertSendResponseCommand = alertClient . sendAlert ( host , port , groupId , title , content , WarningType . FAILURE . getCode ( ) ) ;
Assert . assertNull ( alertSendResponseCommand ) ;
Assert . assertNull ( alertSendResponseCommand ) ;
AlertSendRequestCommand alertSendRequestCommand = new AlertSendRequestCommand ( groupId , title , content ) ;
AlertSendRequestCommand alertSendRequestCommand = new AlertSendRequestCommand ( groupId , title , content , WarningType . FAILURE . getCode ( ) ) ;
Command reqCommand = alertSendRequestCommand . convert2Command ( ) ;
Command reqCommand = alertSendRequestCommand . convert2Command ( ) ;
boolean sendResponseStatus ;
boolean sendResponseStatus ;
List < AlertSendResponseResult > sendResponseResults = new ArrayList < > ( ) ;
List < AlertSendResponseResult > sendResponseResults = new ArrayList < > ( ) ;
@ -86,7 +87,7 @@ public class AlertClientServiceTest {
Command resCommand = alertSendResponseCommandData . convert2Command ( reqCommand . getOpaque ( ) ) ;
Command resCommand = alertSendResponseCommandData . convert2Command ( reqCommand . getOpaque ( ) ) ;
PowerMockito . when ( client . sendSync ( Mockito . any ( ) , Mockito . any ( ) , Mockito . anyLong ( ) ) ) . thenReturn ( resCommand ) ;
PowerMockito . when ( client . sendSync ( Mockito . any ( ) , Mockito . any ( ) , Mockito . anyLong ( ) ) ) . thenReturn ( resCommand ) ;
alertSendResponseCommand = alertClient . sendAlert ( host , port , groupId , title , content ) ;
alertSendResponseCommand = alertClient . sendAlert ( host , port , groupId , title , content , WarningType . FAILURE . getCode ( ) ) ;
Assert . assertFalse ( alertSendResponseCommand . getResStatus ( ) ) ;
Assert . assertFalse ( alertSendResponseCommand . getResStatus ( ) ) ;
alertSendResponseCommand . getResResults ( ) . forEach ( result - >
alertSendResponseCommand . getResResults ( ) . forEach ( result - >
logger . info ( "alert send response result, status:{}, message:{}" , result . getStatus ( ) , result . getMessage ( ) ) ) ;
logger . info ( "alert send response result, status:{}, message:{}" , result . getStatus ( ) , result . getMessage ( ) ) ) ;
@ -100,7 +101,7 @@ public class AlertClientServiceTest {
alertSendResponseCommandData = new AlertSendResponseCommand ( sendResponseStatus , sendResponseResults ) ;
alertSendResponseCommandData = new AlertSendResponseCommand ( sendResponseStatus , sendResponseResults ) ;
resCommand = alertSendResponseCommandData . convert2Command ( reqCommand . getOpaque ( ) ) ;
resCommand = alertSendResponseCommandData . convert2Command ( reqCommand . getOpaque ( ) ) ;
PowerMockito . when ( client . sendSync ( Mockito . any ( ) , Mockito . any ( ) , Mockito . anyLong ( ) ) ) . thenReturn ( resCommand ) ;
PowerMockito . when ( client . sendSync ( Mockito . any ( ) , Mockito . any ( ) , Mockito . anyLong ( ) ) ) . thenReturn ( resCommand ) ;
alertSendResponseCommand = alertClient . sendAlert ( host , port , groupId , title , content ) ;
alertSendResponseCommand = alertClient . sendAlert ( host , port , groupId , title , content , WarningType . FAILURE . getCode ( ) ) ;
Assert . assertFalse ( alertSendResponseCommand . getResStatus ( ) ) ;
Assert . assertFalse ( alertSendResponseCommand . getResStatus ( ) ) ;
alertSendResponseCommand . getResResults ( ) . forEach ( result - >
alertSendResponseCommand . getResResults ( ) . forEach ( result - >
logger . info ( "alert send response result, status:{}, message:{}" , result . getStatus ( ) , result . getMessage ( ) ) ) ;
logger . info ( "alert send response result, status:{}, message:{}" , result . getStatus ( ) , result . getMessage ( ) ) ) ;
@ -113,7 +114,7 @@ public class AlertClientServiceTest {
alertSendResponseCommandData = new AlertSendResponseCommand ( sendResponseStatus , sendResponseResults ) ;
alertSendResponseCommandData = new AlertSendResponseCommand ( sendResponseStatus , sendResponseResults ) ;
resCommand = alertSendResponseCommandData . convert2Command ( reqCommand . getOpaque ( ) ) ;
resCommand = alertSendResponseCommandData . convert2Command ( reqCommand . getOpaque ( ) ) ;
PowerMockito . when ( client . sendSync ( Mockito . any ( ) , Mockito . any ( ) , Mockito . anyLong ( ) ) ) . thenReturn ( resCommand ) ;
PowerMockito . when ( client . sendSync ( Mockito . any ( ) , Mockito . any ( ) , Mockito . anyLong ( ) ) ) . thenReturn ( resCommand ) ;
alertSendResponseCommand = alertClient . sendAlert ( host , port , groupId , title , content ) ;
alertSendResponseCommand = alertClient . sendAlert ( host , port , groupId , title , content , WarningType . FAILURE . getCode ( ) ) ;
Assert . assertFalse ( alertSendResponseCommand . getResStatus ( ) ) ;
Assert . assertFalse ( alertSendResponseCommand . getResStatus ( ) ) ;
alertSendResponseCommand . getResResults ( ) . forEach ( result - >
alertSendResponseCommand . getResResults ( ) . forEach ( result - >
logger . info ( "alert send response result, status:{}, message:{}" , result . getStatus ( ) , result . getMessage ( ) ) ) ;
logger . info ( "alert send response result, status:{}, message:{}" , result . getStatus ( ) , result . getMessage ( ) ) ) ;
@ -125,7 +126,7 @@ public class AlertClientServiceTest {
alertSendResponseCommandData = new AlertSendResponseCommand ( sendResponseStatus , sendResponseResults ) ;
alertSendResponseCommandData = new AlertSendResponseCommand ( sendResponseStatus , sendResponseResults ) ;
resCommand = alertSendResponseCommandData . convert2Command ( reqCommand . getOpaque ( ) ) ;
resCommand = alertSendResponseCommandData . convert2Command ( reqCommand . getOpaque ( ) ) ;
PowerMockito . when ( client . sendSync ( Mockito . any ( ) , Mockito . any ( ) , Mockito . anyLong ( ) ) ) . thenReturn ( resCommand ) ;
PowerMockito . when ( client . sendSync ( Mockito . any ( ) , Mockito . any ( ) , Mockito . anyLong ( ) ) ) . thenReturn ( resCommand ) ;
alertSendResponseCommand = alertClient . sendAlert ( host , port , groupId , title , content ) ;
alertSendResponseCommand = alertClient . sendAlert ( host , port , groupId , title , content , WarningType . FAILURE . getCode ( ) ) ;
Assert . assertFalse ( alertSendResponseCommand . getResStatus ( ) ) ;
Assert . assertFalse ( alertSendResponseCommand . getResStatus ( ) ) ;
alertSendResponseCommand . getResResults ( ) . forEach ( result - >
alertSendResponseCommand . getResResults ( ) . forEach ( result - >
logger . info ( "alert send response result, status:{}, message:{}" , result . getStatus ( ) , result . getMessage ( ) ) ) ;
logger . info ( "alert send response result, status:{}, message:{}" , result . getStatus ( ) , result . getMessage ( ) ) ) ;
@ -138,7 +139,7 @@ public class AlertClientServiceTest {
alertSendResponseCommandData = new AlertSendResponseCommand ( sendResponseStatus , sendResponseResults ) ;
alertSendResponseCommandData = new AlertSendResponseCommand ( sendResponseStatus , sendResponseResults ) ;
resCommand = alertSendResponseCommandData . convert2Command ( reqCommand . getOpaque ( ) ) ;
resCommand = alertSendResponseCommandData . convert2Command ( reqCommand . getOpaque ( ) ) ;
PowerMockito . when ( client . sendSync ( Mockito . any ( ) , Mockito . any ( ) , Mockito . anyLong ( ) ) ) . thenReturn ( resCommand ) ;
PowerMockito . when ( client . sendSync ( Mockito . any ( ) , Mockito . any ( ) , Mockito . anyLong ( ) ) ) . thenReturn ( resCommand ) ;
alertSendResponseCommand = alertClient . sendAlert ( host , port , groupId , title , content ) ;
alertSendResponseCommand = alertClient . sendAlert ( host , port , groupId , title , content , WarningType . FAILURE . getCode ( ) ) ;
Assert . assertTrue ( alertSendResponseCommand . getResStatus ( ) ) ;
Assert . assertTrue ( alertSendResponseCommand . getResStatus ( ) ) ;
alertSendResponseCommand . getResResults ( ) . forEach ( result - >
alertSendResponseCommand . getResResults ( ) . forEach ( result - >
logger . info ( "alert send response result, status:{}, message:{}" , result . getStatus ( ) , result . getMessage ( ) ) ) ;
logger . info ( "alert send response result, status:{}, message:{}" , result . getStatus ( ) , result . getMessage ( ) ) ) ;