8
8
9
9
package org .opensearch .gateway .remote ;
10
10
11
- import org .opensearch .Version ;
12
11
import org .opensearch .action .LatchedActionListener ;
13
- import org .opensearch .cluster .AbstractNamedDiffable ;
14
12
import org .opensearch .cluster .ClusterName ;
15
13
import org .opensearch .cluster .ClusterState ;
16
14
import org .opensearch .cluster .ClusterState .Custom ;
23
21
import org .opensearch .common .util .TestCapturingListener ;
24
22
import org .opensearch .core .action .ActionListener ;
25
23
import org .opensearch .core .common .io .stream .NamedWriteableRegistry ;
26
- import org .opensearch .core .common .io .stream .StreamInput ;
27
- import org .opensearch .core .common .io .stream .StreamOutput ;
28
24
import org .opensearch .core .compress .Compressor ;
29
25
import org .opensearch .core .compress .NoneCompressor ;
30
- import org .opensearch .core .xcontent .XContentBuilder ;
31
26
import org .opensearch .gateway .remote .model .RemoteClusterBlocks ;
32
27
import org .opensearch .gateway .remote .model .RemoteClusterStateCustoms ;
33
28
import org .opensearch .gateway .remote .model .RemoteDiscoveryNodes ;
51
46
import static org .opensearch .gateway .remote .RemoteClusterStateAttributesManager .CLUSTER_STATE_ATTRIBUTE ;
52
47
import static org .opensearch .gateway .remote .RemoteClusterStateAttributesManager .CLUSTER_STATE_ATTRIBUTES_CURRENT_CODEC_VERSION ;
53
48
import static org .opensearch .gateway .remote .RemoteClusterStateAttributesManager .DISCOVERY_NODES ;
49
+ import static org .opensearch .gateway .remote .RemoteClusterStateTestUtils .TestClusterStateCustom1 ;
50
+ import static org .opensearch .gateway .remote .RemoteClusterStateTestUtils .TestClusterStateCustom2 ;
51
+ import static org .opensearch .gateway .remote .RemoteClusterStateTestUtils .TestClusterStateCustom3 ;
52
+ import static org .opensearch .gateway .remote .RemoteClusterStateTestUtils .TestClusterStateCustom4 ;
54
53
import static org .opensearch .gateway .remote .RemoteClusterStateUtils .CLUSTER_STATE_EPHEMERAL_PATH_TOKEN ;
55
54
import static org .opensearch .gateway .remote .RemoteClusterStateUtils .CLUSTER_STATE_PATH_TOKEN ;
56
55
import static org .opensearch .gateway .remote .RemoteClusterStateUtils .CUSTOM_DELIMITER ;
@@ -338,22 +337,22 @@ public void testGetAsyncMetadataReadAction_Exception() throws IOException, Inter
338
337
339
338
public void testGetUpdatedCustoms () {
340
339
Map <String , ClusterState .Custom > previousCustoms = Map .of (
341
- TestCustom1 .TYPE ,
342
- new TestCustom1 ("data1" ),
343
- TestCustom2 .TYPE ,
344
- new TestCustom2 ("data2" ),
345
- TestCustom3 .TYPE ,
346
- new TestCustom3 ("data3" )
340
+ TestClusterStateCustom1 .TYPE ,
341
+ new TestClusterStateCustom1 ("data1" ),
342
+ TestClusterStateCustom2 .TYPE ,
343
+ new TestClusterStateCustom2 ("data2" ),
344
+ TestClusterStateCustom3 .TYPE ,
345
+ new TestClusterStateCustom3 ("data3" )
347
346
);
348
347
ClusterState previousState = ClusterState .builder (new ClusterName ("test-cluster" )).customs (previousCustoms ).build ();
349
348
350
349
Map <String , Custom > currentCustoms = Map .of (
351
- TestCustom2 .TYPE ,
352
- new TestCustom2 ("data2" ),
353
- TestCustom3 .TYPE ,
354
- new TestCustom3 ("data3-changed" ),
355
- TestCustom4 .TYPE ,
356
- new TestCustom4 ("data4" )
350
+ TestClusterStateCustom2 .TYPE ,
351
+ new TestClusterStateCustom2 ("data2" ),
352
+ TestClusterStateCustom3 .TYPE ,
353
+ new TestClusterStateCustom3 ("data3-changed" ),
354
+ TestClusterStateCustom4 .TYPE ,
355
+ new TestClusterStateCustom4 ("data4" )
357
356
);
358
357
359
358
ClusterState currentState = ClusterState .builder (new ClusterName ("test-cluster" )).customs (currentCustoms ).build ();
@@ -368,136 +367,14 @@ public void testGetUpdatedCustoms() {
368
367
assertThat (customsDiff .getDeletes (), is (Collections .emptyList ()));
369
368
370
369
Map <String , ClusterState .Custom > expectedCustoms = Map .of (
371
- TestCustom3 .TYPE ,
372
- new TestCustom3 ("data3-changed" ),
373
- TestCustom4 .TYPE ,
374
- new TestCustom4 ("data4" )
370
+ TestClusterStateCustom3 .TYPE ,
371
+ new TestClusterStateCustom3 ("data3-changed" ),
372
+ TestClusterStateCustom4 .TYPE ,
373
+ new TestClusterStateCustom4 ("data4" )
375
374
);
376
375
377
376
customsDiff = remoteClusterStateAttributesManager .getUpdatedCustoms (currentState , previousState , true , false );
378
377
assertThat (customsDiff .getUpserts (), is (expectedCustoms ));
379
- assertThat (customsDiff .getDeletes (), is (List .of (TestCustom1 .TYPE )));
380
- }
381
-
382
- private static abstract class AbstractTestCustom extends AbstractNamedDiffable <Custom > implements ClusterState .Custom {
383
-
384
- private final String value ;
385
-
386
- AbstractTestCustom (String value ) {
387
- this .value = value ;
388
- }
389
-
390
- AbstractTestCustom (StreamInput in ) throws IOException {
391
- this .value = in .readString ();
392
- }
393
-
394
- @ Override
395
- public Version getMinimalSupportedVersion () {
396
- return Version .CURRENT ;
397
- }
398
-
399
- @ Override
400
- public void writeTo (StreamOutput out ) throws IOException {
401
- out .writeString (value );
402
- }
403
-
404
- @ Override
405
- public XContentBuilder toXContent (XContentBuilder builder , Params params ) throws IOException {
406
- return builder ;
407
- }
408
-
409
- @ Override
410
- public boolean isPrivate () {
411
- return true ;
412
- }
413
-
414
- @ Override
415
- public boolean equals (Object o ) {
416
- if (this == o ) return true ;
417
- if (o == null || getClass () != o .getClass ()) return false ;
418
-
419
- AbstractTestCustom that = (AbstractTestCustom ) o ;
420
-
421
- if (!value .equals (that .value )) return false ;
422
-
423
- return true ;
424
- }
425
-
426
- @ Override
427
- public int hashCode () {
428
- return value .hashCode ();
429
- }
430
- }
431
-
432
- private static class TestCustom1 extends AbstractTestCustom {
433
-
434
- private static final String TYPE = "custom_1" ;
435
-
436
- TestCustom1 (String value ) {
437
- super (value );
438
- }
439
-
440
- TestCustom1 (StreamInput in ) throws IOException {
441
- super (in );
442
- }
443
-
444
- @ Override
445
- public String getWriteableName () {
446
- return TYPE ;
447
- }
448
- }
449
-
450
- private static class TestCustom2 extends AbstractTestCustom {
451
-
452
- private static final String TYPE = "custom_2" ;
453
-
454
- TestCustom2 (String value ) {
455
- super (value );
456
- }
457
-
458
- TestCustom2 (StreamInput in ) throws IOException {
459
- super (in );
460
- }
461
-
462
- @ Override
463
- public String getWriteableName () {
464
- return TYPE ;
465
- }
466
- }
467
-
468
- private static class TestCustom3 extends AbstractTestCustom {
469
-
470
- private static final String TYPE = "custom_3" ;
471
-
472
- TestCustom3 (String value ) {
473
- super (value );
474
- }
475
-
476
- TestCustom3 (StreamInput in ) throws IOException {
477
- super (in );
478
- }
479
-
480
- @ Override
481
- public String getWriteableName () {
482
- return TYPE ;
483
- }
484
- }
485
-
486
- private static class TestCustom4 extends AbstractTestCustom {
487
-
488
- private static final String TYPE = "custom_4" ;
489
-
490
- TestCustom4 (String value ) {
491
- super (value );
492
- }
493
-
494
- TestCustom4 (StreamInput in ) throws IOException {
495
- super (in );
496
- }
497
-
498
- @ Override
499
- public String getWriteableName () {
500
- return TYPE ;
501
- }
378
+ assertThat (customsDiff .getDeletes (), is (List .of (TestClusterStateCustom1 .TYPE )));
502
379
}
503
380
}
0 commit comments