Skip to content

Commit

Permalink
Adding Integ Tests
Browse files Browse the repository at this point in the history
Signed-off-by: Dharmesh 💤 <[email protected]>
  • Loading branch information
psychbot committed Sep 19, 2023
1 parent 74d4a88 commit 0f16a6b
Show file tree
Hide file tree
Showing 5 changed files with 179 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -34,16 +34,20 @@

import org.opensearch.cluster.metadata.RepositoryMetadata;
import org.opensearch.common.settings.ClusterSettings;
import org.opensearch.common.settings.Setting;
import org.opensearch.common.settings.Settings;
import org.opensearch.core.common.unit.ByteSizeUnit;
import org.opensearch.core.common.unit.ByteSizeValue;
import org.opensearch.core.xcontent.NamedXContentRegistry;
import org.opensearch.env.Environment;
import org.opensearch.indices.recovery.RecoverySettings;
import org.opensearch.repositories.blobstore.BlobStoreRepository;
import org.opensearch.repositories.blobstore.BlobStoreTestUtil;
import org.opensearch.test.OpenSearchTestCase;
import org.junit.AfterClass;

import java.util.List;

import reactor.core.scheduler.Schedulers;

import static org.hamcrest.Matchers.is;
Expand Down Expand Up @@ -179,4 +183,21 @@ public void testChunkSize() {
);
}

public void testSystemRepositoryDefault() {
assertThat(azureRepository(Settings.EMPTY).isSystemRepository(), is(false));
}

public void testSystemRepositoryOn() {
assertThat(azureRepository(Settings.builder().put("system_repository", true).build()).isSystemRepository(), is(true));
}

