Skip to content

Commit

Permalink
Fix unit tests
Browse files Browse the repository at this point in the history
Signed-off-by: Sooraj Sinha <[email protected]>
  • Loading branch information
soosinha committed Jun 14, 2024
1 parent 597057a commit 0ab67e6
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -290,15 +290,16 @@ public RemoteClusterStateManifestInfo writeIncrementalMetadata(
assert previousClusterState.metadata().coordinationMetadata().term() == clusterState.metadata().coordinationMetadata().term();

boolean firstUploadForSplitGlobalMetadata = !previousManifest.hasMetadataAttributesFiles();
boolean firstUploadForEphemeralMetadata = previousManifest.getDiscoveryNodesMetadata() != null;

final DiffableUtils.MapDiff<String, Metadata.Custom, Map<String, Metadata.Custom>> customsDiff = remoteGlobalMetadataManager
.getCustomsDiff(clusterState, previousClusterState, isPublicationEnabled, firstUploadForSplitGlobalMetadata);
.getCustomsDiff(clusterState, previousClusterState, firstUploadForSplitGlobalMetadata, isPublicationEnabled);
final DiffableUtils.MapDiff<String, ClusterState.Custom, Map<String, ClusterState.Custom>> clusterStateCustomsDiff =
remoteClusterStateAttributesManager.getUpdatedCustoms(
clusterState,
previousClusterState,
isPublicationEnabled,
firstUploadForSplitGlobalMetadata
firstUploadForEphemeralMetadata
);
final Map<String, UploadedMetadataAttribute> allUploadedCustomMap = new HashMap<>(previousManifest.getCustomMetadataMap());
final Map<String, UploadedMetadataAttribute> allUploadedClusterStateCustomsMap = new HashMap<>(
Expand Down Expand Up @@ -348,15 +349,15 @@ public RemoteClusterStateManifestInfo writeIncrementalMetadata(
;
boolean updateSettingsMetadata = firstUploadForSplitGlobalMetadata
|| Metadata.isSettingsMetadataEqual(previousClusterState.metadata(), clusterState.metadata()) == false;
boolean updateTransientSettingsMetadata = firstUploadForSplitGlobalMetadata
boolean updateTransientSettingsMetadata = firstUploadForEphemeralMetadata
|| Metadata.isTransientSettingsMetadataEqual(previousClusterState.metadata(), clusterState.metadata()) == false;
boolean updateTemplatesMetadata = firstUploadForSplitGlobalMetadata
|| Metadata.isTemplatesMetadataEqual(previousClusterState.metadata(), clusterState.metadata()) == false;

final boolean updateDiscoveryNodes = isPublicationEnabled
&& clusterState.getNodes().delta(previousClusterState.getNodes()).hasChanges();
final boolean updateClusterBlocks = isPublicationEnabled && !clusterState.blocks().equals(previousClusterState.blocks());
final boolean updateHashesOfConsistentSettings = isPublicationEnabled && firstUploadForSplitGlobalMetadata
final boolean updateHashesOfConsistentSettings = isPublicationEnabled && firstUploadForEphemeralMetadata
|| Metadata.isHashesOfConsistentSettingsEqual(previousClusterState.metadata(), clusterState.metadata()) == false;

uploadedMetadataResults = writeMetadataInParallel(
Expand Down Expand Up @@ -398,13 +399,13 @@ public RemoteClusterStateManifestInfo writeIncrementalMetadata(
if (!updateTemplatesMetadata) {
uploadedMetadataResults.uploadedTemplatesMetadata = previousManifest.getTemplatesMetadata();
}
if (!updateDiscoveryNodes && !firstUploadForSplitGlobalMetadata) {
if (!updateDiscoveryNodes && !firstUploadForEphemeralMetadata) {
uploadedMetadataResults.uploadedDiscoveryNodes = previousManifest.getDiscoveryNodesMetadata();
}
if (!updateClusterBlocks && !firstUploadForSplitGlobalMetadata) {
if (!updateClusterBlocks && !firstUploadForEphemeralMetadata) {
uploadedMetadataResults.uploadedClusterBlocks = previousManifest.getClusterBlocksMetadata();
}
if (!updateHashesOfConsistentSettings && !firstUploadForSplitGlobalMetadata) {
if (!updateHashesOfConsistentSettings && !firstUploadForEphemeralMetadata) {
uploadedMetadataResults.uploadedHashesOfConsistentSettings = previousManifest.getHashesOfConsistentSettings();
}
uploadedMetadataResults.uploadedCustomMetadataMap = allUploadedCustomMap;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,7 @@ public class RemoteClusterStateServiceTests extends OpenSearchTestCase {
private BlobStoreRepository blobStoreRepository;
private BlobStore blobStore;
private Settings settings;
private boolean publicationEnabled;
private final ThreadPool threadPool = new TestThreadPool(getClass().getName());

@Before
Expand Down Expand Up @@ -178,7 +179,9 @@ public void setup() {
when(repositoriesService.repository("routing_repository")).thenReturn(blobStoreRepository);

when(blobStoreRepository.getNamedXContentRegistry()).thenReturn(xContentRegistry);
Settings nodeSettings = Settings.builder().put(REMOTE_PUBLICATION_EXPERIMENTAL, "true").build();
// TODO Make the publication flag parameterized
publicationEnabled = true;
Settings nodeSettings = Settings.builder().put(REMOTE_PUBLICATION_EXPERIMENTAL, publicationEnabled).build();
FeatureFlags.initializeFeatureFlags(nodeSettings);
remoteClusterStateService = new RemoteClusterStateService(
"test-node-id",
Expand Down Expand Up @@ -355,8 +358,8 @@ public void testWriteFullMetadataInParallelSuccess() throws IOException {
assertThat(manifest.getStateUUID(), is(expectedManifest.getStateUUID()));
assertThat(manifest.getPreviousClusterUUID(), is(expectedManifest.getPreviousClusterUUID()));

assertEquals(7, actionListenerArgumentCaptor.getAllValues().size());
assertEquals(7, writeContextArgumentCaptor.getAllValues().size());
assertEquals(12, actionListenerArgumentCaptor.getAllValues().size());
assertEquals(12, writeContextArgumentCaptor.getAllValues().size());

byte[] writtenBytes = capturedWriteContext.get("metadata")
.getStreamProvider(Integer.MAX_VALUE)
Expand Down Expand Up @@ -814,6 +817,7 @@ public void testCustomMetadataDeletedUpdatedAndAdded() throws IOException {
.putCustom("custom1", new CustomMetadata1("mock_custom_metadata1"))
.putCustom("custom2", new CustomMetadata1("mock_custom_metadata2"))
.putCustom("custom3", new CustomMetadata1("mock_custom_metadata3"))
.version(initialClusterState.metadata().version() + 1)
)
.build();

Expand All @@ -829,6 +833,7 @@ public void testCustomMetadataDeletedUpdatedAndAdded() throws IOException {
.putCustom("custom2", new CustomMetadata1("mock_updated_custom_metadata"))
.putCustom("custom3", new CustomMetadata1("mock_custom_metadata3"))
.putCustom("custom4", new CustomMetadata1("mock_custom_metadata4"))
.version(clusterState1.metadata().version() + 1)
)
.build();
ClusterMetadataManifest manifest2 = remoteClusterStateService.writeIncrementalMetadata(clusterState1, clusterState2, manifest1)
Expand Down Expand Up @@ -1358,7 +1363,11 @@ public void testRemoteStateStats() throws IOException {
}

public void testRemoteRoutingTableNotInitializedWhenDisabled() {
assertTrue(remoteClusterStateService.getRemoteRoutingTableService() instanceof NoopRemoteRoutingTableService);
if (publicationEnabled) {
assertTrue(remoteClusterStateService.getRemoteRoutingTableService() instanceof InternalRemoteRoutingTableService);
} else {
assertTrue(remoteClusterStateService.getRemoteRoutingTableService() instanceof NoopRemoteRoutingTableService);
}
}

public void testRemoteRoutingTableInitializedWhenEnabled() {
Expand Down

0 comments on commit 0ab67e6

Please sign in to comment.