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