Skip to content

Commit

Permalink
change codec version to V2 in tests
Browse files Browse the repository at this point in the history
Signed-off-by: Shivansh Arora <hishiv@amazon.com>
  • Loading branch information
shiv0408 committed Jun 10, 2024
1 parent 2ab8c9e commit 955871a
Show file tree
Hide file tree
Showing 3 changed files with 71 additions and 69 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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();
Expand All @@ -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)
Expand Down Expand Up @@ -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()))
Expand Down Expand Up @@ -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);
}

Expand Down Expand Up @@ -1577,7 +1578,7 @@ private ClusterMetadataManifest generateV1ClusterMetadataManifest(
.committed(true)
.clusterUUIDCommitted(isUUIDCommitted)
.globalMetadataFileName(globalMetadataFileName)
.codecVersion(ClusterMetadataManifest.CODEC_V1)
.codecVersion(CODEC_V1)
.build();
}

Expand Down Expand Up @@ -1649,7 +1650,7 @@ private void mockBlobContainer(
Map<String, IndexMetadata> 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);
Expand Down Expand Up @@ -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) -> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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";
Expand Down Expand Up @@ -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
)
)
);
}
}

0 comments on commit 955871a

Please sign in to comment.