17
17
import io .kubernetes .client .models .V1ServiceSpec ;
18
18
import java .util .ArrayList ;
19
19
import java .util .List ;
20
+ import java .util .Map ;
20
21
import java .util .concurrent .ConcurrentHashMap ;
21
22
import java .util .concurrent .atomic .AtomicInteger ;
22
23
import java .util .logging .Level ;
@@ -57,13 +58,22 @@ public class ReadHealthStepTest {
57
58
.withWlsServer (MANAGED_SERVER1 , MANAGED_SERVER1_PORT_NUM )
58
59
.withAdminServerName (ADMIN_NAME );
59
60
61
+ V1Service service ;
62
+ Step next ;
63
+ HttpClientStub httpClientStub ;
64
+ ReadHealthWithHttpClientStep withHttpClientStep ;
65
+
60
66
@ Before
61
67
public void setup () {
62
68
consoleControl =
63
69
TestUtils .silenceOperatorLogger ()
64
70
.collectLogMessages (logRecords , LOG_KEYS )
65
71
.ignoringLoggedExceptions (CLASSCAST_EXCEPTION )
66
72
.withLogLevel (Level .FINE );
73
+ service = Stub .createStub (V1ServiceStub .class );
74
+ next = new MockStep (null );
75
+ httpClientStub = Stub .createStub (HttpClientStub .class );
76
+ withHttpClientStep = new ReadHealthWithHttpClientStep (service , null , next );
67
77
}
68
78
69
79
@ After
@@ -73,58 +83,40 @@ public void tearDown() {
73
83
74
84
@ Test
75
85
public void withHttpClientStep_Health_logIfFailed () {
76
- V1Service service = Stub .createStub (V1ServiceStub .class );
77
- Step next = new MockStep (null );
78
- final String SERVER_NAME = ADMIN_NAME ;
79
86
Packet packet =
80
87
Stub .createStub (PacketStub .class )
81
- .withServerName (SERVER_NAME )
88
+ .withServerName (ADMIN_NAME )
82
89
.withGetKeyThrowsException (true );
83
90
84
- ReadHealthWithHttpClientStep withHttpClientStep =
85
- new ReadHealthWithHttpClientStep (service , null , next );
86
91
withHttpClientStep .apply (packet );
87
92
88
- assertThat (logRecords , containsInfo (WLS_HEALTH_READ_FAILED , SERVER_NAME ));
93
+ assertThat (logRecords , containsInfo (WLS_HEALTH_READ_FAILED , ADMIN_NAME ));
89
94
}
90
95
91
96
@ Test
92
97
public void withHttpClientStep_logIfMissingHTTPClient () {
93
- V1Service service = Stub .createStub (V1ServiceStub .class );
94
- Step next = new MockStep (null );
95
- final String SERVER_NAME = ADMIN_NAME ;
96
98
Packet packet =
97
- Stub .createStub (PacketStub .class ).withServerName (SERVER_NAME ).withGetKeyReturnValue (null );
99
+ Stub .createStub (PacketStub .class ).withServerName (ADMIN_NAME ).withGetKeyReturnValue (null );
98
100
packet .put (ProcessingConstants .REMAINING_SERVERS_HEALTH_TO_READ , new AtomicInteger (1 ));
99
101
100
- ReadHealthWithHttpClientStep withHttpClientStep =
101
- new ReadHealthWithHttpClientStep (service , null , next );
102
102
withHttpClientStep .apply (packet );
103
103
104
- assertThat (logRecords , containsInfo (WLS_HEALTH_READ_FAILED_NO_HTTPCLIENT , SERVER_NAME ));
104
+ assertThat (logRecords , containsInfo (WLS_HEALTH_READ_FAILED_NO_HTTPCLIENT , ADMIN_NAME ));
105
105
assertThat (
106
106
((AtomicInteger ) packet .get (ProcessingConstants .REMAINING_SERVERS_HEALTH_TO_READ )).get (),
107
107
is (1 ));
108
108
}
109
109
110
110
@ Test
111
111
public void withHttpClientStep_decrementRemainingServerHealthReadInPacketIfSucceeded () {
112
- V1Service service = Stub .createStub (V1ServiceStub .class );
113
- Step next = new MockStep (null );
114
- final String SERVER_NAME = ADMIN_NAME ;
115
-
116
- HttpClientStub httpClientStub = Stub .createStub (HttpClientStub .class );
117
-
118
112
Packet packet =
119
113
Stub .createStub (PacketStub .class )
120
- .withServerName (SERVER_NAME )
114
+ .withServerName (ADMIN_NAME )
121
115
.withGetKeyReturnValue (httpClientStub );
122
116
packet .put (
123
117
ProcessingConstants .SERVER_HEALTH_MAP , new ConcurrentHashMap <String , ServerHealth >());
124
118
packet .put (ProcessingConstants .REMAINING_SERVERS_HEALTH_TO_READ , new AtomicInteger (1 ));
125
119
126
- ReadHealthWithHttpClientStep withHttpClientStep =
127
- new ReadHealthWithHttpClientStep (service , null , next );
128
120
withHttpClientStep .apply (packet );
129
121
130
122
assertThat (
@@ -134,11 +126,6 @@ public void withHttpClientStep_decrementRemainingServerHealthReadInPacketIfSucce
134
126
135
127
@ Test
136
128
public void withHttpClientStep_decrementRemainingServerHealthReadInMultipleClonedPackets () {
137
- V1Service service = Stub .createStub (V1ServiceStub .class );
138
- Step next = new MockStep (null );
139
-
140
- HttpClientStub httpClientStub = Stub .createStub (HttpClientStub .class );
141
-
142
129
Packet packet = new Packet ();
143
130
packet .put (ProcessingConstants .DOMAIN_TOPOLOGY , configSupport .createDomainConfig ());
144
131
packet .put (HttpClient .KEY , httpClientStub );
@@ -164,6 +151,78 @@ public void withHttpClientStep_decrementRemainingServerHealthReadInMultipleClone
164
151
is (0 ));
165
152
}
166
153
154
+ @ Test
155
+ public void withHttpClientStep_verifyOkServerHealthAddedToPacket () {
156
+ httpClientStub .withResponse (OK_RESPONSE );
157
+
158
+ Packet packet =
159
+ Stub .createStub (PacketStub .class )
160
+ .withServerName (MANAGED_SERVER1 )
161
+ .withGetKeyReturnValue (httpClientStub );
162
+ packet .put (
163
+ ProcessingConstants .SERVER_HEALTH_MAP , new ConcurrentHashMap <String , ServerHealth >());
164
+ packet .put (ProcessingConstants .REMAINING_SERVERS_HEALTH_TO_READ , new AtomicInteger (1 ));
165
+
166
+ withHttpClientStep .apply (packet );
167
+
168
+ Map <String , ServerHealth > serverHealthMap =
169
+ packet .getValue (ProcessingConstants .SERVER_HEALTH_MAP );
170
+ ServerHealth serverHealth = serverHealthMap .get (MANAGED_SERVER1 );
171
+ assertThat (serverHealth .getOverallHealth (), is ("ok" ));
172
+ }
173
+
174
+ @ Test
175
+ public void withHttpClientStep_verifyServerHealthForServerOverloadedAddedToPacket () {
176
+ httpClientStub .withStatus (500 ).withSuccessful (false );
177
+
178
+ Packet packet =
179
+ Stub .createStub (PacketStub .class )
180
+ .withServerName (MANAGED_SERVER1 )
181
+ .withGetKeyReturnValue (httpClientStub );
182
+ packet .put (
183
+ ProcessingConstants .SERVER_HEALTH_MAP , new ConcurrentHashMap <String , ServerHealth >());
184
+ packet .put (ProcessingConstants .REMAINING_SERVERS_HEALTH_TO_READ , new AtomicInteger (1 ));
185
+
186
+ withHttpClientStep .apply (packet );
187
+
188
+ Map <String , ServerHealth > serverHealthMap =
189
+ packet .getValue (ProcessingConstants .SERVER_HEALTH_MAP );
190
+ ServerHealth serverHealth = serverHealthMap .get (MANAGED_SERVER1 );
191
+ assertThat (
192
+ serverHealth .getOverallHealth (), is (ReadHealthStep .OVERALL_HEALTH_FOR_SERVER_OVERLOADED ));
193
+ }
194
+
195
+ @ Test
196
+ public void withHttpClientStep_verifyServerHealthForOtherErrorAddedToPacket () {
197
+ httpClientStub .withStatus (404 ).withSuccessful (false );
198
+
199
+ Packet packet =
200
+ Stub .createStub (PacketStub .class )
201
+ .withServerName (MANAGED_SERVER1 )
202
+ .withGetKeyReturnValue (httpClientStub );
203
+ packet .put (
204
+ ProcessingConstants .SERVER_HEALTH_MAP , new ConcurrentHashMap <String , ServerHealth >());
205
+ packet .put (ProcessingConstants .REMAINING_SERVERS_HEALTH_TO_READ , new AtomicInteger (1 ));
206
+
207
+ withHttpClientStep .apply (packet );
208
+
209
+ Map <String , ServerHealth > serverHealthMap =
210
+ packet .getValue (ProcessingConstants .SERVER_HEALTH_MAP );
211
+ ServerHealth serverHealth = serverHealthMap .get (MANAGED_SERVER1 );
212
+ assertThat (serverHealth .getOverallHealth (), is (ReadHealthStep .OVERALL_HEALTH_NOT_AVAILABLE ));
213
+ }
214
+
215
+ static final String OK_RESPONSE =
216
+ "{\n "
217
+ + " \" overallHealthState\" : {\n "
218
+ + " \" state\" : \" ok\" ,\n "
219
+ + " \" subsystemName\" : null,\n "
220
+ + " \" partitionName\" : null,\n "
221
+ + " \" symptoms\" : []\n "
222
+ + " },\n "
223
+ + " \" activationTime\" : 1556759105378\n "
224
+ + "}" ;
225
+
167
226
abstract static class PacketStub extends Packet {
168
227
169
228
String serverName ;
0 commit comments