88
99package org .opensearch .gateway .remote ;
1010
11- import org .opensearch .Version ;
1211import org .opensearch .action .LatchedActionListener ;
13- import org .opensearch .cluster .AbstractNamedDiffable ;
1412import org .opensearch .cluster .ClusterName ;
1513import org .opensearch .cluster .ClusterState ;
1614import org .opensearch .cluster .ClusterState .Custom ;
2321import org .opensearch .common .util .TestCapturingListener ;
2422import org .opensearch .core .action .ActionListener ;
2523import 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 ;
2824import org .opensearch .core .compress .Compressor ;
2925import org .opensearch .core .compress .NoneCompressor ;
30- import org .opensearch .core .xcontent .XContentBuilder ;
3126import org .opensearch .gateway .remote .model .RemoteClusterBlocks ;
3227import org .opensearch .gateway .remote .model .RemoteClusterStateCustoms ;
3328import org .opensearch .gateway .remote .model .RemoteDiscoveryNodes ;
5146import static org .opensearch .gateway .remote .RemoteClusterStateAttributesManager .CLUSTER_STATE_ATTRIBUTE ;
5247import static org .opensearch .gateway .remote .RemoteClusterStateAttributesManager .CLUSTER_STATE_ATTRIBUTES_CURRENT_CODEC_VERSION ;
5348import 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 ;
5453import static org .opensearch .gateway .remote .RemoteClusterStateUtils .CLUSTER_STATE_EPHEMERAL_PATH_TOKEN ;
5554import static org .opensearch .gateway .remote .RemoteClusterStateUtils .CLUSTER_STATE_PATH_TOKEN ;
5655import static org .opensearch .gateway .remote .RemoteClusterStateUtils .CUSTOM_DELIMITER ;
@@ -338,22 +337,22 @@ public void testGetAsyncMetadataReadAction_Exception() throws IOException, Inter
338337
339338 public void testGetUpdatedCustoms () {
340339 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" )
347346 );
348347 ClusterState previousState = ClusterState .builder (new ClusterName ("test-cluster" )).customs (previousCustoms ).build ();
349348
350349 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" )
357356 );
358357
359358 ClusterState currentState = ClusterState .builder (new ClusterName ("test-cluster" )).customs (currentCustoms ).build ();
@@ -368,136 +367,14 @@ public void testGetUpdatedCustoms() {
368367 assertThat (customsDiff .getDeletes (), is (Collections .emptyList ()));
369368
370369 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" )
375374 );
376375
377376 customsDiff = remoteClusterStateAttributesManager .getUpdatedCustoms (currentState , previousState , true , false );
378377 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 )));
502379 }
503380}
0 commit comments