1717import io .kubernetes .client .models .V1ServiceSpec ;
1818import java .util .ArrayList ;
1919import java .util .List ;
20+ import java .util .Map ;
2021import java .util .concurrent .ConcurrentHashMap ;
2122import java .util .concurrent .atomic .AtomicInteger ;
2223import java .util .logging .Level ;
@@ -57,13 +58,22 @@ public class ReadHealthStepTest {
5758 .withWlsServer (MANAGED_SERVER1 , MANAGED_SERVER1_PORT_NUM )
5859 .withAdminServerName (ADMIN_NAME );
5960
61+ V1Service service ;
62+ Step next ;
63+ HttpClientStub httpClientStub ;
64+ ReadHealthWithHttpClientStep withHttpClientStep ;
65+
6066 @ Before
6167 public void setup () {
6268 consoleControl =
6369 TestUtils .silenceOperatorLogger ()
6470 .collectLogMessages (logRecords , LOG_KEYS )
6571 .ignoringLoggedExceptions (CLASSCAST_EXCEPTION )
6672 .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 );
6777 }
6878
6979 @ After
@@ -73,58 +83,40 @@ public void tearDown() {
7383
7484 @ Test
7585 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 ;
7986 Packet packet =
8087 Stub .createStub (PacketStub .class )
81- .withServerName (SERVER_NAME )
88+ .withServerName (ADMIN_NAME )
8289 .withGetKeyThrowsException (true );
8390
84- ReadHealthWithHttpClientStep withHttpClientStep =
85- new ReadHealthWithHttpClientStep (service , null , next );
8691 withHttpClientStep .apply (packet );
8792
88- assertThat (logRecords , containsInfo (WLS_HEALTH_READ_FAILED , SERVER_NAME ));
93+ assertThat (logRecords , containsInfo (WLS_HEALTH_READ_FAILED , ADMIN_NAME ));
8994 }
9095
9196 @ Test
9297 public void withHttpClientStep_logIfMissingHTTPClient () {
93- V1Service service = Stub .createStub (V1ServiceStub .class );
94- Step next = new MockStep (null );
95- final String SERVER_NAME = ADMIN_NAME ;
9698 Packet packet =
97- Stub .createStub (PacketStub .class ).withServerName (SERVER_NAME ).withGetKeyReturnValue (null );
99+ Stub .createStub (PacketStub .class ).withServerName (ADMIN_NAME ).withGetKeyReturnValue (null );
98100 packet .put (ProcessingConstants .REMAINING_SERVERS_HEALTH_TO_READ , new AtomicInteger (1 ));
99101
100- ReadHealthWithHttpClientStep withHttpClientStep =
101- new ReadHealthWithHttpClientStep (service , null , next );
102102 withHttpClientStep .apply (packet );
103103
104- assertThat (logRecords , containsInfo (WLS_HEALTH_READ_FAILED_NO_HTTPCLIENT , SERVER_NAME ));
104+ assertThat (logRecords , containsInfo (WLS_HEALTH_READ_FAILED_NO_HTTPCLIENT , ADMIN_NAME ));
105105 assertThat (
106106 ((AtomicInteger ) packet .get (ProcessingConstants .REMAINING_SERVERS_HEALTH_TO_READ )).get (),
107107 is (1 ));
108108 }
109109
110110 @ Test
111111 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-
118112 Packet packet =
119113 Stub .createStub (PacketStub .class )
120- .withServerName (SERVER_NAME )
114+ .withServerName (ADMIN_NAME )
121115 .withGetKeyReturnValue (httpClientStub );
122116 packet .put (
123117 ProcessingConstants .SERVER_HEALTH_MAP , new ConcurrentHashMap <String , ServerHealth >());
124118 packet .put (ProcessingConstants .REMAINING_SERVERS_HEALTH_TO_READ , new AtomicInteger (1 ));
125119
126- ReadHealthWithHttpClientStep withHttpClientStep =
127- new ReadHealthWithHttpClientStep (service , null , next );
128120 withHttpClientStep .apply (packet );
129121
130122 assertThat (
@@ -134,11 +126,6 @@ public void withHttpClientStep_decrementRemainingServerHealthReadInPacketIfSucce
134126
135127 @ Test
136128 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-
142129 Packet packet = new Packet ();
143130 packet .put (ProcessingConstants .DOMAIN_TOPOLOGY , configSupport .createDomainConfig ());
144131 packet .put (HttpClient .KEY , httpClientStub );
@@ -164,6 +151,78 @@ public void withHttpClientStep_decrementRemainingServerHealthReadInMultipleClone
164151 is (0 ));
165152 }
166153
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+
167226 abstract static class PacketStub extends Packet {
168227
169228 String serverName ;
0 commit comments