public void testRestrictedSettingsDefault() {
List<Setting<?>> restrictedSettings = azureRepository(Settings.EMPTY).getRestrictedSystemRepositorySettings();
assertThat(restrictedSettings.size(), is(5));
assertTrue(restrictedSettings.contains(BlobStoreRepository.SYSTEM_REPOSITORY_SETTING));
assertTrue(restrictedSettings.contains(BlobStoreRepository.READONLY_SETTING));
assertTrue(restrictedSettings.contains(BlobStoreRepository.REMOTE_STORE_INDEX_SHALLOW_COPY));
assertTrue(restrictedSettings.contains(AzureRepository.Repository.BASE_PATH_SETTING));
assertTrue(restrictedSettings.contains(AzureRepository.Repository.LOCATION_MODE_SETTING));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
import org.opensearch.indices.replication.common.ReplicationType;
import org.opensearch.node.Node;
import org.opensearch.node.remotestore.RemoteStoreNodeAttribute;
import org.opensearch.repositories.RepositoriesService;
import org.opensearch.repositories.blobstore.BlobStoreRepository;
import org.opensearch.repositories.fs.FsRepository;
import org.opensearch.test.OpenSearchIntegTestCase;
Expand Down Expand Up @@ -302,11 +303,16 @@ public void assertRemoteStoreRepositoryOnAllNodes(String repositoryName) {
.custom(RepositoriesMetadata.TYPE);
RepositoryMetadata actualRepository = repositories.repository(repositoryName);

final RepositoriesService repositoriesService = internalCluster().getClusterManagerNodeInstance(RepositoriesService.class);
final BlobStoreRepository repository = (BlobStoreRepository) repositoriesService.repository(repositoryName);

for (String nodeName : internalCluster().getNodeNames()) {
ClusterService clusterService = internalCluster().getInstance(ClusterService.class, nodeName);
DiscoveryNode node = clusterService.localNode();
RepositoryMetadata expectedRepository = buildRepositoryMetadata(node, repositoryName);
assertTrue(actualRepository.equalsIgnoreGenerations(expectedRepository));
repository.getRestrictedSystemRepositorySettings()
.stream()
.forEach(setting -> assertEquals(setting.get(actualRepository.settings()), setting.get(expectedRepository.settings())));
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@

package org.opensearch.remotestore;

import org.opensearch.client.Client;
import org.opensearch.cluster.metadata.RepositoryMetadata;
import org.opensearch.common.settings.Settings;
import org.opensearch.core.common.unit.ByteSizeValue;
import org.opensearch.plugins.Plugin;
import org.opensearch.test.OpenSearchIntegTestCase;
import org.opensearch.test.disruption.NetworkDisruption;
Expand Down Expand Up @@ -94,4 +98,68 @@ public void testMultiNodeClusterRandomNodeRecoverNetworkIsolation() {

internalCluster().clearDisruptionScheme();
}

public void testMultiNodeClusterRandomNodeRecoverNetworkIsolationPostNonRestrictedSettingsUpdate() {
Set<String> nodesInOneSide = internalCluster().startNodes(3).stream().collect(Collectors.toCollection(HashSet::new));
Set<String> nodesInAnotherSide = internalCluster().startNodes(3).stream().collect(Collectors.toCollection(HashSet::new));
ensureStableCluster(6);

NetworkDisruption networkDisruption = new NetworkDisruption(
new NetworkDisruption.TwoPartitions(nodesInOneSide, nodesInAnotherSide),
NetworkDisruption.DISCONNECT
);
internalCluster().setDisruptionScheme(networkDisruption);

networkDisruption.startDisrupting();

final Client client = client(nodesInOneSide.iterator().next());
RepositoryMetadata repositoryMetadata = client.admin()
.cluster()
.prepareGetRepositories(REPOSITORY_NAME)
.get()
.repositories()
.get(0);
Settings.Builder updatedSettings = Settings.builder().put(repositoryMetadata.settings()).put("chunk_size", new ByteSizeValue(20));
updatedSettings.remove("system_repository");

client.admin()
.cluster()
.preparePutRepository(repositoryMetadata.name())
.setType(repositoryMetadata.type())
.setSettings(updatedSettings)
.get();

ensureStableCluster(3, nodesInOneSide.stream().findAny().get());
networkDisruption.stopDisrupting();

ensureStableCluster(6);

internalCluster().clearDisruptionScheme();
}

public void testNodeRestartPostNonRestrictedSettingsUpdate() throws Exception {
internalCluster().startClusterManagerOnlyNode();
internalCluster().startNodes(3);

final Client client = client();
RepositoryMetadata repositoryMetadata = client.admin()
.cluster()
.prepareGetRepositories(REPOSITORY_NAME)
.get()
.repositories()
.get(0);
Settings.Builder updatedSettings = Settings.builder().put(repositoryMetadata.settings()).put("chunk_size", new ByteSizeValue(20));
updatedSettings.remove("system_repository");

client.admin()
.cluster()
.preparePutRepository(repositoryMetadata.name())
.setType(repositoryMetadata.type())
.setSettings(updatedSettings)
.get();

internalCluster().restartRandomDataNode();

ensureStableCluster(4);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -108,4 +108,16 @@ public void testUpdateRepository() {
final Repository updatedRepository = repositoriesService.repository(repositoryName);
assertThat(updatedRepository, updated ? not(sameInstance(originalRepository)) : sameInstance(originalRepository));
}

public void testSystemRepositoryCantBeCreated() {
internalCluster();
final String repositoryName = "test-repo";
final Client client = client();
final Settings.Builder repoSettings = Settings.builder().put("system_repository", true).put("location", randomRepoPath());

assertThrows(
RepositoryException.class,
() -> client.admin().cluster().preparePutRepository(repositoryName).setType(FsRepository.TYPE).setSettings(repoSettings).get()
);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
/*
* SPDX-License-Identifier: Apache-2.0
*
* The OpenSearch Contributors require contributions made to
* this file be licensed under the Apache-2.0 license or a
* compatible open source license.
*/

package org.opensearch.snapshots;

import org.opensearch.client.Client;
import org.opensearch.common.settings.Settings;
import org.opensearch.core.common.unit.ByteSizeValue;
import org.opensearch.repositories.RepositoryException;
import org.opensearch.repositories.fs.FsRepository;
import org.opensearch.test.OpenSearchIntegTestCase;
import org.junit.Before;

import java.nio.file.Path;

import static org.opensearch.remotestore.RemoteStoreBaseIntegTestCase.remoteStoreClusterSettings;
import static org.opensearch.test.hamcrest.OpenSearchAssertions.assertAcked;

@OpenSearchIntegTestCase.ClusterScope(scope = OpenSearchIntegTestCase.Scope.TEST, numDataNodes = 0)
public class SystemRepositoryIT extends AbstractSnapshotIntegTestCase {
protected Path absolutePath;
final String systemRepoName = "system-repo-name";

@Before
public void setup() {
absolutePath = randomRepoPath().toAbsolutePath();
}

@Override
protected Settings nodeSettings(int nodeOrdinal) {
return Settings.builder()
.put(super.nodeSettings(nodeOrdinal))
.put(remoteStoreClusterSettings(systemRepoName, absolutePath))
.build();
}

public void testRestrictedSettingsCantBeUpdated() {
disableRepoConsistencyCheck("System repository is being used for the test");

internalCluster().startNode();
final Client client = client();
final Settings.Builder repoSettings = Settings.builder().put("location", randomRepoPath());

RepositoryException e = expectThrows(
RepositoryException.class,
() -> client.admin().cluster().preparePutRepository(systemRepoName).setType("mock").setSettings(repoSettings).get()
);
assertEquals(
e.getMessage(),
"[system-repo-name] trying to modify an unmodifiable attribute type of system "
+ "repository from current value [fs] to new value [mock]"
);
}

public void testSystemRepositoryNonRestrictedSettingsCanBeUpdated() {
disableRepoConsistencyCheck("System repository is being used for the test");

internalCluster().startNode();
final Client client = client();
final Settings.Builder repoSettings = Settings.builder().put("location", absolutePath).put("chunk_size", new ByteSizeValue(20));

assertAcked(
client.admin().cluster().preparePutRepository(systemRepoName).setType(FsRepository.TYPE).setSettings(repoSettings).get()
);
}
}

0 comments on commit 0f16a6b

Please sign in to comment.