4
4
5
5
package oracle .kubernetes .operator .steps ;
6
6
7
- import static oracle .kubernetes .LogMatcher .containsFine ;
7
+ import static oracle .kubernetes .LogMatcher .containsInfo ;
8
8
import static oracle .kubernetes .operator .logging .MessageKeys .WLS_HEALTH_READ_FAILED ;
9
+ import static oracle .kubernetes .operator .logging .MessageKeys .WLS_HEALTH_READ_FAILED_NO_HTTPCLIENT ;
9
10
import static org .hamcrest .MatcherAssert .assertThat ;
10
11
import static org .junit .Assert .*;
11
12
20
21
import oracle .kubernetes .operator .ProcessingConstants ;
21
22
import oracle .kubernetes .operator .http .HttpClient ;
22
23
import oracle .kubernetes .operator .steps .ReadHealthStep .ReadHealthWithHttpClientStep ;
23
- import oracle .kubernetes .operator .work .Component ;
24
24
import oracle .kubernetes .operator .work .NextAction ;
25
25
import oracle .kubernetes .operator .work .Packet ;
26
26
import oracle .kubernetes .operator .work .Step ;
30
30
31
31
public class ReadHealthStepTest {
32
32
// The log messages to be checked during this test
33
- private static final String [] LOG_KEYS = {WLS_HEALTH_READ_FAILED };
33
+ private static final String [] LOG_KEYS = {
34
+ WLS_HEALTH_READ_FAILED , WLS_HEALTH_READ_FAILED_NO_HTTPCLIENT
35
+ };
34
36
35
37
private List <LogRecord > logRecords = new ArrayList <>();
36
38
private Memento consoleControl ;
@@ -52,6 +54,23 @@ public void tearDown() {
52
54
53
55
@ Test
54
56
public void withHttpClientStep_Health_logIfFailed () {
57
+ V1Service service = Stub .createStub (V1ServiceStub .class );
58
+ Step next = new MockStep (null );
59
+ final String SERVER_NAME = "admin-server" ;
60
+ Packet packet =
61
+ Stub .createStub (PacketStub .class )
62
+ .withServerName (SERVER_NAME )
63
+ .withGetKeyThrowsException (true );
64
+
65
+ ReadHealthWithHttpClientStep withHttpClientStep =
66
+ new ReadHealthWithHttpClientStep (service , next );
67
+ withHttpClientStep .apply (packet );
68
+
69
+ assertThat (logRecords , containsInfo (WLS_HEALTH_READ_FAILED , SERVER_NAME ));
70
+ }
71
+
72
+ @ Test
73
+ public void withHttpClientStep_logIfMissingHTTPClient () {
55
74
V1Service service = Stub .createStub (V1ServiceStub .class );
56
75
Step next = new MockStep (null );
57
76
final String SERVER_NAME = "admin-server" ;
@@ -61,29 +80,31 @@ public void withHttpClientStep_Health_logIfFailed() {
61
80
new ReadHealthWithHttpClientStep (service , next );
62
81
withHttpClientStep .apply (packet );
63
82
64
- assertThat (logRecords , containsFine ( WLS_HEALTH_READ_FAILED , SERVER_NAME ));
83
+ assertThat (logRecords , containsInfo ( WLS_HEALTH_READ_FAILED_NO_HTTPCLIENT , SERVER_NAME ));
65
84
}
66
85
67
86
abstract static class PacketStub extends Packet {
68
87
69
- Integer retryCount ;
70
88
String serverName ;
89
+ boolean getKeyThrowsException ;
71
90
72
- PacketStub withServerName ( String serverName ) {
73
- this .serverName = serverName ;
91
+ PacketStub withGetKeyThrowsException ( boolean getKeyThrowsException ) {
92
+ this .getKeyThrowsException = getKeyThrowsException ;
74
93
return this ;
75
94
}
76
95
77
- PacketStub addSpi (Class clazz , Object spiObject ) {
78
- Component component = Component .createFor (spiObject );
79
- this .getComponents ().put (clazz .getName (), component );
96
+ PacketStub withServerName (String serverName ) {
97
+ this .serverName = serverName ;
80
98
return this ;
81
99
}
82
100
83
101
@ Override
84
102
public Object get (Object key ) {
85
103
if (HttpClient .KEY .equals (key )) {
86
- throw CLASSCAST_EXCEPTION ; // to go to catch clause in WithHttpClientStep.apply() method
104
+ if (getKeyThrowsException ) {
105
+ throw CLASSCAST_EXCEPTION ; // to go to catch clause in WithHttpClientStep.apply() method
106
+ }
107
+ return null ;
87
108
} else if (ProcessingConstants .SERVER_NAME .equals (key )) {
88
109
return serverName ;
89
110
}
0 commit comments