5
5
package oracle .kubernetes .operator .steps ;
6
6
7
7
import static oracle .kubernetes .LogMatcher .containsInfo ;
8
+ import static oracle .kubernetes .operator .ProcessingConstants .SERVER_STATE_MAP ;
8
9
import static oracle .kubernetes .operator .logging .MessageKeys .WLS_HEALTH_READ_FAILED ;
9
10
import static oracle .kubernetes .operator .logging .MessageKeys .WLS_HEALTH_READ_FAILED_NO_HTTPCLIENT ;
10
11
import static org .hamcrest .MatcherAssert .assertThat ;
11
12
import static org .hamcrest .Matchers .is ;
13
+ import static org .hamcrest .Matchers .nullValue ;
12
14
13
15
import com .meterware .simplestub .Memento ;
14
16
import com .meterware .simplestub .Stub ;
24
26
import java .util .logging .LogRecord ;
25
27
import oracle .kubernetes .TestUtils ;
26
28
import oracle .kubernetes .operator .ProcessingConstants ;
29
+ import oracle .kubernetes .operator .helpers .DomainPresenceInfo ;
30
+ import oracle .kubernetes .operator .helpers .KubernetesVersion ;
27
31
import oracle .kubernetes .operator .http .HttpClient ;
28
32
import oracle .kubernetes .operator .http .HttpClientStub ;
29
33
import oracle .kubernetes .operator .steps .ReadHealthStep .ReadHealthWithHttpClientStep ;
30
34
import oracle .kubernetes .operator .utils .WlsDomainConfigSupport ;
35
+ import oracle .kubernetes .operator .work .Component ;
31
36
import oracle .kubernetes .operator .work .NextAction ;
32
37
import oracle .kubernetes .operator .work .Packet ;
33
38
import oracle .kubernetes .operator .work .Step ;
@@ -42,6 +47,9 @@ public class ReadHealthStepTest {
42
47
WLS_HEALTH_READ_FAILED , WLS_HEALTH_READ_FAILED_NO_HTTPCLIENT
43
48
};
44
49
50
+ private static final String NAMESPACE = "testnamespace" ;
51
+ private static final String DOMAIN_UID = "domain-uid" ;
52
+
45
53
private static final String DOMAIN_NAME = "domain" ;
46
54
private static final String ADMIN_NAME = "admin-server" ;
47
55
private static final int ADMIN_PORT_NUM = 3456 ;
@@ -155,33 +163,23 @@ public void withHttpClientStep_decrementRemainingServerHealthReadInMultipleClone
155
163
public void withHttpClientStep_verifyOkServerHealthAddedToPacket () {
156
164
httpClientStub .withResponse (OK_RESPONSE );
157
165
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 ));
166
+ Packet packet = createPacketForTest ();
165
167
166
168
withHttpClientStep .apply (packet );
167
169
168
170
Map <String , ServerHealth > serverHealthMap =
169
171
packet .getValue (ProcessingConstants .SERVER_HEALTH_MAP );
170
172
ServerHealth serverHealth = serverHealthMap .get (MANAGED_SERVER1 );
171
173
assertThat (serverHealth .getOverallHealth (), is ("ok" ));
174
+ Map <String , String > serverStateMap = packet .getValue (SERVER_STATE_MAP );
175
+ assertThat (serverStateMap .get (MANAGED_SERVER1 ), is ("RUNNING" ));
172
176
}
173
177
174
178
@ Test
175
179
public void withHttpClientStep_verifyServerHealthForServerOverloadedAddedToPacket () {
176
180
httpClientStub .withStatus (500 ).withSuccessful (false );
177
181
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 ));
182
+ Packet packet = createPacketForTest ();
185
183
186
184
withHttpClientStep .apply (packet );
187
185
@@ -190,27 +188,24 @@ public void withHttpClientStep_verifyServerHealthForServerOverloadedAddedToPacke
190
188
ServerHealth serverHealth = serverHealthMap .get (MANAGED_SERVER1 );
191
189
assertThat (
192
190
serverHealth .getOverallHealth (), is (ReadHealthStep .OVERALL_HEALTH_FOR_SERVER_OVERLOADED ));
191
+ Map <String , String > serverStateMap = packet .getValue (SERVER_STATE_MAP );
192
+ assertThat (serverStateMap .get (MANAGED_SERVER1 ), nullValue ());
193
193
}
194
194
195
195
@ Test
196
196
public void withHttpClientStep_verifyServerHealthForOtherErrorAddedToPacket () {
197
197
httpClientStub .withStatus (404 ).withSuccessful (false );
198
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
- packet .put (ProcessingConstants .SERVER_STATE_MAP , new ConcurrentHashMap <String , ServerHealth >());
199
+ Packet packet = createPacketForTest ();
207
200
208
201
withHttpClientStep .apply (packet );
209
202
210
203
Map <String , ServerHealth > serverHealthMap =
211
204
packet .getValue (ProcessingConstants .SERVER_HEALTH_MAP );
212
205
ServerHealth serverHealth = serverHealthMap .get (MANAGED_SERVER1 );
213
206
assertThat (serverHealth .getOverallHealth (), is (ReadHealthStep .OVERALL_HEALTH_NOT_AVAILABLE ));
207
+ Map <String , String > serverStateMap = packet .getValue (SERVER_STATE_MAP );
208
+ assertThat (serverStateMap .get (MANAGED_SERVER1 ), nullValue ());
214
209
}
215
210
216
211
static final String OK_RESPONSE =
@@ -221,9 +216,29 @@ public void withHttpClientStep_verifyServerHealthForOtherErrorAddedToPacket() {
221
216
+ " \" partitionName\" : null,\n "
222
217
+ " \" symptoms\" : []\n "
223
218
+ " },\n "
219
+ + " \" state\" : \" RUNNING\" ,\n "
224
220
+ " \" activationTime\" : 1556759105378\n "
225
221
+ "}" ;
226
222
223
+ Packet createPacketForTest () {
224
+ Packet packet =
225
+ Stub .createStub (PacketStub .class )
226
+ .withServerName (MANAGED_SERVER1 )
227
+ .withGetKeyReturnValue (httpClientStub );
228
+ packet .put (
229
+ ProcessingConstants .SERVER_HEALTH_MAP , new ConcurrentHashMap <String , ServerHealth >());
230
+ packet .put (ProcessingConstants .REMAINING_SERVERS_HEALTH_TO_READ , new AtomicInteger (1 ));
231
+ packet .put (SERVER_STATE_MAP , new ConcurrentHashMap <String , String >());
232
+ packet
233
+ .getComponents ()
234
+ .put (
235
+ ProcessingConstants .DOMAIN_COMPONENT_NAME ,
236
+ Component .createFor (
237
+ new DomainPresenceInfo (NAMESPACE , DOMAIN_UID ), KubernetesVersion .TEST_VERSION ));
238
+
239
+ return packet ;
240
+ }
241
+
227
242
abstract static class PacketStub extends Packet {
228
243
229
244
String serverName ;
0 commit comments