6
6
import java .util .ArrayList ;
7
7
import java .util .Arrays ;
8
8
import java .util .List ;
9
+ import java .util .Objects ;
9
10
10
11
import com .meterware .simplestub .Memento ;
11
12
import oracle .kubernetes .utils .SystemClockTestSupport ;
14
15
import org .junit .Before ;
15
16
import org .junit .Test ;
16
17
18
+ import static oracle .kubernetes .operator .WebLogicConstants .SHUTDOWN_STATE ;
17
19
import static oracle .kubernetes .weblogic .domain .model .DomainConditionMatcher .hasCondition ;
18
20
import static oracle .kubernetes .weblogic .domain .model .DomainConditionType .Available ;
19
21
import static oracle .kubernetes .weblogic .domain .model .DomainConditionType .Failed ;
@@ -259,25 +261,86 @@ public void verifyThat_addServers_serverSortedInExpectedOrdering() {
259
261
domainStatus .addServer (cluster1Server1 ).addServer (cluster2Server1 )
260
262
.addServer (cluster1Server2 ).addServer (standAloneServerA ).addServer (adminServer );
261
263
262
- assertThat (domainStatus .servers ,
264
+ assertThat (domainStatus .getServers () ,
263
265
contains (adminServer , standAloneServerA , cluster1Server1 , cluster1Server2 , cluster2Server1 ));
264
266
}
265
267
266
268
@ Test
267
269
public void verifyThat_setServers_serverSortedInExpectedOrdering () {
268
- ServerStatus cluster1Server1 = new ServerStatus ().withClusterName ("cluster-1" ).withServerName ("cluster1-server1" );
269
- ServerStatus cluster1Server2 = new ServerStatus ().withClusterName ("cluster-1" ).withServerName ("cluster1-server2" );
270
- ServerStatus cluster2Server1 = new ServerStatus ().withClusterName ("cluster-2" ).withServerName ("cluster2-server1" );
271
- ServerStatus adminServer = new ServerStatus ().withServerName ("admin-server" ).withIsAdminServer (true );
272
- ServerStatus standAloneServerA = new ServerStatus ().withServerName ("a" );
270
+ ServerStatus cluster1Server1 = createStatus ().withClusterName ("cluster-1" ).withServerName ("cluster1-server1" );
271
+ ServerStatus cluster1Server2 = createStatus ().withClusterName ("cluster-1" ).withServerName ("cluster1-server2" );
272
+ ServerStatus cluster2Server1 = createStatus ().withClusterName ("cluster-2" ).withServerName ("cluster2-server1" );
273
+ ServerStatus adminServer = createStatus ().withServerName ("admin-server" ).withIsAdminServer (true );
274
+ ServerStatus standAloneServerA = createStatus ().withServerName ("a" );
273
275
274
276
domainStatus .setServers (Arrays .asList (cluster1Server1 ,
275
277
cluster2Server1 , cluster1Server2 , standAloneServerA , adminServer ));
276
278
277
- assertThat (domainStatus .servers ,
279
+ assertThat (domainStatus .getServers () ,
278
280
contains (adminServer , standAloneServerA , cluster1Server1 , cluster1Server2 , cluster2Server1 ));
279
281
}
280
282
283
+ private ServerStatus createStatus () {
284
+ return new ServerStatus ().withState ("a" );
285
+ }
286
+
287
+ @ Test
288
+ public void whenMatchingServersExist_setServersUpdatesState () {
289
+ domainStatus .addServer (new ServerStatus ().withClusterName ("1" ).withServerName ("1" ).withState ("state1" ));
290
+ domainStatus .addServer (new ServerStatus ().withClusterName ("1" ).withServerName ("2" ).withState ("state1" ));
291
+ domainStatus .addServer (new ServerStatus ().withClusterName ("1" ).withServerName ("3" ).withState ("state1" ));
292
+
293
+ domainStatus .setServers (Arrays .asList (
294
+ new ServerStatus ().withClusterName ("1" ).withServerName ("1" ).withState ("state1" ),
295
+ new ServerStatus ().withClusterName ("1" ).withServerName ("2" ).withState ("state1" ),
296
+ new ServerStatus ().withServerName ("admin" ).withIsAdminServer (true ).withState ("state2" )
297
+ ));
298
+
299
+ assertThat (getServer ("1" , "1" ).getState (), equalTo ("state1" ));
300
+ assertThat (getServer ("1" , "2" ).getState (), equalTo ("state1" ));
301
+ assertThat (getServer (null , "admin" ).getState (), equalTo ("state2" ));
302
+ }
303
+
304
+ @ Test
305
+ public void whenSetServerIncludesServerWithoutStateAndNoExistingState_defaultToSHUTDOWN () {
306
+ domainStatus .addServer (new ServerStatus ().withClusterName ("1" ).withServerName ("1" ).withState ("state1" ));
307
+ domainStatus .addServer (new ServerStatus ().withClusterName ("1" ).withServerName ("2" ).withState ("state1" ));
308
+ domainStatus .addServer (new ServerStatus ().withClusterName ("1" ).withServerName ("3" ).withState ("state1" ));
309
+
310
+ domainStatus .setServers (Arrays .asList (
311
+ new ServerStatus ().withClusterName ("1" ).withServerName ("1" ).withState ("state1" ),
312
+ new ServerStatus ().withClusterName ("1" ).withServerName ("2" ).withState ("state1" ),
313
+ new ServerStatus ().withClusterName ("1" ).withServerName ("3" ).withState ("state2" ),
314
+ new ServerStatus ().withClusterName ("2" ).withServerName ("1" )
315
+ ));
316
+
317
+ assertThat (getServer ("2" , "1" ).getState (), equalTo (SHUTDOWN_STATE ));
318
+ }
319
+
320
+ @ Test
321
+ public void whenSetServerIncludesServerWithoutStateAndHasExistingState_preserveIt () {
322
+ domainStatus .addServer (new ServerStatus ().withClusterName ("1" ).withServerName ("1" ).withState ("state1" ));
323
+ domainStatus .addServer (new ServerStatus ().withClusterName ("1" ).withServerName ("2" ).withState ("state1" ));
324
+ domainStatus .addServer (new ServerStatus ().withClusterName ("1" ).withServerName ("3" ).withState ("state1" ));
325
+
326
+ domainStatus .setServers (Arrays .asList (
327
+ new ServerStatus ().withClusterName ("1" ).withServerName ("1" ).withState ("state1" ),
328
+ new ServerStatus ().withClusterName ("1" ).withServerName ("2" ).withState ("state1" ),
329
+ new ServerStatus ().withClusterName ("1" ).withServerName ("3" )
330
+ ));
331
+
332
+ assertThat (getServer ("1" , "3" ).getState (), equalTo ("state1" ));
333
+ }
334
+
335
+ private ServerStatus getServer (String clusterName , String serverName ) {
336
+ return domainStatus .getServers ()
337
+ .stream ()
338
+ .filter (s -> Objects .equals (clusterName , s .getClusterName ()))
339
+ .filter (s -> Objects .equals (serverName , s .getServerName ()))
340
+ .findFirst ()
341
+ .orElse (null );
342
+ }
343
+
281
344
@ Test
282
345
public void verifyThat_getServers_serverInExpectedOrdering () {
283
346
ServerStatus cluster1Server1 = new ServerStatus ().withClusterName ("cluster-1" ).withServerName ("cluster1-server1" );
@@ -303,7 +366,7 @@ public void verifyThat_addClusters_clustersSortedInExpectedOrdering() {
303
366
304
367
domainStatus .addCluster (cluster10 ).addCluster (cluster1 ).addCluster (cluster2 );
305
368
306
- assertThat (domainStatus .clusters , contains (cluster1 , cluster2 , cluster10 ));
369
+ assertThat (domainStatus .getClusters () , contains (cluster1 , cluster2 , cluster10 ));
307
370
}
308
371
309
372
@ Test
@@ -314,9 +377,7 @@ public void verifyThat_setClusters_clustersSortedInExpectedOrdering() {
314
377
315
378
domainStatus .setClusters (Arrays .asList (cluster10 , cluster1 , cluster2 ));
316
379
317
- List <ClusterStatus > clusterStatuses = domainStatus .clusters ;
318
-
319
- assertThat (clusterStatuses , contains (cluster1 , cluster2 , cluster10 ));
380
+ assertThat (domainStatus .getClusters (), contains (cluster1 , cluster2 , cluster10 ));
320
381
}
321
382
322
383
@ Test
0 commit comments