From 955871a3d47d4e49a9945aa2c2d804c3b8e1482a Mon Sep 17 00:00:00 2001 From: Shivansh Arora Date: Mon, 10 Jun 2024 19:35:21 +0530 Subject: [PATCH] change codec version to V2 in tests Signed-off-by: Shivansh Arora --- .../remote/ClusterMetadataManifest.java | 48 ++++++------ .../RemoteClusterStateServiceTests.java | 17 +++-- .../model/RemoteClusterStateCustomsTests.java | 75 ++++++++++--------- 3 files changed, 71 insertions(+), 69 deletions(-) diff --git a/server/src/main/java/org/opensearch/gateway/remote/ClusterMetadataManifest.java b/server/src/main/java/org/opensearch/gateway/remote/ClusterMetadataManifest.java index 44c08ce6a09dc..9fe48b29c93a2 100644 --- a/server/src/main/java/org/opensearch/gateway/remote/ClusterMetadataManifest.java +++ b/server/src/main/java/org/opensearch/gateway/remote/ClusterMetadataManifest.java @@ -746,30 +746,30 @@ public boolean equals(Object o) { } final ClusterMetadataManifest that = (ClusterMetadataManifest) o; return Objects.equals(indices, that.indices) - && clusterTerm == that.clusterTerm - && stateVersion == that.stateVersion - && Objects.equals(clusterUUID, that.clusterUUID) - && Objects.equals(stateUUID, that.stateUUID) - && Objects.equals(opensearchVersion, that.opensearchVersion) - && Objects.equals(nodeId, that.nodeId) - && Objects.equals(committed, that.committed) - && Objects.equals(previousClusterUUID, that.previousClusterUUID) - && Objects.equals(clusterUUIDCommitted, that.clusterUUIDCommitted) - && Objects.equals(globalMetadataFileName, that.globalMetadataFileName) - && Objects.equals(codecVersion, that.codecVersion) - && Objects.equals(routingTableVersion, that.routingTableVersion) - && Objects.equals(indicesRouting, that.indicesRouting) - && Objects.equals(uploadedCoordinationMetadata, that.uploadedCoordinationMetadata) - && Objects.equals(uploadedSettingsMetadata, that.uploadedSettingsMetadata) - && Objects.equals(uploadedTemplatesMetadata, that.uploadedTemplatesMetadata) - && Objects.equals(uploadedCustomMetadataMap, that.uploadedCustomMetadataMap) - && Objects.equals(metadataVersion, that.metadataVersion) - && Objects.equals(uploadedDiscoveryNodesMetadata, that.uploadedDiscoveryNodesMetadata) - && Objects.equals(uploadedClusterBlocksMetadata, that.uploadedClusterBlocksMetadata) - && Objects.equals(uploadedTransientSettingsMetadata, that.uploadedTransientSettingsMetadata) - && Objects.equals(uploadedHashesOfConsistentSettings, that.uploadedHashesOfConsistentSettings) - && Objects.equals(uploadedClusterStateCustomMap, that.uploadedClusterStateCustomMap) - && Objects.equals(diffManifest, that.diffManifest); + && clusterTerm == that.clusterTerm + && stateVersion == that.stateVersion + && Objects.equals(clusterUUID, that.clusterUUID) + && Objects.equals(stateUUID, that.stateUUID) + && Objects.equals(opensearchVersion, that.opensearchVersion) + && Objects.equals(nodeId, that.nodeId) + && Objects.equals(committed, that.committed) + && Objects.equals(previousClusterUUID, that.previousClusterUUID) + && Objects.equals(clusterUUIDCommitted, that.clusterUUIDCommitted) + && Objects.equals(globalMetadataFileName, that.globalMetadataFileName) + && Objects.equals(codecVersion, that.codecVersion) + && Objects.equals(routingTableVersion, that.routingTableVersion) + && Objects.equals(indicesRouting, that.indicesRouting) + && Objects.equals(uploadedCoordinationMetadata, that.uploadedCoordinationMetadata) + && Objects.equals(uploadedSettingsMetadata, that.uploadedSettingsMetadata) + && Objects.equals(uploadedTemplatesMetadata, that.uploadedTemplatesMetadata) + && Objects.equals(uploadedCustomMetadataMap, that.uploadedCustomMetadataMap) + && Objects.equals(metadataVersion, that.metadataVersion) + && Objects.equals(uploadedDiscoveryNodesMetadata, that.uploadedDiscoveryNodesMetadata) + && Objects.equals(uploadedClusterBlocksMetadata, that.uploadedClusterBlocksMetadata) + && Objects.equals(uploadedTransientSettingsMetadata, that.uploadedTransientSettingsMetadata) + && Objects.equals(uploadedHashesOfConsistentSettings, that.uploadedHashesOfConsistentSettings) + && Objects.equals(uploadedClusterStateCustomMap, that.uploadedClusterStateCustomMap) + && Objects.equals(diffManifest, that.diffManifest); } @Override diff --git a/server/src/test/java/org/opensearch/gateway/remote/RemoteClusterStateServiceTests.java b/server/src/test/java/org/opensearch/gateway/remote/RemoteClusterStateServiceTests.java index 1c06b50da910d..044f3cc27d686 100644 --- a/server/src/test/java/org/opensearch/gateway/remote/RemoteClusterStateServiceTests.java +++ b/server/src/test/java/org/opensearch/gateway/remote/RemoteClusterStateServiceTests.java @@ -86,6 +86,7 @@ import static java.util.stream.Collectors.toList; import static org.opensearch.common.util.FeatureFlags.REMOTE_PUBLICATION_EXPERIMENTAL; +import static org.opensearch.gateway.remote.ClusterMetadataManifest.CODEC_V1; import static org.opensearch.gateway.remote.RemoteClusterStateService.COORDINATION_METADATA; import static org.opensearch.gateway.remote.RemoteClusterStateService.DELIMITER; import static org.opensearch.gateway.remote.RemoteClusterStateService.FORMAT_PARAMS; @@ -475,7 +476,7 @@ public void testMigrationFromCodecV0ManifestToCodecV2Manifest() throws IOExcepti * even if it was not changed in this cluster state update */ public void testMigrationFromCodecV1ManifestToCodecV2Manifest() throws IOException { - verifyCodecMigrationManifest(ClusterMetadataManifest.CODEC_V1); + verifyCodecMigrationManifest(CODEC_V1); } private void verifyCodecMigrationManifest(int previousCodec) throws IOException { @@ -524,7 +525,7 @@ public void testWriteIncrementalGlobalMetadataFromCodecV0Success() throws IOExce public void testWriteIncrementalGlobalMetadataFromCodecV1Success() throws IOException { final ClusterMetadataManifest previousManifest = ClusterMetadataManifest.builder() - .codecVersion(1) + .codecVersion(CODEC_V1) .globalMetadataFileName("global-metadata-file") .indices(Collections.emptyList()) .build(); @@ -548,7 +549,7 @@ private void verifyWriteIncrementalGlobalMetadataFromOlderCodecSuccess(ClusterMe ); final ClusterMetadataManifest expectedManifest = ClusterMetadataManifest.builder() - .codecVersion(3) + .codecVersion(MANIFEST_CURRENT_CODEC_VERSION) .indices(Collections.emptyList()) .clusterTerm(1L) .stateVersion(1L) @@ -1105,7 +1106,7 @@ public void testReadGlobalMetadataIOException() throws IOException { .stateVersion(1L) .stateUUID("state-uuid") .clusterUUID("cluster-uuid") - .codecVersion(ClusterMetadataManifest.CODEC_V1) + .codecVersion(CODEC_V1) .globalMetadataFileName(globalIndexMetadataName) .nodeId("nodeA") .opensearchVersion(VersionUtils.randomOpenSearchVersion(random())) @@ -1314,7 +1315,7 @@ public void testFileNames() { assertThat(splittedIndexMetadataFileName[3], is(String.valueOf(INDEX_METADATA_CURRENT_CODEC_VERSION))); verifyManifestFileNameWithCodec(MANIFEST_CURRENT_CODEC_VERSION); - verifyManifestFileNameWithCodec(ClusterMetadataManifest.CODEC_V1); + verifyManifestFileNameWithCodec(CODEC_V1); verifyManifestFileNameWithCodec(ClusterMetadataManifest.CODEC_V0); } @@ -1577,7 +1578,7 @@ private ClusterMetadataManifest generateV1ClusterMetadataManifest( .committed(true) .clusterUUIDCommitted(isUUIDCommitted) .globalMetadataFileName(globalMetadataFileName) - .codecVersion(ClusterMetadataManifest.CODEC_V1) + .codecVersion(CODEC_V1) .build(); } @@ -1649,7 +1650,7 @@ private void mockBlobContainer( Map indexMetadataMap, int codecVersion ) throws IOException { - String manifestFileName = codecVersion >= ClusterMetadataManifest.CODEC_V1 + String manifestFileName = codecVersion >= CODEC_V1 ? "manifest__manifestFileName__abcd__abcd__abcd__" + codecVersion : "manifestFileName"; BlobMetadata blobMetadata = new PlainBlobMetadata(manifestFileName, 1); @@ -1769,7 +1770,7 @@ private void mockBlobContainerForGlobalMetadata( } ); } - } else if (codecVersion == ClusterMetadataManifest.CODEC_V1) { + } else if (codecVersion == CODEC_V1) { String[] splitPath = clusterMetadataManifest.getGlobalMetadataFileName().split("/"); when(blobContainer.readBlob(RemoteClusterStateService.GLOBAL_METADATA_FORMAT.blobName(splitPath[splitPath.length - 1]))) .thenAnswer((invocationOnMock) -> { diff --git a/server/src/test/java/org/opensearch/gateway/remote/model/RemoteClusterStateCustomsTests.java b/server/src/test/java/org/opensearch/gateway/remote/model/RemoteClusterStateCustomsTests.java index 7c4ffa395fd49..1f7a5e8bfffb1 100644 --- a/server/src/test/java/org/opensearch/gateway/remote/model/RemoteClusterStateCustomsTests.java +++ b/server/src/test/java/org/opensearch/gateway/remote/model/RemoteClusterStateCustomsTests.java @@ -8,30 +8,7 @@ package org.opensearch.gateway.remote.model; -import static java.util.Collections.emptyList; -import static java.util.Collections.emptyMap; -import static org.hamcrest.Matchers.greaterThan; -import static org.hamcrest.Matchers.is; -import static org.hamcrest.Matchers.lessThanOrEqualTo; -import static org.hamcrest.Matchers.nullValue; -import static org.mockito.Mockito.mock; -import static org.mockito.Mockito.when; -import static org.opensearch.Version.CURRENT; -import static org.opensearch.cluster.SnapshotsInProgress.State.INIT; -import static org.opensearch.cluster.SnapshotsInProgress.State.STARTED; -import static org.opensearch.gateway.remote.RemoteClusterStateUtils.CUSTOM_DELIMITER; -import static org.opensearch.gateway.remote.RemoteClusterStateUtils.GLOBAL_METADATA_CURRENT_CODEC_VERSION; -import static org.opensearch.gateway.remote.model.RemoteClusterStateCustoms.CLUSTER_STATE_CUSTOM; - -import java.io.IOException; -import java.io.InputStream; -import java.util.List; -import org.junit.After; -import org.junit.Before; import org.opensearch.cluster.ClusterState.Custom; -import org.opensearch.cluster.RepositoryCleanupInProgress; -import org.opensearch.cluster.RepositoryCleanupInProgress.Entry; -import org.opensearch.cluster.SnapshotDeletionsInProgress; import org.opensearch.cluster.SnapshotsInProgress; import org.opensearch.common.blobstore.BlobPath; import org.opensearch.common.compress.DeflateCompressor; @@ -51,6 +28,26 @@ import org.opensearch.test.OpenSearchTestCase; import org.opensearch.threadpool.TestThreadPool; import org.opensearch.threadpool.ThreadPool; +import org.junit.After; +import org.junit.Before; + +import java.io.IOException; +import java.io.InputStream; +import java.util.List; + +import static java.util.Collections.emptyList; +import static java.util.Collections.emptyMap; +import static org.opensearch.Version.CURRENT; +import static org.opensearch.cluster.SnapshotsInProgress.State.INIT; +import static org.opensearch.gateway.remote.RemoteClusterStateUtils.CUSTOM_DELIMITER; +import static org.opensearch.gateway.remote.RemoteClusterStateUtils.GLOBAL_METADATA_CURRENT_CODEC_VERSION; +import static org.opensearch.gateway.remote.model.RemoteClusterStateCustoms.CLUSTER_STATE_CUSTOM; +import static org.hamcrest.Matchers.greaterThan; +import static org.hamcrest.Matchers.is; +import static org.hamcrest.Matchers.lessThanOrEqualTo; +import static org.hamcrest.Matchers.nullValue; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.when; public class RemoteClusterStateCustomsTests extends OpenSearchTestCase { private static final String TEST_BLOB_NAME = "/test-path/test-blob-name"; @@ -241,19 +238,23 @@ public void testSerDe() throws IOException { } private Custom getClusterStateCustom() { - return SnapshotsInProgress.of(List.of(new SnapshotsInProgress.Entry( - new Snapshot("repo", new SnapshotId("test-snapshot", "test-snapshot-uuid")), - false, - false, - INIT, - emptyList(), - emptyList(), - 0L, - 0L, - emptyMap(), - emptyMap(), - CURRENT, - false - ))); + return SnapshotsInProgress.of( + List.of( + new SnapshotsInProgress.Entry( + new Snapshot("repo", new SnapshotId("test-snapshot", "test-snapshot-uuid")), + false, + false, + INIT, + emptyList(), + emptyList(), + 0L, + 0L, + emptyMap(), + emptyMap(), + CURRENT, + false + ) + ) + ); } }