Skip to content

Commit

Permalink
Add more assertions
Browse files Browse the repository at this point in the history
Signed-off-by: Sooraj Sinha <[email protected]>
  • Loading branch information
soosinha committed Jun 15, 2024
1 parent 6d182de commit 18eceb7
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -130,11 +130,11 @@ public CheckedRunnable<IOException> getAsyncMetadataReadAction(
public DiffableUtils.MapDiff<String, ClusterState.Custom, Map<String, ClusterState.Custom>> getUpdatedCustoms(
ClusterState clusterState,
ClusterState previousClusterState,
boolean includeEphemeral,
boolean isWriteFull,
boolean firstUploadForEphemeralMetadata
) {
if (!includeEphemeral) {
// When includeEphemeral is false, we do not want store any custom objects
if (!isWriteFull) {
// When isWriteFull is false, we do not want store any custom objects
return DiffableUtils.diff(
Collections.emptyMap(),
Collections.emptyMap(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,6 @@

package org.opensearch.gateway.remote;

import java.util.Collections;
import java.util.List;
import java.util.Map;
import org.opensearch.Version;
import org.opensearch.action.LatchedActionListener;
import org.opensearch.cluster.AbstractNamedDiffable;
Expand Down Expand Up @@ -43,6 +40,9 @@
import org.junit.Before;

import java.io.IOException;
import java.util.Collections;
import java.util.List;
import java.util.Map;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.atomic.AtomicReference;

Expand All @@ -53,11 +53,11 @@
import static org.opensearch.gateway.remote.model.RemoteClusterBlocksTests.randomClusterBlocks;
import static org.opensearch.gateway.remote.model.RemoteDiscoveryNodes.DISCOVERY_NODES_FORMAT;
import static org.opensearch.gateway.remote.model.RemoteDiscoveryNodesTests.getDiscoveryNodes;
import static org.hamcrest.Matchers.is;
import static org.mockito.ArgumentMatchers.anyIterable;
import static org.mockito.ArgumentMatchers.anyString;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
import static org.hamcrest.Matchers.is;

public class RemoteClusterStateAttributesManagerTests extends OpenSearchTestCase {
private RemoteClusterStateAttributesManager remoteClusterStateAttributesManager;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -179,10 +179,6 @@ public void setup() {
when(repositoriesService.repository("routing_repository")).thenReturn(blobStoreRepository);

when(blobStoreRepository.getNamedXContentRegistry()).thenReturn(xContentRegistry);
// 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",
repositoriesServiceSupplier,
Expand All @@ -199,6 +195,9 @@ public void setup() {
public void teardown() throws Exception {
super.tearDown();
remoteClusterStateService.close();
publicationEnabled = false;
Settings nodeSettings = Settings.builder().build();
FeatureFlags.initializeFeatureFlags(nodeSettings);
threadPool.shutdown();
}

Expand Down Expand Up @@ -272,9 +271,28 @@ public void testWriteFullMetadataSuccess() throws IOException {
assertThat(manifest.getSettingsMetadata(), notNullValue());
assertThat(manifest.getTemplatesMetadata(), notNullValue());
assertFalse(manifest.getCustomMetadataMap().isEmpty());
assertThat(manifest.getClusterBlocksMetadata(), nullValue());
assertThat(manifest.getDiscoveryNodesMetadata(), nullValue());
assertThat(manifest.getTransientSettingsMetadata(), nullValue());
assertThat(manifest.getHashesOfConsistentSettings(), nullValue());
assertThat(manifest.getClusterStateCustomMap().size(), is(0));
}

public void testWriteFullMetadataSuccessPublicationEnabled() throws IOException {
// 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",
repositoriesServiceSupplier,
settings,
clusterService,
() -> 0L,
threadPool,
List.of(new RemoteIndexPathUploader(threadPool, settings, repositoriesServiceSupplier, clusterSettings)),
writableRegistry()
);
final ClusterState clusterState = generateClusterStateWithOneIndex().nodes(nodesWithLocalNodeClusterManager())
.customs(Map.of(RepositoryCleanupInProgress.TYPE, new RepositoryCleanupInProgress(List.of(new Entry("test-repo", 10L)))))
.build();
Expand Down Expand Up @@ -358,8 +376,8 @@ public void testWriteFullMetadataInParallelSuccess() throws IOException {
assertThat(manifest.getStateUUID(), is(expectedManifest.getStateUUID()));
assertThat(manifest.getPreviousClusterUUID(), is(expectedManifest.getPreviousClusterUUID()));

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

byte[] writtenBytes = capturedWriteContext.get("metadata")
.getStreamProvider(Integer.MAX_VALUE)
Expand Down

0 comments on commit 18eceb7

Please sign in to comment.